const Fraction operator/(const Fraction& term1, const Fraction& term2) { //Multiplies by the reciprocal of term2 Fraction result; result.SetNumerator(((term1.GetWhole() * term1.GetDenominator()) + term1.GetNumerator()) * term2.GetDenominator()); result.SetDenominator(term1.GetDenominator() * ((term2.GetWhole() * term2.GetDenominator()) + term2.GetNumerator())); result.Normalize(); return result; }
const Fraction operator-(const Fraction& term1, const Fraction& term2) { //Finds least commons denominator, turns into improper fraction and then subtracted Fraction frac1(0, ((term1.GetWhole() * term1.GetDenominator() * term2.GetDenominator()) + (term1.GetNumerator() * term2.GetDenominator())), (term1.GetDenominator() * term2.GetDenominator())); Fraction frac2(0, ((term2.GetWhole() * term2.GetDenominator() * term1.GetDenominator()) + (term2.GetNumerator() * term1.GetDenominator())), (term1.GetDenominator() * term2.GetDenominator())); Fraction result(0, (frac1.GetNumerator() - frac2.GetNumerator()), frac1.GetDenominator()); result.Normalize(); return result; }
const Fraction operator*(const Fraction& term1, const Fraction& term2) { //Turned into improper fractions and then mulitplied through Fraction result; result.SetNumerator(((term1.GetWhole() * term1.GetDenominator()) + term1.GetNumerator()) * ((term2.GetWhole() * term2.GetDenominator()) + term2.GetNumerator())); result.SetDenominator(term1.GetDenominator() * term2.GetDenominator()); result.Normalize(); return result; }