Esempio n. 1
0
        public static bool RandomInput()
        {
            Console.Clear();
            Random rnd = new Random();

            Console.WriteLine("Enter the quantity of equatations:");
            int Quantity;

            while (!Int32.TryParse(Console.ReadLine(), out Quantity) || Quantity < 3 ||
                   Quantity > 20)
            {
                Console.Write("Wrong input, try again : ");
            }
            Matrix Matrix = new Matrix(Quantity);

            for (int i = 0; i < Quantity; i++)
            {
                for (int j = 0; j < Quantity + 1; j++)
                {
                    Matrix.InputMatrix[i, j] = rnd.Next(-20, 20);
                }
            }


            Matrix.GenerateWorkingMatrix();
            Matrix.Print();
            Computations comps = new Computations();

            comps.Solve(Matrix);
            Matrix.PrintResult();

            return(true);
        }
Esempio n. 2
0
        public static bool KeyboardInput()
        {
            Console.Clear();
            Console.Write("Enter the quantity of equatations:");
            int Quantity;

            while (!Int32.TryParse(Console.ReadLine(), out Quantity) || Quantity < 3 ||
                   Quantity > 20)
            {
                Console.Write("Wrong input, try again : ");
            }
            Matrix Matrix = new Matrix(Quantity);

            for (int i = 0; i < Quantity; i++)
            {
                for (int j = 0; j < Quantity + 1; j++)
                {
                    Console.WriteLine($"Input the element №{j} on the string №{i}");
                    double Element;
                    while (!Double.TryParse(Console.ReadLine(), out Element))
                    {
                        Console.WriteLine("Wrong input, try again : ");
                    }
                    Matrix.InputMatrix[i, j] = Element;
                }
            }



            Matrix.GenerateWorkingMatrix();
            Matrix.Print();
            Computations comps = new Computations();

            comps.Solve(Matrix);
            Matrix.PrintResult();

            return(true);
        }
Esempio n. 3
0
        public static bool FileInput()
        {
            Console.Clear();
            var FileToOpen = new OpenFileDialog
            {
                Filter = "Текстовый файл(*.txt)|*.txt"
            };

            FileToOpen.ShowDialog();
            if (FileToOpen.FileName == "")
            {
                return(true);
            }
            string Path = FileToOpen.FileName;

            using (StreamReader SR = File.OpenText(Path))
            {
                if (!Int32.TryParse(SR.ReadLine(), out int Quantity) || Quantity < 3 ||
                    Quantity > 20)
                {
                    Console.WriteLine("The file is wrong: quantity is set wrong");
                    return(true);
                }
                string[] Elements       = SR.ReadLine().Split(' ');
                int      QuantityInFile = 0;
                foreach (var str in Elements)
                {
                    QuantityInFile++;
                    if (!Double.TryParse(str, out double useless))
                    {
                        Console.WriteLine("The file is wrong: one of the elements can't be parsed to Double");
                        return(true);
                    }
                }
                if (QuantityInFile != Quantity * (Quantity + 1))
                {
                    Console.WriteLine("The file is wrong: quantity of elements doesn't match the one set in file");
                    return(true);
                }
                Matrix Matrix = new Matrix(Quantity);

                int ElementNumber = 0;
                for (int i = 0; i < Quantity; i++)
                {
                    for (int j = 0; j < Quantity + 1; j++)
                    {
                        Matrix.InputMatrix[i, j] = Convert.ToDouble(Elements[ElementNumber]);
                        ElementNumber++;
                    }
                }


                Matrix.GenerateWorkingMatrix();
                Matrix.Print();
                Computations comps = new Computations();
                comps.Solve(Matrix);
                Matrix.PrintResult();
            }

            return(true);
        }