public static RationalOverloaded operator *(RationalOverloaded num1, RationalOverloaded num2) { int numer = num1.numerator * num2.GetNumerator(); int denom = num1.denominator * num2.GetDenominator(); RationalOverloaded result = new RationalOverloaded(numer, denom); return(result); }
static void Main(string[] args) { RationalOverloaded rational_a = new RationalOverloaded(2, 4); RationalOverloaded rational_b = new RationalOverloaded(4, 5); RationalOverloaded rational_c = rational_a * rational_b; Console.WriteLine("The multiply is {0}", rational_c.StrVal()); //RationalOverloaded ratio }
public static RationalOverloaded operator -(RationalOverloaded num1, RationalOverloaded num2) { int commonDenom = num1.denominator * num2.GetDenominator(); int numer1 = num1.numerator * num2.GetDenominator(); int numer2 = num2.GetNumerator() * num1.denominator; int difference = numer1 - numer2; RationalOverloaded result = new RationalOverloaded(difference, commonDenom); return(result); }
public static RationalOverloaded operator +(RationalOverloaded num1, RationalOverloaded num2) { int commonDenom = num1.denominator * num2.GetDenominator(); int numer1 = num1.numerator * num2.GetDenominator(); int numer2 = num2.GetNumerator() * num1.denominator; int sum = numer1 + numer2; RationalOverloaded result = new RationalOverloaded(sum, commonDenom); return(result); }