Question: I need help on this C++ operator overloading activity. Please label the fraction.h, fraction.cpp and main.cpp. Thank you Consider the following class definition to define

I need help on this C++ operator overloading activity. Please label the fraction.h, fraction.cpp and main.cpp. Thank you

Consider the following class definition to define a class for fractions:

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; if (X > Y) cout << X << " is bigger than " << Y << endl;

else if (X < Y) cout << X << " is less than " << Y << endl;

else if (X == Y) cout << X << " is equivalent to " << Y << endl;

cout << X << "++ is ";

X++;

cout << X << endl;

system("pause"); return 0;

}

Create a new Visual Studio project with files fraction.h, fraction.cpp, and main.cpp. 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).

Once you have the code working, if you overloaded the comparison operators (>, <, ==) using methods then try to rewrite your code so that you overload these operators using friend functions. If you overloaded the comparison operators (>, <, ==) using friend functions then try to rewrite your code so that you overload these operators using methods

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!