Esempio n. 1
0
        static void Main()
        {
            RationalNum first  = new RationalNum(1, 6);
            RationalNum second = new RationalNum(4, 8);

            List <RationalNum> numbers = new List <RationalNum>();

            numbers.Add(first);
            numbers.Add(second);



            while (true)
            {
                Console.WriteLine("1 - Add new number\n2 - View number\n3 - Math operations\n4 - Compare\n5 - Simplify all numbers\n6 - Exit");

                switch (Console.ReadKey(false).Key)
                {
                case ConsoleKey.D1: AddNumbers(numbers); Console.Clear(); break;

                case ConsoleKey.D2: ViewNumbers(numbers); Console.Clear(); break;

                case ConsoleKey.D3: Calculate(numbers); Console.Clear(); break;

                case ConsoleKey.D4: NumComparer(numbers); Console.Clear(); break;

                case ConsoleKey.D5: AllSimple(numbers); break;

                case ConsoleKey.D6: return;
                }
            }
        }
Esempio n. 2
0
        static void NumChoice(List <RationalNum> nums, out RationalNum first, out RationalNum second)
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("Choose 2 numbers by their id");
                for (int i = 0; i < nums.Count; i++)
                {
                    Console.WriteLine(i + ") " + nums[i].ToString("n"));
                }

                Console.WriteLine("First id : ");
                if (!int.TryParse(Console.ReadLine(), out int index))
                {
                    continue;
                }

                if (index >= nums.Count)
                {
                    continue;
                }

                first = nums[index];

                Console.WriteLine("Second id : ");
                if (!int.TryParse(Console.ReadLine(), out index))
                {
                    continue;
                }
                if (index >= nums.Count)
                {
                    continue;
                }

                second = nums[index];
                return;
            }
        }
Esempio n. 3
0
        static public void AddNumbers(List <RationalNum> nums)
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("Choose the format of input number : \n1 - Numerator/Denominator\n2 - Numerator.Denominator");
                switch (Console.ReadKey(false).Key)
                {
                case ConsoleKey.D1: Console.Clear(); Console.WriteLine("Input\n"); nums.Add(RationalNum.ConvertToRat(Console.ReadLine(), "n")); return;

                case ConsoleKey.D2: Console.Clear(); Console.WriteLine("Input\n"); nums.Add(RationalNum.ConvertToRat(Console.ReadLine(), "s")); return;

                default: Console.WriteLine("Incorrect input"); break;
                }
                continue;
            }
        }