Marcus+Goh


 * 1) include

class Rational{ protected: int num, den; public:

Rational{num=0; den=1;}; Rational(int n, int d){num = n; den = d;};

Rational ADD(Rational R){ Rational F; F.num=num*R.den+den*R.num; F.den=den*R.den; return R; }

Rational SUBTRACT(Rational R){ Rational F; F.num=num*R.den-den*R.num; F.den=den*R.den; return R; }

Rational MULTIPLY(Rational R){ Rational F; F.num=num*R.num; F.den=den*R.den; return R; }

Rational DIVIDE(Rational R){ Rational F; F.num=num*R.den; F.den=den*R.num; return R; }

~Rational{}; void Display{ cout << num << "/" << den; }; void Set_num(int n){num = n; }; void Set_den(int d){den = d; };

};

int main{ int n, d; Rational R1; Rational R2; Rational R3; Rational R4; Rational R5; Rational R6; cout<< "Enter a numerator: "; cin>> n; cout<< "Enter a denominator: "; cin>> d; Rational R1(n,d);

cout<< "Enter a numerator: "; cin>> n; cout<< "Enter a denominator: "; cin>> d; Rational R2(n,d);

R3=R1.ADD(R2) R4=R1.SUBTRACT(R2) R5=R1.MULTIPLY(R2) R6=R1.DIVIDE(R2)

cout<< "Sum: " << endl; R3.Display; cout<< "Difference: " << endl; R4.Display; cout<< "Product: " << endl; R5.Display; cout<< "Divided: " << endl; R6.Display;

system ("pause"); return 0; }