Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions