Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.1 kB
2
Indexable
Never
using System;

namespace Practice
{
    internal class Program
    {
        public static void Main()
        {
            Console.WriteLine("Введите a: ");
            double a = double.Parse(Console.ReadLine());

            Console.WriteLine("Введите b: ");
            double b = double.Parse(Console.ReadLine());

            Console.WriteLine("Введите c: ");
            double c = double.Parse(Console.ReadLine());

            Console.WriteLine("Введите начальное значение x: ");
            double xStart = double.Parse(Console.ReadLine());

            Console.WriteLine("Введите конечное значение x: ");
            double xEnd = double.Parse(Console.ReadLine());

            Console.WriteLine("Введите шаг: ");
            double step = double.Parse(Console.ReadLine());

            MathFunction mathFunction = new MathFunction(a, b, c);

            Console.WriteLine("Значения функции для x < 1 и c != 0:");
            mathFunction.PrintTable(xStart, xEnd, step, MathFunction.Condition1);

            Console.WriteLine("Значения функции для x > 1.5 и c = 0:");
            mathFunction.PrintTable(xStart, xEnd, step, MathFunction.Condition2);

            Console.WriteLine("Значения функции для остальных значений x и c:");
            mathFunction.PrintTable(xStart, xEnd, step, MathFunction.Condition3);
        }

    }
    internal class MathFunction
    {
        private double a;
        private double b;
        private double c;

        public MathFunction(double a, double b, double c)
        {
            this.a = a;
            this.b = b;
            this.c = c;
        }
        public static double Condition1(double x, double a, double b, double c)
        {
            if (c < 0 && x != 0)
            {
                return -a * x / c;
            }

            return 0;
        }

        public static double Condition2(double x, double a, double b, double c)
        {
            if (c > 0 && x == 0)
            {
                return 0;
            }

            return 0;
        }

        public static double Condition3(double x, double a, double b, double c)
        {
            if ((x < 1 && c == 0) || (x > 1 && x <= 1.5) || (x > 1.5 && c != 0))
            {
                return b * x / Math.Abs(c - a);
            }

            return 0;
        }

        public void PrintTable(double xStart, double xEnd, double step, Func<double, double, double, double, double> function)
        {
            Console.WriteLine("|    x    |    F    |");
            Console.WriteLine("--------------------");

            for (double x = xStart; x <= xEnd; x += step)
            {
                double result = function(x, a, b, c);

                Console.WriteLine("| {0,6:F2} | {1,6:F2} |", x, result);
            }
        }
    }
}