コード例 #1
0
        public void Task_2()
        {
            Point upLeft, lowRight;

            Console.WriteLine("Please input coordinates of an upper left corner:\n");
            Console.Write("X1: ");
            upLeft.X = double.Parse(Console.ReadLine());
            Console.Write("Y1: ");

            Console.WriteLine("Please input coordinates of an lower right corner:\n");
            upLeft.Y = double.Parse(Console.ReadLine());
            Console.Write("X2: ");
            lowRight.X = double.Parse(Console.ReadLine());
            Console.Write("Y2: ");
            lowRight.Y = double.Parse(Console.ReadLine());

            Rectangle_2 rect2 = new Rectangle_2(upLeft, lowRight);

            Console.WriteLine("Area of a Rectangle is: " + rect2.GetArea);
            Console.WriteLine("Perimeter of a Rectangle is: " + rect2.GetPerimeter);
        }
コード例 #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
        }
コード例 #3
0
        static void Main(string[] args)
        {
            #region Rectangle
            Console.WriteLine("------------------ Task 1 ------------------\n");
            Rectangle rectangle = new Rectangle();

            Console.Write("Please, enter upper left point X coordinate: ");
            rectangle.upperLeftX = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please, enter upper left point Y coordinate: ");
            rectangle.upperLeftY = Convert.ToInt32(Console.ReadLine());

            Console.Write("Please, enter down right point X coordinate: ");
            rectangle.downRightX = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please, enter down right point Y coordinate: ");
            rectangle.downRightY = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Square is: " + rectangle.Square());
            Console.WriteLine("Perimeter is: " + rectangle.Perimeter());
            #endregion
            #region Circle

            Circle circle = new Circle();

            Console.Write("Please, enter the radius of the circle: ");
            circle.radius = Convert.ToDouble(Console.ReadLine());

            circle.CircleLenght();
            circle.CircleSquare();
            #endregion
            #region Complex Number

            Console.Write("Please, enter first real part: ");
            double real1 = Convert.ToDouble(Console.ReadLine());
            Console.Write("Please, enter first imaginary part: ");
            double imaginary1 = Convert.ToDouble(Console.ReadLine());

            Console.Write("Please, enter second real part: ");
            double real2 = Convert.ToDouble(Console.ReadLine());
            Console.Write("Please, enter second imaginary part: ");
            double imaginary2 = Convert.ToDouble(Console.ReadLine());

            ComplexNumber firstComplex  = new ComplexNumber(real1, imaginary1);
            ComplexNumber secondComplex = new ComplexNumber(real2, imaginary2);

            ComplexNumber multiplying = firstComplex * secondComplex;
            Console.WriteLine($"Multipling of complex numbers = {multiplying.Real} + {multiplying.Imiginary}i");

            ComplexNumber dividing = firstComplex / secondComplex;
            Console.WriteLine($"Dividing of complex numbers = {dividing.Real} + {dividing.Imiginary}i");
            #endregion
            #region Draw
            Console.WriteLine("\n------------------ Task 2 ------------------\n");

            Rectangle_2 r = new Rectangle_2();
            r.Draw();

            Square s = new Square();
            s.Draw();
            #endregion
            #region Collections
            Console.WriteLine("\n------------------ Task 3 ------------------\n");
            Console.WriteLine("Display name and age of each created person:\n");

            var people = new List <Person>
            {
                new Person {
                    Name = "Emma", Age = 18, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                },
                new Person {
                    Name = "Olivia", Age = 19, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                },
                new Person {
                    Name = "Ava", Age = 20, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                },
                new Person {
                    Name = "Isabella", Age = 21, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                },
                new Person {
                    Name = "Sophia", Age = 22, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                },
                new Person {
                    Name = "Charlotte", Age = 23, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                },
            };

            foreach (var person in people)
            {
                Console.WriteLine("Name: {0}, Age: {1}", person.Name, person.Age);
            }

            Console.WriteLine("\nPhone numbers of all created persons:\n");
            people.AddRange(new List <Person>
            {
                new Person {
                    Name = "Mia", Age = 24, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                },
                new Person {
                    Name = "Amelia", Age = 25, PhoneNumbers = new List <string>()
                    {
                        "+ Kyivstar", "+ Life", "+ Vodafone"
                    }
                }
            });

            foreach (var person in people)
            {
                Console.WriteLine("Name: {0}", person.Name);

                foreach (var number in person.PhoneNumbers)
                {
                    Console.WriteLine($"{number}");
                }
            }

            Console.WriteLine("\nList of randomly generated elements:\n");
            RandomString random = new RandomString();
            random.ElementsNumber();
            random.DisplayPage();

            #endregion
            Console.ReadKey();
        }