RuiHao

code format="cpp" using namespace std;
 * 1) include

class Rational{ protected: int num, den;

public: Rational(int n, int d){num = n; den = d;}; //Constructor ~Rational{}; //Destructor void Display{ cout << num << "/" << den; };// Public member function to display Fraction Rational ADD(Rational f2) {        int n3,d3; d3= den*f2.den; n3= num*f2.den+den*f2.num; Rational ans(n3,d3); return ans; }; Rational minus(Rational f2) {        int n3,d3; d3= den*f2.den; n3= num*f2.den-den*f2.num; Rational ans(n3,d3); return ans; }; Rational multiply(Rational f2) {        int n3,d3; d3= den*f2.den; n3= num*f2.num; Rational ans(n3,d3); return ans; }; Rational divide(Rational f2) {        int n3,d3; d3= den*f2.num; n3= num*f2.den; Rational ans(n3,d3); return ans; }; //Setter Functions void Set_num(int n){num = n; }; void Set_den(int d){den = d; };

};

int main{ cout<<"Enter a numerator:\n"; int n,d; cin>>n; cout<<"Enter a denominator:\n"; cin>>d; Rational f1(n,d); cout<<"The Fraction is:\n";f1.Display;cout<>n; cout<<"Enter another denominator:\n"; cin>>d; Rational f2(n,d); cout<<"The 2nd Fraction is:\n";f2.Display;cout<<endl; Rational answer=f1; cout<<"Addition:\n";answer = answer.ADD(f2); answer.Display;cout<<endl; cout<<"Subtraction:\n";answer = answer.minus(f2); answer.Display;cout<<endl; cout<<"Multiplication:\n";answer = answer.multiply(f2); answer.Display;cout<<endl; cout<<"Division:\n";answer = answer.divide(f2); answer.Display;cout<<endl;

system ("pause"); return 0; }

code
 * D

thanks to Ray Yan for his high speed download of bloodshed C++ (within 2mins) thanks to Yao Chong for guiding me along the way of, quite literally.