//7.1 #includeusing namespace std;class Total{ public: Total(int i,int j){ cout<<"* constructor is called"< >m>>n; A a(m,n); B b(m,n); C c(m,n); cout<<"m + n ="; cout< <
//7.2 #includeusing namespace std;class vehicle{ public: vehicle(int i,int j) : maxspeed(i) , weight(j){cout<<"vehicle's constructor is called"< >m>>n; cout<<"please decide your motorcar's height and seatnum:"< >p>>q; motorcycle mc(m,n,p,q); system("pause"); mc.run(); system("pause"); mc.stop(); system("pause"); return 0;}
//7.3 代码大部分见上次fraction类
//main中添加代码 system("pause"); cout<<"about ifraction---------------"<>times2; while(times2--){ int p,q; cout<<"please make sure of the top and bottom of the fraction: "< >p>>q; iFraction ifraction(p,q); ifraction.legal(); convertF(ifraction); ifraction.print();//iFraction类 class iFraction :public Fraction{ public: iFraction(int n,int m):Fraction(n,m),wholepart(0),fractionparttop(0),fractionpartbottom(0){} ~iFraction(){} friend void convertF(iFraction &A); void print(); private: int wholepart; int fractionparttop; int fractionpartbottom;};//ifraction 实现 #include #include"ifraction.h"using namespace std;void convertF(iFraction &A){ int i; i=A.top; int j; j=A.bottom; if(i>0){ A.wholepart=i/j; A.fractionparttop=i-A.wholepart*j; A.fractionpartbottom=j; } if(i<0){ i=-1*i; A.wholepart=i/j; A.fractionparttop=i-A.wholepart*j; A.fractionpartbottom=j; A.wholepart=-1*A.wholepart; }}void iFraction::print(){ if(wholepart!=0) cout< <<" ("< <<"/"< <<")"<