Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this needs to be in C++ 1. Continue using the Fraction class, do the following a

ID: 3572947 • Letter: T

Question

this needs to be in C++

1. Continue using the Fraction class, do the following a. Overload the operator to multiply two Fraction objects Test code shown below Fraction fl (1,5) Fraction f2 (3,4) Fraction f3; f3 cout f3 f3 print //should print 3/20 b. Overload the operator to add two Fraction objects. Test code shown below in red (added to existing code from above) Fraction fl (1,5); Fraction f2 (3,4) Fraction f3; Fraction f4 f3 f1 f2 f4 f1 f2; cout f3 f3 print //should print f3 3/20 cout. "VnInf4 f4 print //should 19/20 c. Overload the KK operator to print information about an object that invokes it It will be same task done by print method. Test code shown below in red (added to existing code from above) Fraction fl (1,5); Fraction f2 (3,4) Fraction f3; Fraction f4 f3 f1 f2 f4

Explanation / Answer

a. Overloading the Fraction * operator:

Fraction operator*(Fraction second)
{
Fraction temp;
temp.setNumerator(numerator + second.getNumerator());
temp.setDenominator(denominator + second.getDenominator());
return temp;
}

b. Overloading the Fraction + operator:

Fraction operator+(Fraction second)
{
Fraction temp;
temp.setNumerator(numerator*second.getDenominator() + denominator*second.getNumerator());
temp.setDenominator(denominator * second.getDenominator());
return temp;
}

c. Overloading the Fraction << operator:

ostream &operator<<( ostream &output, const Fraction &one)
{
output << "Fraction one is: " << one.f1 << " ";
output << "Fraction two is: " << one.f2 << " " << endl;

return output; // enables cascading eg cout << a << b;
}

// overloaded stream-extraction operator
istream &operator>>( istream &input, Fraction &one)
{
input >> one.f1 >> one.f2;
return input; // enables cascading eg cin >> a >> b;
}