Peng+Ning

using namespace std ; class Rational{ protected :  int num, den ; Rational SIMPLIFY { Rational simp( num, den ); int diff= abs ( num - den ), hcf= 1 ; if (diff!= 1 && diff!= 0 && num != 0 ){ for ( int i=diff; i>= 1 ; i--){ if ( num %i== 0 && den %i== 0 ){ hcf=i; simp. num = num /hcf; simp. den = den /hcf; break ;} } } if (diff== 0 ){ simp. num = 1 ; simp. den = 1 ; } if ( num == 0 ){ simp. den = 1 ; } return simp; }; public : Rational{ num = 0 ; den = 1 ;}; Rational( int n, int d){ num = n; den = d;};  Rational ADD ( Rational Temp) { Rational A, simp; A. num = num *Temp. den +Temp. num * den ; A. den = den *Temp. den ; simp = A. SIMPLIFY ; return simp; }  Rational MINUS ( Rational Temp) { Rational A, simp; A. num = num *Temp. den -Temp. num * den ; A. den = den *Temp. den ; simp = A. SIMPLIFY ; return simp; } Rational MULTIPLY ( Rational Temp) { Rational A, simp; A. num = num *Temp. num ; A. den = den *Temp. den ; simp = A. SIMPLIFY ; return simp; } Rational DIVIDE ( Rational Temp) { Rational A, simp; A. num = num *Temp. den ; A. den = den *Temp. num ; simp = A. SIMPLIFY ; return simp; } ~Rational{}; void display { cout << num << "/" << den << endl;}; void Set_num( int n){ num = n;}; void Set_den( int d){ den = d;}; }; int main{ Rational R1, R2, R3, R4, R5, R6; R1. Set_num ( 1 ); R1. Set_den ( 2 ); R1. display ; R2. Set_num ( 2 ); R2. Set_den ( 2 ); R2. display ; R3=R1. ADD (R2); R3. display ; R4=R1. MINUS (R2); R4. display ; R5=R1. MULTIPLY (R2); R5. display ; R6=R1. DIVIDE (R2); R6. display ;  system ( "pause" );  return 0 ; }
 * 1) include