标签:utc name pac main cin src div run min
#include<iostream> using namespace std; class Base{ public: Base(int x,int y):m(x),n(y){}; void plus(){cout<<"m+n="<<m+n<<endl;}; friend class A; friend class B; friend class C; private: int m,n; }; class A:public Base{ public: A(int x,int y):Base(x,y){}; void minus(){cout<<"m-n="<<m-n<<endl;}; }; class B:public Base{ public: B(int x,int y):Base(x,y){}; void multiply(){cout<<"m*n="<<m*n<<endl;}; }; class C:public Base{ public: C(int x,int y):Base(x,y){}; void divide(){cout<<"m/n="<<m/n<<endl;}; };
#include<iostream> #include"Base.h" using namespace std; int main() { int m,n; cout<<"输入m:"; cin>>m; cout<<"输入n:"; cin>>n; if(n==0){ cout<<"输入条件不符。"<<endl; } else{ A outA(m,n); outA.plus(); outA.minus(); B outB(m,n); outB.plus(); outB.multiply(); C outC(m,n); outC.plus(); outC.divide(); } return 0; }
第二题:
#include<iostream> using namespace std; class vehicle{ public: void run(){cout<<"run"<<endl;}; void stop(){cout<<"stop"<<endl;}; vehicle(int x,int y):maxspeed(x),weight(y){ cout<<"maxspeed="<<maxspeed<<",weight="<<weight<<endl; }; friend class bicycle; friend class motorcar; ~vehicle(){}; private: int maxspeed,weight; }; class bicycle:virtual public vehicle{ public: bicycle(int x,int y,int z):vehicle(x,y){ int height; height=z; cout<<"height="<<height<<endl; }; ~bicycle(){}; }; class motorcar:virtual public vehicle{ public: motorcar(int x,int y,int z):vehicle(x,y){ int setnum; setnum=z; cout<<"setnum="<<setnum<<endl; }; ~motorcar(){}; };
#include <iostream> #include"vehicle.h" using namespace std; int main() { int a,b,c,d; cout<<"输入maxspeed,weight:"; cin>>a>>b; cout<<"输入自行车的height:"; cin>>c; bicycle newB(a,b,c); newB.run(); newB.stop(); cout<<"输入摩托车的setnum:"; cin>>d; motorcar newM(a,b,d); newM.run(); newM.stop(); return 0; }
标签:utc name pac main cin src div run min
原文地址:https://www.cnblogs.com/a18851962010/p/9151298.html