To learn about operator overloading.
Consider the following class definition:
class Fraction
{
private:
int numerator;
int denominator;
public:
Fraction(int n = 0, int d = 1) {numerator = n; denominator = d;}
};
and the following main function:
int main()
{
Fraction X, Y, Z;
cout << "Enter two fractions (in the form numerator/denominator): ";
cin >> X;
cin >> Y;
Z = X + Y;
cout << X << " + " << Y << " = " << Z << endl;
Z = X - Y;
cout << X << " - " << Y << " = " << Z << endl;
Z = X * Y;
cout << X << " * " << Y << " = " << Z << endl;
Z = X / Y;
cout << X << " / " << Y << " = " << Z << endl;
cout << X << " as a double is " << (double)X << endl;
system("pause");
return 0;
}
Write the code that would be necessary to get this program to compile and work correctly (i.e. you should overload the appropriate operators for the Fraction class).
You must write separate .h files for each class.
You should also use good commenting and code style. Expect points to be deducted from your score if you do not comment your code and use good coding practices.
You may not use global variables or GOTO statements.