public Circle(Circle c) : this(c.Center.X, c.Center.Y, c.Radius) { }
 public Round(Circle c) : base(c) { }
Exemple #3
0
        static void Main(string[] args)
        {
            var line = new Line();
            var circle = new Circle();
            var round = new Round();
            var ring = new Ring();
            var rect = new Rect();
            bool li = false, ci = false, ro = false, ri = false, re = false;
            do
            {
                int num;
               
                Console.WriteLine("1. Добавить линию.");
                Console.WriteLine("2. Добавить окружность.");
                Console.WriteLine("3. Добавить круг.");
                Console.WriteLine("4. Добавить кольцо.");
                Console.WriteLine("5. Добавить прямоугольник.");
                Console.WriteLine("6. Вывести на экран все фигуры.");
                num = int.Parse(Console.ReadLine());
                switch (num)
                {
                    case 1:
                        Console.WriteLine("Введите координаты первой точки:");
                        Console.WriteLine("x=");
                        int X1 = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int Y1 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Введите координаты второй точки:");
                        Console.WriteLine("x=");
                        int X2 = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int Y2 = int.Parse(Console.ReadLine());

                        line.get(X1, Y1, X2, Y2);
                        li = true;
                        break;

                    case 2:
                        Console.WriteLine("Введите координаты центра и радиус:");
                        Console.WriteLine("x=");
                        int X = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int Y = int.Parse(Console.ReadLine());
                        Console.WriteLine("r=");
                        int R = int.Parse(Console.ReadLine());
                        circle.get(X, Y, R);
                        ci = true;
                        break;

                    case 3:
                        Console.WriteLine("Введите координаты центра и радиус:");
                        Console.WriteLine("x=");
                        int Xro = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int Yro = int.Parse(Console.ReadLine());
                        Console.WriteLine("r=");
                        int Rro = int.Parse(Console.ReadLine());
                        round.get(Xro, Yro, Rro);
                        ro = true;
                        break;

                    case 4:
                        Console.WriteLine("Введите координаты центра:");
                        Console.WriteLine("x=");
                        int Xri = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int Yri = int.Parse(Console.ReadLine());
                        Console.WriteLine("Введите внеший радиус R=");
                        int Rri = int.Parse(Console.ReadLine());
                        Console.WriteLine("Введите внутренный радиус r=");
                        int rri = int.Parse(Console.ReadLine());
                        ri = true;
                        ring.get(Xri, Yri, Rri, rri);
                        break;

                    case 5:
                        Console.WriteLine("Введите координаты первой точки:");
                        Console.WriteLine("x=");
                        int x1 = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int y1 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Введите координаты второй точки:");
                        Console.WriteLine("x=");
                        int x2 = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int y2 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Введите координаты третьей точки:");
                        Console.WriteLine("x=");
                        int x3 = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int y3 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Введите координаты четвертой точки:");
                        Console.WriteLine("x=");
                        int x4 = int.Parse(Console.ReadLine());
                        Console.WriteLine("y=");
                        int y4 = int.Parse(Console.ReadLine());

                        rect.get(x1, y2, x2, y2, x3, y3, x4, y4);
                        re = true;
                        break;

                    case 6:
                        if (li) line.Show();                        
                        if (ci) circle.Show();
                        if (ro) round.Show();
                        if (ri) ring.Show();
                        if (re) rect.Show();
                        break;

                }
            } while (true);
        }
 //сеттер
 public void set(Circle inner, Circle outer)
 {
     Inner.set(inner.getCenter(), inner.Radius);
     Outer.set(outer.getCenter(), outer.Radius);
 }
 public Ring(int x, int y, int ir, int or)
 {
     Inner = new Circle(x, y, ir);
     Outer = new Circle(x, y, or);
 }
 //конструкторы
 public Ring(Circle inner, Circle outer)
 {
     Inner = new Circle(inner);
     Outer = new Circle(outer);
 }
        static void Main(string[] args)
        {
            int n;
            int x, y, r1, r2;
            Point p1, p2;

            //выбор фигуры
            Console.WriteLine("Выберите фигуру, которую вы хотите создать: ");
            Console.WriteLine("1 | Линия");
            Console.WriteLine("2 | Окружность");
            Console.WriteLine("3 | Прямоугольник");
            Console.WriteLine("4 | Круг");
            Console.WriteLine("5 | Кольцо");
            while (!int.TryParse(Console.ReadLine(), out n) || n > 5)
                Console.Write("Неверный ввод. Введите целое число от 1 до 5: ");
            switch(n)
            {
                case 1:
                    //ввод линии
                    Line l;
                    Console.WriteLine("\n\nВы выбрали линию. Введите 2 точки:");

                    Console.Write("  Введите координату x первой точки: ");
                    while (!int.TryParse(Console.ReadLine(), out x))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    Console.Write("  Введите координату y первой точки: ");
                    while (!int.TryParse(Console.ReadLine(), out y))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    p1 = new Point(x, y);

                    Console.Write("  Введите координату х второй точки: ");
                    while (!int.TryParse(Console.ReadLine(), out x))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    Console.Write("  Введите координату у второй точки: ");
                    while (!int.TryParse(Console.ReadLine(), out y))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    p2 = new Point(x, y);

                    l = new Line(p1, p2);
                    Console.WriteLine("\nВаша линия: {0}\n", l);
                    Console.ReadKey();
                    break;
                case 2:
                    //ввод окружности
                    Circle c;
                    Console.WriteLine("\n\nВы выбрали окружность. Введите центр и радиус:");

                    Console.Write("  Введите координату x центра: ");
                    while (!int.TryParse(Console.ReadLine(), out x))
                        Console.Write("  Неверный ввод. Введите целой число: ");
                    Console.Write("  Введите координату y центра: ");
                    while (!int.TryParse(Console.ReadLine(), out y))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    p1 = new Point(x, y);
                    Console.Write("  Введите радиус: ");
                    while (!int.TryParse(Console.ReadLine(), out r1) || r1 < 0)
                        Console.Write("  Неверный ввод. Введите натуральное число: ");

                    c = new Circle(p1, r1);
                    Console.WriteLine("Ваша окружность: {0}",c);
                    Console.ReadKey();
                    break;
                case 3:
                    //ввод прямоугольника
                    Rectangle r;
                    Console.WriteLine("\n\nВы выбрали прямоугольник. Введите 2 точки:");

                    Console.Write("  Введите координату x первой точки: ");
                    while (!int.TryParse(Console.ReadLine(), out x))
                        Console.Write("  Неверный ввод. Введите целой число: ");
                    Console.Write("  Введите координату y первой точки: ");
                    while (!int.TryParse(Console.ReadLine(), out y))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    p1 = new Point(x, y);

                    Console.Write("  Введите координату х второй точки: ");
                    while (!int.TryParse(Console.ReadLine(), out x))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    Console.Write("  Введите координату у второй точки: ");
                    while (!int.TryParse(Console.ReadLine(), out y))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    p2 = new Point(x, y);

                    r = new Rectangle(p1, p2);
                    Console.WriteLine("\nВаш прямоугольник: {0}\n", r);
                    Console.ReadKey();
                    break;
                case 4:
                    //ввод круга
                    Round round;
                    Console.WriteLine("\n\nВы выбрали круг. Введите центр и радиус:");

                    Console.Write("  Введите координату x центра: ");
                    while (!int.TryParse(Console.ReadLine(), out x))
                        Console.Write("  Неверный ввод. Введите целой число: ");
                    Console.Write("  Введите координату y центра: ");
                    while (!int.TryParse(Console.ReadLine(), out y))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    p1 = new Point(x, y);
                    Console.Write("  Введите радиус: ");
                    while (!int.TryParse(Console.ReadLine(), out r1) || r1 < 0)
                        Console.Write("  Неверный ввод. Введите натуральное число: ");

                    round = new Round(p1, r1);
                    Console.WriteLine("Ваш круг: {0}", round);
                    Console.ReadKey();
                    break;
                case 5:
                    //ввод кольца
                    Ring ring;
                    Console.WriteLine("\n\nВы выбрали кольцо. Введите центр и диаметры: ");

                    Console.Write("  Введите координату x центра: ");
                    while (!int.TryParse(Console.ReadLine(), out x))
                        Console.Write("  Неверный ввод. Введите целой число: ");
                    Console.Write("  Введите координату y центра: ");
                    while (!int.TryParse(Console.ReadLine(), out y))
                        Console.Write("  Неверный ввод. Введите целое число: ");
                    Console.Write("  Введите внутренний радиус: ");
                    while (!int.TryParse(Console.ReadLine(), out r1) || r1 < 0)
                        Console.Write("  Неверный ввод. Введите натуральное число: ");
                    Console.Write("  Введите внутренний радиус: ");
                    while (!int.TryParse(Console.ReadLine(), out r2) || r2 <= r1)
                        Console.Write("  Неверный ввод. Введите натуральное число больше {0}: ", r1);

                    ring = new Ring(x, y, r1, r2);
                    Console.WriteLine("Ваше кольцо: {0}", ring);
                    Console.ReadKey();
                    break;
            }
        }
