Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int    choseLection;                              // For chosing Lection
            int    choseTasks;                                // For chosing Tasks
            int    page;                                      // for 4 Lection
            double x1, y1, x2, y2, radius, real, imagine;     // Input data
            double circuit, areaofthecircle, perimeter, area; // Output data

            Console.WriteLine(" ~ Chose Lection \n 2 - Second Lection \n 3 - Third Lection \n 4 - Fourth Lection");
            choseLection = Int32.Parse(Console.ReadLine());
            switch (choseLection)
            {
            case 2:
                Console.Clear();
                Console.WriteLine(" ~ Chose Task \n From 1 to 5");
                choseTasks = Int32.Parse(Console.ReadLine());
                switch (choseTasks)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine(" ~ Enter Coordinates for Rectangle");
                    Console.Write("x1: ");
                    x1 = Double.Parse(Console.ReadLine());
                    Console.Write("y1: ");
                    y1 = Double.Parse(Console.ReadLine());
                    Console.Write("x2: ");
                    x2 = Double.Parse(Console.ReadLine());
                    Console.Write("y2: ");
                    y2 = Double.Parse(Console.ReadLine());
                    Lection2Library.Rectangle recTask1 = new Lection2Library.Rectangle(x1, y1, x2, y2);
                    perimeter = recTask1.GetPerimeter();
                    Console.WriteLine($"Rectangle Perimeter = {perimeter}");
                    area = recTask1.GetArea();
                    Console.WriteLine($"Rectangle Area = {area}");
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine(" ~ Enter Coordinates for Rectangle");
                    Console.Write("x1: ");
                    x1 = Double.Parse(Console.ReadLine());
                    Console.Write("y1: ");
                    y1 = Double.Parse(Console.ReadLine());
                    Console.Write("x2: ");
                    x2 = Double.Parse(Console.ReadLine());
                    Console.Write("y2: ");
                    y2 = Double.Parse(Console.ReadLine());
                    RectangleAutoProperties recTask2 = new RectangleAutoProperties(x1, y1, x2, y2);
                    Console.WriteLine($"Rectangle Perimeter = {recTask2.GetPerimeter}");
                    Console.WriteLine($"Rectangle Area = {recTask2.GetArea}");
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine(" ~ Enter radius");
                    Console.Write("Radius: ");
                    radius = Double.Parse(Console.ReadLine());
                    Circle circleTask3 = new Circle();
                    circuit = circleTask3.Circuit(radius);
                    Console.WriteLine($"Circle Perimeter = {circuit}");
                    areaofthecircle = circleTask3.AreaOfTheCircle(radius);
                    Console.WriteLine($"Circle Area = {areaofthecircle}");
                    break;

                case 4:
                    Console.Clear();
                    Console.WriteLine(" ~ Enter Coordinates for static Rectangle");
                    Console.Write("x1: ");
                    x1 = Double.Parse(Console.ReadLine());
                    Console.Write("y1: ");
                    y1 = Double.Parse(Console.ReadLine());
                    Console.Write("x2: ");
                    x2 = Double.Parse(Console.ReadLine());
                    Console.Write("y2: ");
                    y2        = Double.Parse(Console.ReadLine());
                    perimeter = StaticRectangle.GetPerimeter(x1, y1, x2, y2);
                    Console.WriteLine($"Rectangle Perimeter = {perimeter}");
                    area = StaticRectangle.GetArea(x1, y1, x2, y2);
                    Console.WriteLine($"Rectangle Area = {area}");
                    Console.WriteLine(" ~ Enter radius for static Circle");
                    Console.Write("Radius: ");
                    radius  = Double.Parse(Console.ReadLine());
                    circuit = StaticCircle.Circuit(radius);
                    Console.WriteLine($"Circle Perimeter = {circuit}");
                    areaofthecircle = StaticCircle.AreaOfTheCircle(radius);
                    Console.WriteLine($"Circle Area = {areaofthecircle}");
                    break;

                case 5:
                    Console.Clear();
                    Console.WriteLine(" ~ Enter real number 1");
                    Console.Write("reZ: ");
                    real = Double.Parse(Console.ReadLine());
                    Console.WriteLine(" ~ Enter imagine number 1");
                    Console.Write("imZ: ");
                    imagine = Double.Parse(Console.ReadLine());
                    ComplexNumber num1 = new ComplexNumber(real, imagine);
                    Console.WriteLine(" ~ Enter real number 2");
                    Console.Write("reZ: ");
                    real = Double.Parse(Console.ReadLine());
                    Console.WriteLine(" ~ Enter imagine number 2");
                    Console.Write("imZ: ");
                    imagine = Double.Parse(Console.ReadLine());
                    ComplexNumber num2 = new ComplexNumber(real, imagine);
                    ComplexNumber num3, num4;
                    num3 = num1 * num2;
                    Console.WriteLine(num3.GetComplexNumber());
                    num4 = num1 / num2;
                    Console.WriteLine(num4.GetComplexNumber());
                    break;
                }
                break;

            case 3:
                Console.Clear();
                Console.WriteLine(" ~ Chose Task \n From 1 to 4");
                choseTasks = Int32.Parse(Console.ReadLine());
                switch (choseTasks)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine(" ~ Task #1");
                    Lection3Task1.Square square = new Lection3Task1.Square();
                    square.Draw();
                    Lection3Task1.Rectangle rect = new Lection3Task1.Rectangle();
                    rect.Draw();
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine(" ~ Task #2");
                    Lection3Task2.Square squareTask2 = new Lection3Task2.Square(2, 5);
                    squareTask2.Draw();
                    Lection3Task2.Rectangle rectTask2 = new Lection3Task2.Rectangle(1, 6);
                    rectTask2.Draw();
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine(" ~ Task #3");
                    Lection3Task3.Figure figure = new Lection3Task3.Figure(2, 5);
                    figure.Draw();
                    Lection3Task3.Square squareTask3 = new Lection3Task3.Square(2, 5);
                    squareTask3.Draw();
                    Lection3Task3.Rectangle rectTask3 = new Lection3Task3.Rectangle(1, 6);
                    rectTask3.Draw();
                    break;

                case 4:
                    Console.Clear();
                    Console.WriteLine(" ~ Task #4");
                    void DrawAll(params IDrawable[] array)
                    {
                        for (int i = 0; i < array.Length; i++)
                        {
                            array[i].Draw();
                        }
                    }

                    DrawAll(new Lection3Task4.Figure(1, 2), new Lection3Task4.Rectangle(2, 3), new Lection3Task4.Square(5, 5));
                    break;
                }
                break;

            case 4:
                Console.Clear();
                Console.WriteLine(" ~ Chose Task \n From 1 to 3");
                choseTasks = Int32.Parse(Console.ReadLine());
                switch (choseTasks)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine(" ~ Task #1");
                    Task1 task1 = new Task1();
                    task1.Show();
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine(" ~ Task #2");
                    Task2 task2 = new Task2();
                    task2.Show();
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine(" ~ Task #3");
                    Task3 task3 = new Task3();
                    task3.Show();
                    Console.Write("Input Page: ");
                    page = Int32.Parse(Console.ReadLine());
                    task3.DisplayPage(page);
                    break;
                }
                break;
            }
        }
