11.9 定义分数类Rational......
View Code
1 #include2 #include 3 class Rational{ 4 private: 5 int fm,fz; 6 int getZdgys(int a,int b); 7 public: 8 Rational(){ 9 fm=1;fz=0;10 }11 Rational(int a,int b);12 friend Rational Add(Rational r1,Rational r2);13 friend Rational Sub(Rational r1,Rational r2);14 void Print1();15 void Print2();16 };17 18 Rational::Rational(int fm1,int fz1)19 {20 int t=getZdgys(fm1,fz1);21 fm=fm1/t;22 fz=fz1/t;23 }24 25 void Rational::Print1()26 {27 cout< <<"/"< <