public Rational Multiply(Rational num2) { int numer = numerator * num2.GetNumerator(); int denom = denominator * num2.GetDenominator(); Rational result = new Rational(numer, denom); return result; }
public Rational Divide(Rational num2) { int numer = num2.GetDenominator(); int denom = num2.GetNumerator(); Rational r = new Rational(numer, denom); Rational result = Multiply(r); return result; }
public Rational Add(Rational num2) { int commonDenom = denominator * num2.GetDenominator(); int numer1 = numerator * num2.GetDenominator(); int numer2 = num2.GetNumerator() * denominator; int sum = numer1 + numer2; Rational result = new Rational(sum, commonDenom); return result; }
public Rational Subtract(Rational num2) { int commonDenom = denominator * num2.GetDenominator(); int numer1 = numerator * num2.GetDenominator(); int numer2 = num2.GetNumerator() * denominator; int difference = numer1 - numer2; Rational result = new Rational(difference, commonDenom); return result; }