Yu+Fan

using namespace std; class Rational{ protected: int num, den; public: Rational{num=0; den=1;} Rational(int n, int d){num = n; den = d;} ~Rational{}; void Display{ cout << num << "/" << den << endl; } void Set_fraction(int n, int d){num = n; den = d; }
 * 1) include

Rational Add(Rational A){ int a, b; a=num*A.den+den*A.num; b=den*A.den; Rational test(a,b); return test;}

Rational Subtract(Rational S){ int a, b; a=num*S.den-den*S.num; b=den*S.den; Rational test(a,b); return test;}

Rational Multiply(Rational M){ int a, b; a=num*M.num; b=den*M.den; Rational test(a,b); return test;}

Rational Divide(Rational D){ int a, b; a=num*D.den; b=den*D.num; Rational test(a,b); return test;} };

int main{ Rational F1, F2, F3; int a, b, c, d; cout << "Please enter a numerator:\n"; cin >> a; cout << "Please enter a denominator:\n"; cin >> b; cout << "Please enter another numerator:\n"; cin >> c; cout << "Please enter another denominator:\n"; cin >> d; F1.Set_fraction(a,b); F2.Set_fraction(c,d); cout << "The first fraction is: "; F1.Display; cout << "\nThe second fraction is: "; F2.Display; cout << "Addition:\n"; F3 = F1.Add(F2); F3.Display; F3 = F1.Subtract(F2); F3.Display; F3 = F1.Multiply(F2); F3.Display; F3 = F1.Divide(F2); F3.Display; system("pause"); return 0; }

p.s. I dont understand rational test. When comparing with Sean's work, his have rational test and mine don't. After adding it in, it worked.