Question: Write a class Fraction that defines adding, subtracting multiplying and dividing fractions by overloading standard operators for these operations. Write a function member for reducing

Write a class Fraction that defines adding, subtracting multiplying and dividing fractions by overloading standard operators for these operations. Write a function member for reducing factors and overload I?O operators to input and output fractions. help how would i set this up ? i have some thing but its not working right... urgent help needed...



//Anbessa Mesquitta

// Program 1 pg. 48



#include

using namespace std;



class Fraction

{

public:


Fraction()

{


Fraction operator+(Fraction x)

{


Fraction p;

p.denom = denom * x.denom;

p.num = ( num * x.denom) + (x.num * denom);


return p;

}

//-------------------------------------------------

Fraction operator-(Fraction y )

{

Fraction p;

p.denom = denom * y.denom;

p.num = ( num * y.denom) - (y.num * denom);


return p;

}



Fraction operator*(Fraction w )

{


Fraction p;

p.denom = denom * w.denom;

p.num = num * w.num;

return p;

}



Fraction operator /(Fraction z)

{

Fraction p;

p.num = z.num * denom;

p.denom = num * z.denom;


return p;

}



int num, denom;






void reduction()

{

int largest;

int gcd = 0; // gca


largest = numerator > denominator ? numerator : denominator;

for (int loop = 2; loop <= largest; loop++)

if (numerator % loop == 0 && denominator % loop == 0)

gcd = loop;


if (gcd != 0)


{


numerator /= gcd;

denominator /= gcd;


}


// end if


}


//end function




};

int main()




help!!! thanks!

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 Programming Questions!