Exemple #8
0
 static void Main(string[] args)
 {
     int i = 0;
     
     do
     {
         Console.WriteLine("---------------------------------------------------");
         Console.WriteLine("Выберите действие:");
         Console.WriteLine("1 | Создать линию.");
         Console.WriteLine("2 | Создать прямоугольник.");
         Console.WriteLine("3 | Создать окружность.");
         Console.WriteLine("4 | Создать круг.");
         Console.WriteLine("5 | Создать кольцо.");
         Console.WriteLine("---------------------------------------------------");
         Console.WriteLine("0 | Выход.");
         Console.WriteLine("---------------------------------------------------");
         int switchOne;
         switchOne = Convert.ToInt32(Console.ReadLine());
         switch (switchOne)
         {
             case 0:
                 i++;
                 break;
             case 1:
                 double x, y;
                 Console.WriteLine("Введите координаты точки A:");
                 Console.Write("x=");
                 x = Convert.ToInt32(Console.ReadLine());
                 Console.Write("y=");
                 y = Convert.ToInt32(Console.ReadLine());
                 Point a = new Point(x, y);
                 Console.WriteLine("Введите координаты точки B:");
                 Console.Write("x=");
                 x = Convert.ToInt32(Console.ReadLine());
                 Console.Write("y=");
                 y = Convert.ToInt32(Console.ReadLine());
                 Point b = new Point(x, y);
                 Line L = new Line(a, b);
                 L.Draw();
                 break;
             case 2:
                 Console.WriteLine("Введите координаты верхней левой точки A:");
                 Console.Write("x=");
                 x = Convert.ToInt32(Console.ReadLine());
                 Console.Write("y=");
                 y = Convert.ToInt32(Console.ReadLine());
                 a = new Point(x, y);
                 Console.WriteLine("Введите координаты нижней правой точки C:");
                 Console.Write("x=");
                 x = Convert.ToInt32(Console.ReadLine());
                 Console.Write("y=");
                 y = Convert.ToInt32(Console.ReadLine());
                 b = new Point(x, y);
                 Rectangle R = new Rectangle(a, b);
                 R.Draw();
                 break;
             case 3:
                 Console.WriteLine("Введите координаты центра:");
                 Console.Write("x=");
                 x = Convert.ToInt32(Console.ReadLine());
                 Console.Write("y=");
                 y = Convert.ToInt32(Console.ReadLine());
                 Point o = new Point(x, y);
                 Console.WriteLine("Введите радиус:");
                 Console.Write("r=");
                 double r = Convert.ToDouble(Console.ReadLine());
                 Circle C = new Circle(o, r);
                 C.Draw();
                 break;
             case 4:
                 Console.WriteLine("Введите координаты центра:");
                 Console.Write("x=");
                 x = Convert.ToInt32(Console.ReadLine());
                 Console.Write("y=");
                 y = Convert.ToInt32(Console.ReadLine());
                 o = new Point(x, y);
                 Console.WriteLine("Введите радиус:");
                 Console.Write("r=");
                 r = Convert.ToDouble(Console.ReadLine());
                 Round R1 = new Round(o, r);
                 R1.Draw();
                 break;
             case 5:
                 Console.WriteLine("Введите координаты центра:");
                 Console.Write("x=");
                 x = Convert.ToInt32(Console.ReadLine());
                 Console.Write("y=");
                 y = Convert.ToInt32(Console.ReadLine());
                 o = new Point(x, y);
                 Console.WriteLine("Введите внешний радиус кольца:");
                 Console.Write("r=");
                 double r1 = Convert.ToDouble(Console.ReadLine());
                 Console.WriteLine("Введите внутренний радиус кольца:");
                 Console.Write("r=");
                 double r2 = Convert.ToDouble(Console.ReadLine());
                 Ring R2 = new Ring(o, r1, r2);
                 R2.Draw();
                 break;
             default:
                 Console.WriteLine("Ошибка: неверное действие.");
                 break;
         }
     } while (i == 0);
 }