GRP5

NAME 3: Stephen Chow Guang Wei (3P3-04)
code format="cpp-qt" /* Question: OOP Task 1 (Rational ADD, MINUS, MUTIPLY, DIVIDE)
 * OOP Task 1 >> Rational (ADD, MINUS, MUTIPLY, DIVIDE):**

Group: Group 5

~Member 1~ >>Name: Fan Jun Wei >>Class: 3S2 >>Index: 10

~Member 2~ >>Name: Kok Xuan Liang >>Class: 3S2 >>Index: 13

Date-Of-Submission: 13 June 2010

using namespace std;
 * 1) include

class Rational{

protected: int num; int den;

public: Rational{num=0; den=1;}; //Default Constructor

Rational(int x, int y){ num = x; den = y;      }; //Constructor

~Rational{}; //Destructor

void Display{ cout << num << "/" << den; }; //Public member function to display Fraction

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

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

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

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

}; //class

int main{

int num1; int den1; int num2; int den2;

cout<<"Please enter 4 numbers. \n \n Numbers should be entered in the order of: \n \n 'Numerator1', 'Denominator1', 'Numerator2', 'Denominator2' \n \n "; cin >>num1>>den1>>num2>>den2; cout<<endl; Rational A(num1,den1); //Declaration Rational B(num2,den2); Rational C;

cout<<"Input Numbers:"; cout<<endl; A.Display; cout<<endl; B.Display; cout<<endl;

cout<<endl; //A.ADD(B); //A.Display; cout<<endl;

cout<<"Additional of Fractions:"; cout<<endl; C=A.ADD(B); C.Display; cout<<endl;

cout<<endl;

cout<<"Subtraction of Fractions:"; cout<<endl; C=A.MINUS(B); C.Display; cout<<endl;

cout<<endl;

cout<<"Mutiplication of Fractions:"; cout<<endl; C=A.MUTIPLY(B); C.Display; cout<<endl;

cout<<endl;

cout<<"Division of Fractions:"; cout<<endl; C=A.DIVIDE(B); C.Display; cout<<endl;

cout<<endl;

system("pause");

}//main

code