Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //створення об'єків систем
            SystemFactory factory = new SystemFactory();

            ISystem system2 = factory.CreateLinearSystem2();
            ISystem system3 = factory.CreateLinearSystem3();

            Console.WriteLine("\nSystem 1 (2 rows 2 vars): ");
            system2.Show();    //вивід через перевантажений метод
            Console.WriteLine("\nSystem 1 (3 rows 3 vars): ");
            system3.Show();    //вивід системи в консоль


            Console.WriteLine("Enter x1 x2");
            var x = Console.ReadLine()
                    .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(f => double.Parse(f)).ToArray();

            Console.WriteLine("X is " + (
                                  // notify wrapper   -> comparison  -  system   -> method
                                  new ComparableNotifier(new Comparable(system2)).IsEqualTo(x)
                ? "the root" : "not root") + " of equatation");

            Console.WriteLine("Enter x1 x2 x3");
            x = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(f => double.Parse(f)).ToArray();
            Console.WriteLine("X is " + (new Comparable(system3).IsEqualTo(x) ? "the root" : "not root") + " of equatation");

            system2 = new LSystem2();

            //ввід вручну
            //для правильної системи
            // 5*1+5+1=10
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.Write("Enter line[" + (i + 1) + "] coef[" + (j + 1) + "]: ");
                    system2.SetCoef(i, j, double.Parse(Console.ReadLine()));
                }
                Console.Write("Enter line[" + (i + 1) + "] -> B: ");
                system2.SetB(i, double.Parse(Console.ReadLine()));
            }

            Console.WriteLine("Enter x1 x2");
            x = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(f => double.Parse(f)).ToArray();
            Console.WriteLine("X is " + (new Comparable(system2).IsEqualTo(x) ? "the root" : "not root") + " of equatation");

            Console.ReadLine();
        }