Question: Description: Consider the following class definition: class Fraction { private: int numerator; int denominator; public: Fraction(int n = 0, int d = 1) {numerator =

Description:

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). For full credit, resulting fractions should also be reduced.

Requirements:

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!