/// <summary>
        /// Вывод корней
        /// </summary>
        public void PrintRoots(double a, double b, double c)
        {
            RootsResult result = this.CalculateRoots(a, b, c);

            Console.Write("Коэффициенты: a={0}, b={1}, c={2}. ", a, b, c);
            string resultType = result.GetType().Name;

            if (resultType == "NoRoots")
            {
                Console.WriteLine("Корней нет.");
            }
            else if (resultType == "OneRoot")
            {
                OneRoot rt1 = (OneRoot)result;
                Console.WriteLine("Один корень {0}", rt1.root);
            }
            else if (resultType == "TwoRoots")
            {
                TwoRoots rt2 = (TwoRoots)result;
                Console.WriteLine("Два корня {0} и {1}", rt2.root1, rt2.root2);
            }
        }
Exemplo n.º 2
0
        public void PrintRoots(double a, double b, double c)
        {
            RootsResult result = this.CalculateRoots(a, b, c);

            Console.Write("Коэффициенты: a={0}, b={1}, c={2}. ", a, b, c);
            string resultType = result.GetType().Name;

            if (resultType == "NoRoots")
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\nКорней нет.");
            }
            else if (resultType == "OneRoot")
            {
                OneRoot rt1 = (OneRoot)result;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("\nОдинкорень {0}", rt1.root);
            }
            else if (resultType == "TwoRoots")
            {
                TwoRoots rt2 = (TwoRoots)result;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("\nДва корня: {0} и {1}", rt2.root1, rt2.root2);
            }
            else if (resultType == "ThreeRoots")
            {
                ThreeRoots rt3 = (ThreeRoots)result;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("\nТри корня: {0}, {1}, {2}", rt3.root1, rt3.root2, rt3.root3);
            }
            else if (resultType == "FourRoots")
            {
                FourRoots rt4 = (FourRoots)result;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("\nЧетыре корня: {0}, {1}, {2}, {3}", rt4.root1, rt4.root2, rt4.root3, rt4.root4);
            }
        }