GRP1

**NAME 2: Rick Wong Tuck Jun**
code // OOP Task 1- Rational // Lester Foo Shi En // 3P3 // 10 // Rick Wong Tuck Jun // 3S2 // 21 // 313/07/2010
 * HCI OOP Task 1:**

using namespace std;
 * 1) include

//Define class Rational class Rational{

protected: int num, den;

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

//Define the output function void Display{ cout << num << "/" << den; }; void Set_num(int n){num = n; }; void Set_den(int d){den = d; };

//Define addition function void ADD(Rational R) { num = num*R.den + R.num*den; den = den*R.den; };

Rational ADD1(Rational R){ Rational Z;        Z.num = num*R.den + R.num*den; Z.den = den*R.den; return Z; };

//Define substraction function void MINUS(Rational R) { num = num*R.den - R.num*den; den = den*R.den; };

Rational MINUS1(Rational R) { Rational Z;        Z.num = num*R.den - R.num*den; Z.den = den*R.den; return Z; };

//Define multiplication function void MULTIPLY(Rational R) { num = num*R.num; den = den*R.den; };

Rational MULTIPLY1(Rational R) { Rational Z;        Z.num = num*R.num; Z.den = den*R.den; return Z; };

//Define division function void DIVIDE(Rational R) { num = num*R.den; den = den*R.num; };

Rational DIVIDE1(Rational R) { Rational Z;        Z.num = num*R.den; Z.den = den*R.num; return Z; }; };

Rational A, B, C;

//Define operation of choice function void operate { char sign; cout<<"Please enter operator sign (+,-,*,/): "; cin>>sign; if (sign=='+') C=A.ADD1(B); else if (sign=='-') C=A.MINUS1(B); else if (sign=='*') C=A.MULTIPLY1(B); else if (sign=='/') C=A.DIVIDE1(B); else operate; }

int main{ int an,ad,bn,bd;

//Instruction to input rational numbers cout << "Enter the the rational numbers in the following order:" << endl; cout << "1stnum 1stden" << endl; cout << "2ndnum 2ndden" << endl; cin>>an>>ad>>bn>>bd;

//Assign input to int A.Set_num(an); A.Set_den(ad); B.Set_num(bn); B.Set_den(bd);

//Run choice of operation function operate;

//Run output functions

A.Display; cout<<endl;

B.Display; cout<<endl;

C.Display; cout<<endl;

system("pause"); return 0; }

code