public void AddFigure()
        {
            for (int i = 0; i < figure.Length; i++)
            {
                Console.WriteLine("Which figure do you want to add?");
                Console.WriteLine("1 - Triangle");
                Console.WriteLine("2 - Trapezoid");
                Console.WriteLine("3 - Square");
                Console.WriteLine("4 - Rhombus");
                Console.WriteLine("5 - Rectangle");
                Console.WriteLine("6 - Parallelogram");
                Console.WriteLine("7 - Ellips");
                Console.WriteLine("8 - Circle");

                int choise = int.Parse(Console.ReadLine());

                switch (choise)
                {
                case 1:
                    Console.WriteLine("Enter the length of the sides of the triangle:");

                    side1 = double.Parse(Console.ReadLine());

                    side2 = double.Parse(Console.ReadLine());

                    side3 = double.Parse(Console.ReadLine());

                    Triangle triangle = new Triangle(side1, side2, side3);

                    triangle.Perimetr();

                    figure[i] = triangle;

                    break;

                case 2:
                    Console.WriteLine("Enter the length of the firstBase/secondBase/height/firstSide/secondSide of the trapezoid:");

                    base1 = double.Parse(Console.ReadLine());

                    base2 = double.Parse(Console.ReadLine());

                    height = double.Parse(Console.ReadLine());

                    side1 = double.Parse(Console.ReadLine());

                    side2 = double.Parse(Console.ReadLine());

                    Trapezoid trapezoid = new Trapezoid(base1, base2, height, side1, side2);

                    figure[i] = trapezoid;

                    break;

                case 3:
                    Console.WriteLine("Enter the length of the side of the square:");

                    side1 = double.Parse(Console.ReadLine());

                    Square square = new Square(side1);

                    figure[i] = square;

                    break;

                case 4:
                    Console.WriteLine("Enter the length of the side/height of the rhombus:");

                    side1 = double.Parse(Console.ReadLine());

                    height = double.Parse(Console.ReadLine());

                    Rhombus rhombus = new Rhombus(side1, height);

                    figure[i] = rhombus;

                    break;

                case 5:
                    Console.WriteLine("Enter the length of the side1/side2 of the rectangle:");

                    side1 = double.Parse(Console.ReadLine());

                    side2 = double.Parse(Console.ReadLine());

                    Rectangle rectangle = new Rectangle(side1, side2);

                    figure[i] = rectangle;

                    break;

                case 6:
                    Console.WriteLine("Enter the length of the firstSide/secondSide/base/height of the parallelogram:");

                    side1 = double.Parse(Console.ReadLine());

                    side2 = double.Parse(Console.ReadLine());

                    base1 = double.Parse(Console.ReadLine());

                    height = double.Parse(Console.ReadLine());

                    Parallelogram parallelogram = new Parallelogram(side1, side2, base1, height);

                    figure[i] = parallelogram;

                    break;

                case 7:
                    Console.WriteLine("Enter the length of the minorAxis/majorAxis of the elleps:");

                    minorAxis = double.Parse(Console.ReadLine());

                    majorAxis = double.Parse(Console.ReadLine());

                    figure[i] = new Ellipse(minorAxis, majorAxis);

                    break;

                case 8:
                    Console.WriteLine("Enter the length of radius of the circle:");

                    radius = double.Parse(Console.ReadLine());

                    Circle circle = new Circle(radius);

                    figure[i] = circle;

                    break;

                default:
                    Console.WriteLine("No such number, only from 1 to 8");

                    break;
                }
            }
        }
Exemple #2
0
        //Разработать абстрактный класс Геометрическая фигура с методами Площадь фигуры и
        //Периметр фигуры.Разработать классы-наследники:Треугольник, Квадрат, Ромб, Прямоугольник,
        //Параллелограмм, Трапеция, Круг, Эллипс.Реализовать конструкторы которые однозначно
        //определяют обьекты данных классов.

        //Реализовать класс Составная фигура, который может
        //состоять из любого кол-ва Геометрических фигур.
        //Для данного класса определить метод нахождения
        //площади фигуры. Создать диаграмму отношений классов.
        static void Main(string[] args)
        {
            Triangle triangle = new Triangle(2.4, 5.6, 7.9);

            triangle.Perimetr();
            triangle.Area();
            triangle.Print();
            Console.WriteLine();

            Square square = new Square(12.5);

            square.Perimetr();
            square.Area();
            square.Print();
            Console.WriteLine();

            Rhombus rhombus = new Rhombus(2.5, 3.5);

            rhombus.Perimetr();
            rhombus.Area();
            rhombus.Print();
            Console.WriteLine();

            Rectangle rectangle = new Rectangle(3.4, 6.7);

            rectangle.Perimetr();
            rectangle.Area();
            rectangle.Print();
            Console.WriteLine();

            Parallelogram parallelogram = new Parallelogram(2.4, 5.6, 4.4, 7.8);

            parallelogram.Perimetr();
            parallelogram.Area();
            parallelogram.Print();
            Console.WriteLine();

            Trapezoid trapezoid = new Trapezoid(6.8, 3.7, 5.3, 4.2, 5.1);

            trapezoid.Perimetr();
            trapezoid.Area();
            trapezoid.Print();
            Console.WriteLine();

            Circle circle = new Circle(5.2);

            circle.Perimetr();
            circle.Area();
            circle.Print();
            Console.WriteLine();

            Ellipse ellipse = new Ellipse(4.6, 8.9);

            ellipse.Perimetr();
            ellipse.Area();
            ellipse.Print();
            Console.WriteLine();

            try
            {
                CompositeFigure compositeFigure = new CompositeFigure();
                compositeFigure.AddFigure();
                compositeFigure.Area();
                compositeFigure.Print();
            }
            catch (Exception)
            {
                Console.WriteLine("You entered incorrect data");
            }
        }