Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int choice = 4;

            while (choice != 0)
            {
                Console.WriteLine("Введите"
                                  + "1) заполнениес клавиатуры"
                                  + "2) заполнение с файла"
                                  + "0) Выход");
                choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.Write("Введите а =");
                    double a = Convert.ToDouble(Console.ReadLine());
                    Console.Write("Введите b =");
                    double b = Convert.ToDouble(Console.ReadLine());
                    Console.Write("Введите c =");
                    double c = Convert.ToDouble(Console.ReadLine());
                    if (a == 0)
                    {
                        Console.WriteLine("Это не квадратное уравнение");
                        break;
                    }
                    KeyBoard.Answer(a, b, c);
                    break;

                case 2:
                    Console.WriteLine("Введите путь к файлу");
                    string        uri = Console.ReadLine();
                    InputFromFile n   = new InputFromFile();
                    n.FromFile(uri);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public bool FromFile(string uri)
        {
            double[] arr = File.ReadAllText(uri).Split(' ').Select(q => double.Parse(q)).ToArray();
            double   a   = arr[0];

            if (a == 0)
            {
                return(false); throw new NotImplementedException("this is not quadratic equation");
            }
            double b = arr[1];
            double c = arr[2];
            double d = b * b - 4 * a * c;

            Console.WriteLine($"{c}");
            if (d < 0)
            {
                Console.WriteLine("Дискриминант меньше нуля");
            }
            InputFromFile n = new InputFromFile();

            if (d == 0)
            {
                n.x = (-b / (2 * a));
                Console.WriteLine("Дискриминант =0 =>" +
                                  $"x={n.x}");
            }
            if (d > 0)
            {
                n.x1 = ((-b - Math.Sqrt(d)) / (2 * a));
                n.x2 = ((-b + Math.Sqrt(d)) / (2 * a));
                Console.WriteLine("Дискриминант >0" +
                                  $"x1 = {n.x1}" +
                                  $"x2 = {n.x2}");
            }
            return(true);
        }