Exemplo n.º 2
0
        static void Hometask1()
        {
            #region Testing all the classes related to Rectangle
            var top_left     = (x : 0.0, y : 4.0);
            var bottom_right = (x : 7.0, y : 0.0);
            Console.WriteLine("Enter coordinates:");
            try
            {
                Console.Write("X for the top left corner --> ");
                top_left.x = Convert.ToDouble(Console.ReadLine());
                Console.Write("Y for the top left corner --> ");
                top_left.y = Convert.ToDouble(Console.ReadLine());
                Console.Write("X for the bottom right corner --> ");
                bottom_right.x = Convert.ToDouble(Console.ReadLine());
                Console.Write("Y for the bottom rigth corner --> ");
                bottom_right.y = Convert.ToDouble(Console.ReadLine());
                Hometask1.Rectangle rec1 = new Hometask1.Rectangle(top_left, bottom_right);
                Console.WriteLine($"Testing Rectangle class:\nCoordinates:\n" +
                                  $"top left corner = {top_left}\n" +
                                  $"bottom rigth corner = {bottom_right}");

                Console.WriteLine($"Area: {rec1.GetArea()}");
                Console.WriteLine($"Perimeter: {rec1.GetPerimeter()}");
                Rectangle_2 rec2 = new Rectangle_2(top_left, bottom_right);
                Console.WriteLine($"Testing Rectangle class wich have automated properties instead of methods:");
                Console.WriteLine($"Area: {rec2.GetArea}");
                Console.WriteLine($"Perimeter: {rec2.GetPerimeter}");

                Console.WriteLine("Testing static Rectangle class:");
                Console.WriteLine($"Area: {StaticRectangle.GetArea(top_left, bottom_right)}");
                Console.WriteLine($"Perimeter: {StaticRectangle.GetPerimeter(top_left, bottom_right)}");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
            }
            #endregion
            #region Testing all the classes related to Circle
            Console.WriteLine("Testing Circle class:");
            Console.Write("Input the radius --> ");
            try
            {
                double radius = Convert.ToDouble(Console.ReadLine());
                Circle circle = new Circle(radius);
                Console.WriteLine($"Area: {circle.GetArea()}");
                Console.WriteLine($"Length: {circle.GetLength()}");

                Console.WriteLine("Testing static Circle class:");
                Console.WriteLine($"Area: {StaticCircle.GetArea(radius)}");
                Console.WriteLine($"Length: {StaticCircle.GetLength(radius)}");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
            }
            #endregion
            #region Testing ComplexNumber class
            try
            {
                Console.WriteLine("Testing ComplexNumber class:");
                Console.Write("Enter the real part --> ");
                double real = Convert.ToDouble(Console.ReadLine());
                Console.Write("Enter the imaginary part --> ");
                double        imaginary = Convert.ToDouble(Console.ReadLine());
                ComplexNumber ob1       = new ComplexNumber(real, imaginary);
                Console.WriteLine($"The first complex number: {ob1}");
                Console.Write("Enter the real part --> ");
                real = Convert.ToDouble(Console.ReadLine());
                Console.Write("Enter the imaginary part --> ");
                imaginary = Convert.ToDouble(Console.ReadLine());
                ComplexNumber ob2 = new ComplexNumber(real, imaginary);
                Console.WriteLine($"The second complex number: {ob2}");
                Console.WriteLine($"({ob1}) + ({ob2}) = {ob1 + ob2}");
                Console.WriteLine($"({ob1}) - ({ob2}) = {ob1 - ob2}");
                Console.WriteLine($"({ob1}) * ({ob2}) = {ob1 * ob2}");
                Console.WriteLine($"({ob1}) / ({ob2}) = {ob1 / ob2}");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
            }
            #endregion
        }