Ejemplo n.º 1
0
Archivo: Main.cs Proyecto: vorolga/Lab
        public static void Main()
        {
            Console.WriteLine("Фигуры:\n");
            Rectangle r = new Rectangle(5, 6);
            Square    s = new Square(5);
            Circle    c = new Circle(7);

            r.Print();
            s.Print();
            c.Print();

            Console.WriteLine("\nКоллекция ArrayList до сортировки:\n");
            ArrayList arrayListFigures = new ArrayList();

            arrayListFigures.Add(r);
            arrayListFigures.Add(s);
            arrayListFigures.Add(c);

            foreach (GeomFigure i in arrayListFigures)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("\nКоллекция ArrayList после сортировки:\n");
            arrayListFigures.Sort();

            foreach (GeomFigure i in arrayListFigures)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("\nКоллекция List<GeomFigure> до сортировки:\n");
            List <GeomFigure> listFigure = new List <GeomFigure>();

            listFigure.Add(r);
            listFigure.Add(s);
            listFigure.Add(c);

            foreach (GeomFigure i in listFigure)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("\nКоллекция List<GeomFigure> после сортировки:\n");
            listFigure.Sort();

            foreach (GeomFigure i in listFigure)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("\nМатрица\n");
            Matrix <GeomFigure> matrix = new Matrix <GeomFigure>(3, 3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0, 0] = r;
            matrix[1, 1, 1] = s;
            matrix[2, 2, 2] = c;
            Console.WriteLine(matrix.ToString());

            Console.WriteLine("\nПример работы класса  SimpleStack:\n");
            Console.WriteLine("Фигуры добавлены в SimpleStack с помощью метода Push() и выведены с помощью метода Pop()\n");
            SimpleStack <GeomFigure> simpleStackFigures = new SimpleStack <GeomFigure>();

            simpleStackFigures.Push(r);
            simpleStackFigures.Push(s);
            simpleStackFigures.Push(c);

            while (simpleStackFigures.Count != 0)
            {
                Console.WriteLine(simpleStackFigures.Pop());
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Создание объектов классов фигур
            Rectangle rectangle = new Rectangle(3, 4);
            Square    square    = new Square(5);
            Circle    circle    = new Circle(2.7282);


            ArrayList array = new ArrayList
            {
                rectangle,
                square,
                circle
            };

            Console.WriteLine("Array list перед сортировкой");
            foreach (var elem in array)
            {
                Console.WriteLine(elem);
            }


            array.Sort();

            Console.WriteLine("\nArray list после сортировки");
            foreach (var elem in array)
            {
                Console.WriteLine(elem);
            }


            List <GeometricFigure> list = new List <GeometricFigure>
            {
                rectangle,
                square,
                circle
            };

            Console.WriteLine("\n\nList перед сортировкой");
            foreach (var elem in array)
            {
                Console.WriteLine(elem);
            }

            list.Sort();

            Console.WriteLine("\nList после сортировки");
            foreach (var elem in array)
            {
                Console.WriteLine(elem);
            }

            Console.WriteLine("\n\nМатрица");
            Matrix <GeometricFigure> matrix = new Matrix <GeometricFigure>(3, 3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0, 0] = rectangle;
            matrix[1, 1, 1] = square;
            matrix[2, 2, 2] = circle;
            Console.WriteLine(matrix.ToString());

            try
            {
                GeometricFigure tmp = matrix[66, 1777, 11];
            }
            catch (ArgumentOutOfRangeException err)
            {
                Console.WriteLine(err.Message);
            }


            Console.WriteLine("\n\nСтек");

            SimpleStack <GeometricFigure> stack = new SimpleStack <GeometricFigure>();

            stack.Push(rectangle);
            stack.Push(square);
            stack.Push(circle);

            while (stack.Count > 0)
            {
                GeometricFigure f = stack.Pop();
                Console.WriteLine(f);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Rectangle rectangle = new Rectangle(2, 5);
            Square    square    = new Square(4);
            Circle    circle    = new Circle(4);

            System.Console.WriteLine("\nArrayList");
            ArrayList arrayList = new ArrayList();

            arrayList.Add(circle);
            arrayList.Add(rectangle);
            arrayList.Add(square);
            foreach (GeomFigure o in arrayList)
            {
                Console.WriteLine(o.ToString());
            }

            System.Console.WriteLine("\nСорт.ArrayList");
            arrayList.Sort();
            foreach (GeomFigure o in arrayList)
            {
                Console.WriteLine(o.ToString());
            }

            System.Console.WriteLine("\nЛист");
            List <GeomFigure> FiguresList = new List <GeomFigure>();

            FiguresList.Add(circle);
            FiguresList.Add(rectangle);
            FiguresList.Add(square);
            foreach (GeomFigure o in FiguresList)
            {
                Console.WriteLine(o.ToString());
            }

            System.Console.WriteLine("\nСорт.Лист");
            FiguresList.Sort();
            foreach (GeomFigure o in FiguresList)
            {
                Console.WriteLine(o.ToString());
            }

            System.Console.WriteLine("\nМатрица");
            Matrix <GeomFigure> matrix = new Matrix <GeomFigure>(3, 3, 3, new GeomFigureMatrixCheckEmpty());

            matrix[0, 0, 0] = rectangle;
            matrix[1, 1, 1] = square;
            matrix[2, 2, 2] = circle;
            System.Console.WriteLine(matrix.ToString());

            System.Console.WriteLine("\nSimpleList");
            SimpleList <GeomFigure> simpleList = new SimpleList <GeomFigure>();

            simpleList.Add(circle);
            simpleList.Add(rectangle);
            simpleList.Add(square);

            foreach (var x in simpleList)
            {
                System.Console.WriteLine(x);
            }

            System.Console.WriteLine("\nСорт.SimpleList");
            simpleList.Sort();
            foreach (var x in simpleList)
            {
                System.Console.WriteLine(x);
            }

            System.Console.WriteLine("\nSimpleStack");
            SimpleStack <GeomFigure> simplestack = new SimpleStack <GeomFigure>();

            simplestack.push(circle);
            simplestack.push(rectangle);
            simplestack.push(square);

            foreach (var x in simplestack)
            {
                System.Console.WriteLine(x);
            }

            System.Console.WriteLine("\nSimpleStack popping out");

            while (simplestack.Count > 0)
            {
                GeomFigure f = simplestack.pop();
                Console.WriteLine(f);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Menu       menu      = new Menu();
            Circles    circle    = new Circles(4);
            Rectangles rectangle = new Rectangles(7, 9);
            Squares    square    = new Squares(5);

            while (true)
            {
                switch (menu.menu())
                {
                case 1:
                {
                    List <Figur> list = new List <Figur>();
                    list.Add(circle);
                    list.Add(rectangle);
                    list.Add(square);

                    foreach (var x in list)
                    {
                        Console.WriteLine(x);
                    }
                    Console.WriteLine();

                    Console.WriteLine("Cортировка");
                    list.Sort();
                    foreach (var x in list)
                    {
                        Console.WriteLine(x);
                    }
                    break;
                }

                case 2:
                {
                    ArrayList array = new ArrayList();
                    array.Add(circle);
                    array.Add(rectangle);
                    array.Add(square);

                    foreach (var x in array)
                    {
                        Console.WriteLine(x);
                    }
                    Console.WriteLine();

                    Console.WriteLine("Сортировка");
                    array.Sort();
                    foreach (var x in array)
                    {
                        Console.WriteLine(x);
                    }
                    Console.WriteLine();
                    break;
                }

                case 3:
                {
                    SimpleStack <Figur> stack = new SimpleStack <Figur>();
                    stack.Push(rectangle);
                    stack.Push(square);
                    stack.Push(circle);

                    while (stack.Count > 0)
                    {
                        Figur f = stack.Pop();
                        Console.WriteLine(f);
                    }
                    Console.WriteLine();
                    break;
                }

                case 4:
                {
                    Matrix3d <Figur> cube = new Matrix3d <Figur>(3, 3, 3, null);
                    cube[0, 0, 0] = rectangle;
                    cube[1, 1, 1] = square;
                    cube[2, 2, 2] = circle;
                    Console.WriteLine(cube.ToString());
                    Console.WriteLine();
                    break;
                }

                case 5:
                {
                    return;
                }
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Rect   rect   = new Rect(5, 4);
            Square square = new Square(5);
            Circle circle = new Circle(5);

            Console.WriteLine("\nArrayList");
            ArrayList al = new ArrayList();

            al.Add(circle);
            al.Add(rect);
            al.Add(square);

            foreach (object x in al)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nArrayList - сортировка");
            al.Sort();
            foreach (object x in al)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nList<GeometricFigure>");
            List <Figure> fl = new List <Figure>();

            fl.Add(circle);
            fl.Add(rect);
            fl.Add(square);

            foreach (Figure x in fl)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nList<GeometricFigure> - сортировка");
            fl.Sort();
            foreach (Figure x in fl)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nМатрица");
            Matrix <Figure> cube = new Matrix <Figure>(3, 3, 3, null);

            cube[0, 0, 0] = rect;
            cube[1, 1, 1] = square;
            cube[2, 2, 2] = circle;
            Console.WriteLine(cube.ToString());

            Console.WriteLine("\nСписок");
            SimpleList <Figure> list = new SimpleList <Figure>();

            list.Add(square);
            list.Add(rect);
            list.Add(circle);

            foreach (var x in list)
            {
                Console.WriteLine(x);
            }

            list.Sort();
            Console.WriteLine("\nСортировка списка");
            foreach (var x in list)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nСтек");
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(rect);
            stack.Push(square);
            stack.Push(circle);

            while (stack.Count > 0)
            {
                Figure f = stack.Pop();
                Console.WriteLine(f);
            }
            Console.ReadLine();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Square    Example = new Square(20);
            Circle    one     = new Circle(10);
            Rectangle two     = new Rectangle(30, 5);
            Square    three   = new Square(20);

            //ARRlist


            //
            Console.WriteLine("\n ARRLIST \n");

            ArrayList figlist = new ArrayList()
            {
                Example, one, two, three
            };

            figlist.Sort();

            foreach (GeomFig temp in figlist)
            {
                Console.WriteLine(temp.ToString());
            }

            //
            Console.WriteLine("\n LIST \n");

            List <GeomFig> listof = new List <GeomFig>()
            {
                Example, one, two, three
            };

            listof.Sort();

            foreach (GeomFig temp in listof)
            {
                Console.WriteLine(temp.ToString());
            }
            //
            Console.WriteLine("\n Односвязный список \n");


            SimpleStack <GeomFig> SSS = new SimpleStack <GeomFig>(5);

            SSS.Push(Example);
            SSS.Push(one);
            SSS.Push(two);
            SSS.Push(three);
            SSS.Pop();
            Console.WriteLine("\n Односвязный список \n");
            SSS.PRINT();


            //Разреженная матрица
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nРазреженная матрица");
            Console.ResetColor();
            Matrix <GeomFig> matrix = new Matrix <GeomFig>(4, 4, 3, new FigureMatrixCheckEmpty());

            matrix[1, 1, 0] = one;
            matrix[1, 2, 1] = two;
            matrix[3, 3, 2] = three;
            Console.WriteLine(matrix.ToString());
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            double rh, rw, ss, cr;

            Console.WriteLine("Введите высоту прямоугольника : ");
            rh = Double.Parse(Console.ReadLine());
            Console.WriteLine("Введите ширину прямоугольника : ");
            rw = Double.Parse(Console.ReadLine());
            Rectangle rect = new Rectangle(rh, rw);

            rect.Print();

            Console.WriteLine("Введите сторону квадрата : ");
            ss = Double.Parse(Console.ReadLine());
            Square sq = new Square(ss);

            sq.Print();

            Console.WriteLine("Введите радиус окружности : ");
            cr = Double.Parse(Console.ReadLine());
            Circle cir = new Circle(cr);

            cir.Print();

            //Работа с необобщенным списком
            Console.WriteLine("\nНеобобщенный список:");
            ArrayList al = new ArrayList();

            al.Add(rect);
            al.Add(sq);
            al.Add(cir);

            Console.WriteLine("\nПеред сортировкой");
            foreach (object o in al)
            {
                Console.WriteLine(o);
            }
            Console.WriteLine("\nПосле сортировки");
            al.Sort();
            foreach (object o in al)
            {
                Console.WriteLine(o);
            }

            Console.WriteLine("\nОбобщённый список:");
            List <Figure> L = new List <Figure>();

            L.Add(rect);
            L.Add(sq);
            L.Add(cir);

            Console.WriteLine("\nПеред сортировкой");
            foreach (object o in L)
            {
                Console.WriteLine(o);
            }
            Console.WriteLine("\nПосле сортировки");
            L.Sort();
            foreach (object o in L)
            {
                Console.WriteLine(o);
            }

            Matrix <Figure> SparseMatrix = new Matrix <Figure>(3, 3, 3, new FigureMatrixCheckEmpty());

            SparseMatrix[0, 0, 0] = rect;
            SparseMatrix[1, 1, 1] = sq;
            SparseMatrix[2, 2, 2] = cir;

            String b = SparseMatrix.ToString();

            Console.WriteLine(b);
            Console.WriteLine("\nСтек");

            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            //добавление данных в стек
            stack.Push(rect);
            stack.Push(sq);
            stack.Push(cir);
            //чтение данных из стека
            while (stack.Count > 0)
            {
                Figure f = stack.Pop();
                Console.WriteLine(f);
            }



            Console.ReadLine();
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Введите параметры прямоугольника");
            double    width  = InputValue("Введите ширину прямоугольника:");
            double    height = InputValue("Введите высоту прямоугольника:");
            Rectangle rect   = new Rectangle(width, height);

            rect.Print();
            Console.WriteLine("Введите параметры квадрата");
            double length = InputValue("Введите сторону квадрата:");
            Square sq     = new Square(length);

            sq.Print();
            Console.WriteLine("Введите параметры окружности");
            double radius = InputValue("Введите радиус круга:");
            Circle circ   = new Circle(radius);

            circ.Print();
            Console.WriteLine("Работаем с ArrayList");
            ArrayList figureArray = new ArrayList();

            figureArray.Add(rect);
            figureArray.Add(sq);
            figureArray.Add(circ);
            Console.WriteLine("Неотсортированный список:");
            foreach (var figure in figureArray)
            {
                Console.WriteLine(figure);
            }
            figureArray.Sort();
            Console.WriteLine("Отсортированный список:");
            foreach (var figure in figureArray)
            {
                Console.WriteLine(figure);
            }
            Console.WriteLine("Работаем с List");
            List <GeometricFigure> figureList = new List <GeometricFigure>();

            figureList.Add(rect);
            figureList.Add(sq);
            figureList.Add(circ);
            Console.WriteLine("Неотсортированный список:");
            foreach (var figure in figureList)
            {
                Console.WriteLine(figure);
            }
            figureList.Sort();
            Console.WriteLine("Отсортированный список:");
            foreach (var figure in figureList)
            {
                Console.WriteLine(figure);
            }

            Console.WriteLine("\nМатрица");
            Console.WriteLine("Введите рамер матрицы");
            int a = (int)InputValue("Введите размер i:");
            int b = (int)InputValue("Введите размер j:");
            int c = (int)InputValue("Введите размер k:");
            Matrix <GeometricFigure> matrix = new Matrix <GeometricFigure>(a, b, c, new FigureMatrixCheckEmpty());

            Console.WriteLine("Заполнение матрицы\n");
            matrix[0, 0, 0] = new Rectangle(10, 5);
            matrix[0, 0, 1] = new Circle(10);
            matrix[0, 1, 0] = new Square(5);
            matrix[0, 1, 1] = new Rectangle(1, 10);
            matrix[1, 0, 0] = new Circle(5);
            matrix[1, 0, 1] = new Square(10);
            matrix[1, 1, 0] = new Circle(100);
            matrix[1, 1, 1] = new Circle(50);
            Console.WriteLine("Матрица:\n");
            Console.WriteLine(matrix.ToString());

            SimpleStack <GeometricFigure> stack = new SimpleStack <GeometricFigure>();

            Console.WriteLine("Добавим прямоугольник в стек");
            double    width1  = InputValue("Введите ширину прямоугольника:");
            double    height1 = InputValue("Введите высоту прямоугольника");
            Rectangle rect1   = new Rectangle(width, height);

            stack.Push(rect1);
            Console.WriteLine("\n");
            Console.WriteLine("Добавим квадрат в стек");
            double length1 = InputValue("Введите сторону квадрата:");
            Square square1 = new Square(length);

            stack.Push(square1);
            Console.WriteLine("\n");
            Console.WriteLine("Добавим круг в стек\n");
            double radius1 = InputValue("Введите радиус круга:");
            Circle circle1 = new Circle(radius);

            Console.WriteLine("\n");
            stack.Push(circle1);
            Console.WriteLine("Последний элемент в стеке:");
            Console.WriteLine(stack);
            Console.WriteLine("Удалим последний элемент в стеке:");
            stack.Pop();
            Console.WriteLine("Последний элемент в стеке:");
            Console.WriteLine(stack);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            #region Объекты классов Rectangle, Square и Circle
            Rectangle rect   = new Rectangle(12, 22);
            Square    square = new Square(24);
            Circle    circle = new Circle(11);
            #endregion

            #region Коллекция класса ArrayList
            Console.WriteLine("Отсортированный необобщенный список");

            ArrayList shapesArrList = new ArrayList();
            shapesArrList.Add(rect);
            shapesArrList.Add(square);
            shapesArrList.Add(circle);

            shapesArrList.Sort();

            foreach (var shape in shapesArrList)
            {
                Console.WriteLine(shape);
            }
            #endregion

            #region Коллекция класса List<Shape>
            Console.WriteLine("\nОтсортированный обобщенный список");

            List <Shape> shapeList = new List <Shape>();
            shapeList.Add(rect);
            shapeList.Add(square);
            shapeList.Add(circle);

            shapeList.Sort();

            foreach (var shape in shapeList)
            {
                Console.WriteLine(shape);
            }
            #endregion

            #region Пример работы разрежённой матрицы Matrix3D<Shape>
            Console.WriteLine("\nМатрица");

            Matrix3D <Shape> matrix = new Matrix3D <Shape>(3, 3, 3, new ShapeMatrixCheckEmpty());
            matrix[0, 0, 0] = rect;
            matrix[1, 1, 1] = square;
            matrix[2, 2, 2] = circle;

            Console.WriteLine(matrix);
            #endregion

            #region Пример работы класса SimpleStack
            Console.WriteLine("Стек");

            SimpleStack <Shape> stack = new SimpleStack <Shape>();
            stack.Push(rect);
            stack.Push(square);
            stack.Push(circle);

            while (stack.Count > 0)
            {
                Shape shape = stack.Pop();
                Console.WriteLine(shape);
            }
            #endregion

            Console.ReadKey();
        }