예제 #1
0
        public static Rational operator /(Rational _a, Rational _b)
        {
            int tempn, tempd;
            tempn = _a.numerator * _b.denominator;
            tempd = _a.denominator * _b.numerator;
            Rational Rationaltemp = new Rational(tempn, tempd);

            return Rationaltemp;
        }
예제 #2
0
        public Rational Devides(Rational _b)
        {
            int bn, bd, tempn, tempd;
            bn = _b.numerator;
            bd = _b.denominator;
            // 已修正变量错误
            tempn = numerator * bd;
            tempd = denominator * bn;
            Rational Rationaltemp = new Rational(tempn, tempd);

            return Rationaltemp;
        }
예제 #3
0
        public Rational Times(Rational _b)
        {
            int tempn, tempd;
            tempn = _b.numerator;
            tempd = _b.denominator;
            tempn = numerator * tempn;
            tempd = denominator * tempd;
            Rational Rationaltemp = new Rational(tempn, tempd);

            return Rationaltemp;
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("input numerator 1");
            int numer1 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("input denominator 1");
            int denom1 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("input numerator 2");
            int numer2 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("input denominator 2");
            int denom2 = Int32.Parse(Console.ReadLine());
            // Does not check for exceptions.

            Rational x = new Rational(numer1, denom1);
            Rational y = new Rational(numer2, denom2);

            Console.WriteLine($"x: {x}");
            Console.WriteLine($"y: {y}");
            Console.WriteLine($"equals: {x.Equals(y)}");
            Console.WriteLine($"==: {x == y}");
            Console.WriteLine($"!=: {x != y}");
            Console.WriteLine($"plus: {x.Plus(y)}");
            Console.WriteLine($"+: {x + y}");
            Console.WriteLine($"minus: {x.Minus(y)}");
            Console.WriteLine($"-: {x - y}");
            Console.WriteLine($"times: {x.Times(y)}");
            Console.WriteLine($"*: {x * y}");
            Console.WriteLine($"devides: {x.Devides(y)}");
            Console.WriteLine($"/: {x / y}");
            Console.ReadLine();
        }
예제 #5
0
 public Boolean Equals(Rational that)
 {
     if (this.numerator == 0 && that.numerator == 0)
     { return true; }
     Reduce();
     if ((this.numerator == that.numerator) && (this.denominator == that.denominator))
     { return true; }
     else
     { return false; }
 }