static void Main(string[] args)
        {
            //instantiating the 4 fractions
            Rational fraction1 = new Rational();
            Rational fraction2 = new Rational(2);
            Rational fraction3 = new Rational(denominator:3,numerator:2);
            Rational fraction4 = new Rational(3, 4);

            //Sum of the fractions
            Console.WriteLine($"Performing the sum of {fraction1} and {fraction3}");
            Console.Write($"{fraction1} + {fraction3} = ");
            fraction1.IncreaseBy(fraction3);
            Console.WriteLine(fraction1);
            Console.WriteLine($"Performing the sum of {fraction3} and {fraction4}");
            Console.Write($"{fraction3} + {fraction4} = ");
            fraction3.IncreaseBy(fraction4);
            Console.WriteLine(fraction3);

            //loading back Fraction 1 and 3 to the original values
            fraction1 = new Rational();
            fraction2 = new Rational(numerator:2);
            fraction3 = new Rational(denominator:3);
            fraction4 = new Rational(3, 4);

            //Subtraction of the fractions
            Console.WriteLine($"Performing the subtraction of {fraction2} and {fraction3}");
            Console.Write($"{fraction2} - {fraction3} = ");
            fraction2.DecreaseBy(fraction3);
            Console.WriteLine(fraction2);
            Console.WriteLine($"Performing the subtraction of {fraction2} and {fraction4}");
            Console.Write($"{fraction2} - {fraction4} = ");
            fraction2.DecreaseBy(fraction4);
            Console.WriteLine(fraction2);
        }
        static void Main(string[] args)
        {
            int num1 = 2, num2 = 3, num3 = 7;

            Rational r1 = new Rational(num1, num2);
            Rational r2 = new Rational(num2, num1);
            Rational r3 = new Rational(num1, num3);
            Rational r4 = new Rational(num2, num3);
            //others
            Rational r5 = new Rational(num1, num1);
            Rational r6 = new Rational(num2, num2);
            Rational r7 = new Rational(num3, num3);
            Rational r8 = new Rational(num3, num1);

            Console.Write($"{r1} + {r5} is ");
            r1.IncreaseBy(r5);
            Console.WriteLine(r1);

            Console.Write($"{r2} + {r6} is ");
            r2.IncreaseBy(r6);
            Console.WriteLine(r2);


            Console.Write($"{r3} - {r7} is ");
            r3.DecreaseBy(r7);
            Console.WriteLine(r3);

            Console.Write($"{r4} - {r8} is ");
            r4.DecreaseBy(r8);
            Console.WriteLine(r8);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Rational fraction1 = new Rational(1, 2);
            Rational fraction2 = new Rational(5, 6);
            Rational fraction3 = new Rational(2, 5);
            Rational fraction4 = new Rational(5, 12);

            Console.WriteLine("Fraction 1: {0}, Fraction 2: {1}, Fraction 3: {2}, Fraction 4: {3}",fraction1,fraction2,fraction3,fraction4);

            fraction1.IncreaseBy(fraction2);
            Console.WriteLine("\nAdding Fraction 1 with Fraction 2: {0}",fraction1);

            fraction3.DecreaseBy(fraction4);
            Console.WriteLine("\nSubtraction Fraction 3 by Fraction 4: {0}", fraction3);
        }