Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

What four factors are needed for marketing to occur? AppendixLO1

Answered: 1 week ago