Esempio n. 1
0
 public static Rational operator *(Rational num1, Rational num2)
 {
     int numer = num1.numerator * num2.GetNumerator();
     int denom = num1.denominator * num2.GetDenominator();
     Rational result = new Rational(numer, denom);
     return result;
 }
Esempio n. 2
0
 public static Rational operator -(Rational num1, Rational num2)
 {
     int commonDenom = num1.denominator * num2.GetDenominator();
     int numer1 = num1.numerator * num2.GetDenominator();
     int numer2 = num2.GetNumerator() * num1.denominator;
     int difference = numer1 - numer2;
     Rational result = new Rational(difference, commonDenom);
     return result;
 }
Esempio n. 3
0
 public static Rational operator +(Rational num1, Rational num2)
 {
     int commonDenom = num1.denominator * num2.GetDenominator();
     int numer1 = num1.numerator * num2.GetDenominator();
     int numer2 = num2.GetNumerator() * num1.denominator;
     int sum = numer1 + numer2;
     Rational result = new Rational(sum, commonDenom);
     return result;
 }
Esempio n. 4
0
            public static void Main(string[] args)
            {
                Rational a = new Rational(3, 4);
                Rational b = new Rational(4, 5);

                Rational c = a + b;
                Console.WriteLine(c.StrVal());
                Console.WriteLine(c.ToString());

                c = b - a;
                Console.WriteLine(c.StrVal());
                Console.WriteLine(c.ToString());
            }