Question: Building a class for Fraction ADT Phase 2 1. In Frac.h, replace the methods of addition (const Fraction &), subtraction(const Fraction&), multiply( const Fraction &),

Building a class for Fraction ADT Phase 2

1. In Frac.h, replace the methods of addition (const Fraction &), subtraction(const Fraction&), multiply( const Fraction &), divide(const Fraction &), void printFraction() by overloading operators +, -, *, /, << respectively. 2. Add overloading operators > and < so that they can compare two Fractions.

3. Write your own implementation file Frac2.cpp to replace Frac.cpp and implement the Fraction class and the necessary overloading operators. 4. Download the testdriver_cpp to test your codes. If your codes in files Frac2.h and Frac2.cpp are correct, the standard output after the execution of your program should be like the following: 7/3 + 1/3 = 8/3 7/3 - 1/3 = 2 7/3 * 1/3 = 7/9 7/3 / 1/3 = 7 7/3 is: > 1/3 according to the overloaded > operator >= 1/3 according to the overloaded < operator Press any key to continue

5. Optional (2 Bonus Points). Improve for cascading use of operators (see LabProjDriver.cpp), Example: x = c + c / d - d * c;

Test Driver

#include using namespace std; #include "Frac2.h" int main() { Fraction c(7, 3), d(3, 9), x; // c.printFraction(); cout << c; cout << " + "; // d.printFraction(); cout << d; cout << " = "; x = c + d; // x.printFraction(); cout << x; cout << ' '; // c.printFraction(); cout << c; cout << " - "; // d.printFraction(); cout << d; cout << " = "; x = c - d; // x.printFraction(); cout << x; cout << ' '; // c.printFraction(); cout << c; cout << " * "; // d.printFraction(); cout << d; cout << " = "; x = c * d; // x.printFraction(); cout << x; cout << ' '; // c.printFraction(); cout << c; cout << " / "; // d.printFraction(); cout << d; cout << " = "; x = c / d; // x.printFraction(); cout << x; cout << ' '; // c.printFraction(); cout << c; cout << " is: ";

cout << ((c > d) ? " > " : " <= "); // d.printFraction(); cout << d; cout << " according to the overloaded > operator "; cout << ((c < d) ? " < " : " >= "); // d.printFraction(); cout << d; cout << " according to the overloaded < operator "; /* uncomment this line for improved version // Optional: 2 Bonus Points // c.printFraction(); cout << c; cout << " + "; // d.printFraction(); cout << c; cout << " / "; cout << d; cout << " - "; cout << d; cout << " * "; cout << c; cout << " = "; x = c + c / d - d * c; // cascading use of operators // x.printFraction(); cout << x; cout << ' '; */ // uncomment this line for improve version #ifdef _WIN32 // _WIN32 is used by visual C++ #if (_MSC_VER <= 1916)// check if it Visual Studio 2017 and earlier system("pause"); #endif #endif return 0; }

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!