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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started