コード例 #1
0
        static void Main(string[] args)
        {
            #region Question 1
            // Q1. Create 4 Rational objects, print them
            Console.WriteLine("[Question 1 : Create 4 Rational objects, print them]");
            Rational rationalNumbers1 = new Rational(-1, 100);
            Rational rationalNumbers2 = new Rational(2, 100);
            Rational rationalNumbers3 = new Rational(3, 100);
            Rational rationalNumbers4 = new Rational(4, 100);

            Console.WriteLine("Rational Number 1: " + rationalNumbers1);
            Console.WriteLine("Rational Number 2: " + rationalNumbers2);
            Console.WriteLine("Rational Number 3: " + rationalNumbers3);
            Console.WriteLine("Rational Number 4: " + rationalNumbers4);
            #endregion

            Console.WriteLine("\n-------------------------------------------------\n");

            #region Question 2
            Console.WriteLine("[Question 2: Do some addition and subtraction and print again]");
            Console.WriteLine("1. Addition");
            rationalNumbers1.IncreaseBy(rationalNumbers2);
            Console.WriteLine("Rational Number 5 (Rational Number 1 + Rational Number 2): " + rationalNumbers1);

            rationalNumbers3.IncreaseBy(rationalNumbers4);
            Console.WriteLine("Rational Number 6 (Rational Number 3 + Rational Number 4): " + rationalNumbers3);

            Console.WriteLine("\n2. Subtraction");
            rationalNumbers3.DecreaseBy(rationalNumbers1);
            Console.WriteLine("Rational Number 7 (Rational Number 5 - Rational Number 6): " + rationalNumbers3);
            #endregion
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("[Q1. Create 4 Rational objects, print them]");
            Rational rationalNumber1 = new Rational(1, 2);
            Rational rationalNumber2 = new Rational(2, 3);
            Rational rationalNumber3 = new Rational(3, 4);
            Rational rationalNumber4 = new Rational(4, 5);

            Console.WriteLine(" - Rational Number1: " + rationalNumber1.ToString());
            Console.WriteLine(" - Rational Number2: " + rationalNumber2.ToString());
            Console.WriteLine(" - Rational Number3: " + rationalNumber3.ToString());
            Console.WriteLine(" - Rational Number4: " + rationalNumber4.ToString());

            Console.WriteLine("\n[Q2.Do some addition and subtraction and print again]");
            rationalNumber1.IncreaseBy(rationalNumber2);
            rationalNumber4.DecreaseBy(rationalNumber3);

            Console.WriteLine(" Rational Number1 + Rational Number2: " + rationalNumber1);
            Console.WriteLine(" Rational Number4 - Rational Number3: " + rationalNumber4);

            Console.WriteLine("\n-----Enhancement: Based on Rational Number Calculation Formula]-----");
            Console.WriteLine("[E1. Add new 4 Rational objects, print them]");
            Rational rationalNumber5 = new Rational(1, 2);
            Rational rationalNumber6 = new Rational(2, 3);
            Rational rationalNumber7 = new Rational(3, 4);
            Rational rationalNumber8 = new Rational(4, 5);

            Console.WriteLine(" - Rational Number5: " + rationalNumber5.ToString());
            Console.WriteLine(" - Rational Number6: " + rationalNumber6.ToString());
            Console.WriteLine(" - Rational Number7: " + rationalNumber7.ToString());
            Console.WriteLine(" - Rational Number8: " + rationalNumber8.ToString());

            Console.WriteLine("\n[E2. Do some addition and subtraction and print again by rational calculation formula]");
            rationalNumber5.IncreaseBy(rationalNumber6);
            Console.WriteLine(" Rational Number5 + Rational Number6: " + rationalNumber5);

            rationalNumber8.DecreaseBy(rationalNumber7);
            Console.WriteLine(" Rational Number8 - Rational Number7: " + rationalNumber8);

            Console.WriteLine("\n[E3. Rational Number Optimization]");
            Rational rationalNumber9 = new Rational(32, 12);

            Console.WriteLine(" - Rational Number9: " + rationalNumber9.ToString());
            rationalNumber9.Optimization();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Rational exp1 = new Rational();     // Object with 0 Arguments
            Rational exp2 = new Rational(5);    // Object with 1 Argument
            Rational exp3 = new Rational(7, 3); // Object with 2 Arguments

            //Displaying Rational Numbers
            Console.WriteLine("First Number: {0}", exp1);
            Console.WriteLine("Seond Number: {0}", exp2);
            Console.WriteLine("Third Number: {0}", exp3);

            //Increasing exp1 by exp2
            exp1.IncreaseBy(exp2);
            Console.WriteLine("First Number After Increasing: {0}", exp1);

            //Decreasing exp2 by exp3
            exp2.DecreaseBy(exp3);
            Console.WriteLine("Second Number After Decreasing: {0}", exp2);
        }