Home / Questions / In Frac.h, replace the methodes addition( const Fraction &),subtraction(const Fraction&),.
In Frac.h, replace the methodes addition( const Fraction &),subtraction(const Fraction&), multiply(const Fraction &);divide(const Fraction &); void printFraction(); by overloadingoperators +, -, *, /, << respectively.* Add overloading operators > and < so that they can comparetwo Fractions Write your own implementation file which is named Frac2.cpp toreplace Frac.cpp and implement the Fraction class and the thenecessary overloading operators. Download the driver Frac2Driver.cpp to test your codes. If your codes in files Frac2.h and Frac2.cppare correct, the standard output after the execution of yourprogram should 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 #include using namespace std; //—————————— Fraction———————————— // default constructor: parameters are numerator and denominatorrespectively // if the number is negative, the negative is always stored inthe numerator Fraction::Fraction(int n, int d) { numerator = (d < 0 ? -n : n); denominator = (d < 0 ? -d : d); reduce(); } //(a)——————————— add //————————————– // overloaded +: addition of 2 Fractions, current object andparameter Fraction Fraction::add(const Fraction a) { Fraction t; t.numerator = a.numerator * denominator + a.denominator *numerator; t.denominator = a.denominator * denominator; t.reduce(); return t; } //(b)—————————— subtract //———————————— Fraction Fraction::subtract(const Fraction a) { Fraction t; t.numerator = a.numerator * denominator – a.denominator *numerator; t.denominator = a.denominator * denominator; t.reduce(); return t; } //(c)—————————— multiply //———————————— Fraction Fraction::multiply(const Fraction a) { Fraction t; t.numerator = a.numerator * numerator; t.denominator = a.denominator * denominator; t.reduce(); return t; } //(d)——————————– divide //———————————— Fraction Fraction::divide(const Fraction a) { Fraction t; t.numerator = a.denominator * numerator; t.denominator = a.numerator * denominator; t.reduce(); return t; } //(e)—————————- printFraction //——————————— void Fraction::printFraction() { if (denominator == 1) cout << numerator << endl; else { cout << numerator << “/” << denominator<< endl; } } //(f)———————— printFractionAsFloat //—————————— void Fraction::printFractionAsFloat() { if (denominator == 0) cout << endl << “DIVIDE BY ZERO ERROR!!!” <<endl; else="" cout="" <<="" float(numerator)="" float(denominator);="" }="" ——————————–="" reduce————————————="" reduce="" fraction="" to="" lowest="" terms="" void="" fraction::reduce()="" {="" int="" n="numerator" <="" 0="" ?="" -numerator="" :="" numerator;="" d="denominator;" largest="n"> d ? n : d; int gcd = 0; // greatest common divisor for (int loop = largest; loop >= 2; loop–) if (numerator % loop == 0 && denominator % loop == 0){ gcd = loop; break; } if (gcd != 0) { numerator /= gcd; denominator /= gcd; } } ********************************************************************************************************************************************************************* // Frac.h // Proj 3 #ifndef Frac_hpp #define Frac_hpp #include using namespace std; class Fraction { public: Fraction(int = 0, int = 1); // default constructor Fraction add(const Fraction); Fraction subtract(const Fraction); Fraction multiply(const Fraction); Fraction divide(const Fraction); void printFractionAsFloat(); void printFraction(); private: int numerator; int denominator; void reduce(); // utility function, reduce to lowest terms }; // end class Fraction #endif /* Frac_hpp */ ********************************************************************************************************************************************************************* // driver for Fraction project part 2 #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 << ‘n’; // c.printFraction(); cout <<c; ="" cout="" <<="" ”="" –="" ;="" d.printfraction();="" d;="" x="c" x.printfraction();="" <<x;="" ‘n’;="" c.printfraction();="" c;="" *="" <<c;="" x;="" is:n”;="" (="" c=""> d ) ? ” > ” : ” <= “); // d.printFraction(); cout << d; cout << ” according to the overloaded >operatorn”; cout << ( ( c < d ) ? ” < ” : ” >= “); // d.printFraction(); cout . . .</c;></endl;>
Apr 06 2020 View more View Less
Suppose that an increase in business confidence increases investment expenditure by one million dollars. How do you expect this increase in investment expenditure to affe...
Apr 13 2020Discuss the following statement: “Primase is a sloppy enzyme that makes many mistakes. Eventually, the RNA primers it makes are replaced with DNA made by a polymerase wit...
Nov 27 2019Which of the following is a method used to reduce an expected labor shortage that is low on revocability? A. OvertimeB. New external hiresC. Temporary employeesD. Out...
Dec 10 2019On December 31, 2011, the separate-company financial statements for Pan Corporation and its 70 percent-owned subsidiary, Sad Corporation, had the following account balanc...
Apr 20 2020Not yet answered Refer to the information provided in Figure below to answer the question that follow. Lingle's monthly budget constraint Marked out of 1.00 40 A Flag qu...
Apr 05 2021The Tech football coaching staff has six basic offensive plays it runs every game. Tech has an upcoming game against State on Saturday, and the Tech coaches know that Sta...
Jun 22 2020Show that A^n = A^(n-2) +A^2 -I and use that to find A^50 for A= 1 0 0 1 0 1 0 1 0 >
Aug 02 2020Select Rx so that 50 V is across it in Figure P2−81.
Jun 15 2020On June 30, 2009, Newsom Company sold equipment for $7,250 that had been acquired for $14,500 on January 1, 2007. Newsom originally estimated that the computer would have...
Mar 22 2020your corporation has a marginal tax rate of 40% but 70% of dividends received your excludable from Texas the corporations before text dividend yield is 15% what is the co...
May 28 2018