示例#1
0
        public static ListOfMatrix ListPut()
        {
            Console.Write("Введите количество матриц в списке: ");
            int n = 0;

            try
            {
                n = int.Parse(Console.ReadLine());
            }
            catch
            {
                throw new FormatException("Неверно введена величина!");
            }
            Console.WriteLine("Введите четыре цифры (элементы квадратной матрицы)");
            ListOfMatrix list = new ListOfMatrix();

            for (int i = 0; i < n; i++)
            {
                Console.Write("Новая матрица: ");
                string mat    = Console.ReadLine();
                Matrix matrix = new Matrix();
                if (!Matrix.TryParseMatrix(mat, matrix))
                {
                    throw new FormatException("Неверно введена матрица!");
                }
                list.AddToList(matrix);
                Console.WriteLine();
            }
            return(list);
        }
示例#2
0
        /* Класс, содержащий функции считывания списка матриц из файла
         * и записи матриц в файл. Перехват исключений при неверной работе
         * с файлами, выходе за пределы массива, деления на 0 (при нахождении обратной)
         */
        public static ListOfMatrix FileRead()
        {
            string str = @"C:\VIS\test.txt";

            string[] readstr;
            if (File.Exists(str))
            {
                readstr = File.ReadAllLines(str);
            }
            else
            {
                throw new FileNotFoundException("Файл не найден");
            }
            if (readstr.Length == 0)
            {
                throw new ArgumentNullException("Файл пустой! lul");
            }
            ListOfMatrix list = new ListOfMatrix();
            Matrix       matrix;

            for (int i = 0; i < readstr.Length; i++)
            {
                string[] ptr = readstr[i].Split(' ');
                if (ptr.Length != 4)
                {
                    throw new ArgumentNullException("Неверно введены данные!!!");
                }
                matrix = new Matrix(double.Parse(ptr[0]), double.Parse(ptr[1]), double.Parse(ptr[2]), double.Parse(ptr[3]));
                list.AddToList(matrix);
            }
            return(list);
        }