Exemple #1
0
        static void Main(string[] args)
        {
            Console.Title = "Сахарова Елизавета ИУ5-32Б";

            Rectangle rectangle = new Rectangle(6, 4);
            Square    square    = new Square(5);
            Circle    circle    = new Circle(7);

            // ArrayList
            Console.WriteLine("ArrayList");
            ArrayList arrayList = new ArrayList();

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

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

            Console.WriteLine("\nОтсортированный ArrayList");
            arrayList.Sort();

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

            // List<Figure>
            Console.WriteLine("\nList<Figure>");
            List <Figure> figureList = new List <Figure>();

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

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

            Console.WriteLine("\nОтсортированный List<Figure>");
            arrayList.Sort();

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

            // Matrix<Figure>
            Console.WriteLine("\nMatrix<Figure>");
            Matrix <Figure> matrix = new Matrix <Figure>(2, 2, 2, square);

            Console.WriteLine(matrix.ToString());

            // SimpleList<Figure>
            Console.WriteLine("SimpleList<Figure>");
            SimpleList <Figure> list = new SimpleList <Figure>();

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

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

            Console.WriteLine("\nОтсортированный SimpleList<Figure>");
            list.Sort();

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

            // SimpleStack<Figure>
            Console.WriteLine("\nSimpleStack<Figure>");
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

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

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

            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Circle    cir  = new Circle(10);
            Rectangle rec  = new Rectangle(1, 3);
            Square    sc   = new Square(2);
            Circle    cir2 = new Circle(100);

            //*** Test 1: ArrayList ***
            ArrayList al = new ArrayList();

            al.Add(cir);
            al.Add(rec);
            al.Add(sc);
            al.Add(cir2);

            Console.WriteLine("Test 1: ArrayList");
            Console.WriteLine("\nДо сортировки:");
            foreach (Figure f in al)
            {
                Console.WriteLine(f);
            }
            al.Sort();
            Console.WriteLine("\nПосле сортировки:");
            foreach (Figure f in al)
            {
                Console.WriteLine(f);
            }

            //*** Test 2: List<T> ***
            List <Figure> list = new List <Figure>();

            list.Add(sc);
            list.Add(rec);
            list.Add(cir);
            list.Add(cir2);

            Console.WriteLine("\n\nTest 2: List<T>");
            Console.WriteLine("\nДо сортировки:");
            foreach (Figure f in list)
            {
                Console.WriteLine(f);
            }
            list.Sort();
            Console.WriteLine("\nПосле сортировки:");
            foreach (Figure f in list)
            {
                Console.WriteLine(f);
            }

            //*** Test 3: Matrix<T> ***
            Matrix <Figure> matrix = new Matrix <Figure>(3, 3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0, 0] = rec;
            matrix[1, 1, 1] = sc;
            matrix[2, 2, 2] = cir;
            matrix[2, 0, 2] = cir2;
            Console.WriteLine("\n\nTest 3: Matrix<T>\n");
            Console.WriteLine(matrix.ToString());

            //*** Test 4: SimpleList<T> ***
            SimpleList <Figure> simple_list = new SimpleList <Figure>();

            simple_list.Add(cir);
            simple_list.Add(rec);
            simple_list.Add(cir2);
            simple_list.Add(sc);
            Console.WriteLine("Test 4: SimpleList<T>");
            Console.WriteLine("\nДо сортировки:");
            foreach (var x in simple_list)
            {
                Console.WriteLine(x);
            }
            simple_list.Sort();
            Console.WriteLine("\nПосле сортировки:");
            foreach (var x in simple_list)
            {
                Console.WriteLine(x);
            }

            //*** Test 5: SimpleStack<T> ***
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(rec);
            stack.Push(sc);
            stack.Push(cir2);
            stack.Push(cir);
            Console.WriteLine("\nTest 5: SimpleStack<T>\n");
            while (stack.Count > 0)
            {
                Figure f = stack.Pop();
                Console.WriteLine(f);
            }

            Console.ReadKey();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Rectangle rect = new Rectangle(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 (var x in al)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nArrayList - сортировка");

            al.Sort();

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

            Console.WriteLine("\nList<Figure>");

            List <Figure> fl = new List <Figure>();

            fl.Add(circle);

            fl.Add(rect);

            fl.Add(square);

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

            Console.WriteLine("\nList<Figure> - сортировка");

            fl.Sort();

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

            Console.WriteLine("\nМатрица");

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

            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();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.Title = "Назаров Максим Михайлович Группа ИУ5-33Б";
            Rectangle rect = new Rectangle(8, 6);
            Square    sq   = new Square(8);
            Circle    cir  = new Circle(8);

            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("\nArrayList");
            Console.ResetColor();
            ArrayList list = new ArrayList();

            list.Add(rect);
            list.Add(sq);
            list.Add(cir);
            foreach (var i in list)
            {
                Console.WriteLine(i.ToString() + " ");
            }

            List <Geometric_figures> list2 = new List <Geometric_figures>();

            list2.Add(rect);
            list2.Add(cir);
            list2.Add(sq);
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("\nПеред сортировкой:");
            Console.ResetColor();
            foreach (var i in list2)
            {
                Console.Write(i.ToString() + " \n" + " ");
            }
            list2.Sort();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nПосле сортировки:");
            Console.ResetColor();
            foreach (var i in list2)
            {
                Console.Write(i.ToString() + " \n" + " ");
            }

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

            matrix[0, 0, 0] = rect;
            matrix[1, 1, 1] = sq;
            matrix[2, 2, 2] = cir;
            Console.WriteLine(matrix.ToString());

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("\nСтек");
            Console.ResetColor();
            SimpleStack <Geometric_figures> stack = new SimpleStack <Geometric_figures>();

            stack.Push(rect);
            stack.Push(sq);
            stack.Push(cir);
            while (stack.Count > 0)
            {
                Geometric_figures f = stack.Pop();
                Console.WriteLine(f);
            }

            Console.ReadKey();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            do
            {
                double[,] dimensions = new double[3, 2];
                string str; // временная сточная переменная для консольного ввода
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Лабораторная работа 3 - 'Cортировка геометрических фигур'");
                Console.Title = "Выполнил:Ли М.В. Группа:ИУ5-34Б";
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите длину Прямоугольника:");
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите ширину Прямоугольника:");
                double.TryParse(str, out dimensions[0, 0]);
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                double.TryParse(str, out dimensions[0, 1]);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите длину стороны Квадрата:");
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                double.TryParse(str, out dimensions[1, 0]);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите радиус Круга:");
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                double.TryParse(str, out dimensions[2, 0]);
                Circle circle = new Circle(dimensions[2, 0]);
                circle.Print();
                Rectangle rectangle = new Rectangle(dimensions[0, 0], dimensions[0, 1]);
                rectangle.Print();
                Square square = new Square(dimensions[1, 0]);
                square.Print();

                Console.WriteLine("\n\tArrayList");
                ArrayList Arr = new ArrayList();
                Arr.Add(rectangle);
                Arr.Add(square);
                Arr.Add(circle);
                Console.WriteLine("\nИсходный ArrayList:", "DarkMagenta");
                foreach (var x in Arr)
                {
                    Console.WriteLine(x);
                }
                Arr.Sort();
                Console.WriteLine("\n\nОтсоритрованные ArrayList:", "DarkMagenta");
                foreach (var x in Arr)
                {
                    Console.WriteLine(x);
                }
                Console.WriteLine("\n\tList");
                List <GeomFigure> List = new List <GeomFigure>();
                GeomFigure        buf;
                List.Add(rectangle);
                List.Add(square);
                List.Add(circle);
                for (int i = 0; i < List.Count; i++)
                {
                    for (int j = 0; j < (List.Count - (i + 1)); j++)
                    {
                        if (List[j].CompareTo(List[j + 1]) == 1)
                        {
                            buf         = List[j];
                            List[j]     = List[j + 1];
                            List[j + 1] = buf;
                        }
                    }
                }
                Console.WriteLine("\nИсходный List:", "DarkMagenta");
                foreach (var x in List)
                {
                    Console.WriteLine(x);
                }
                List.Sort();
                Console.WriteLine("\nОтсортированный List:", "DarkMagenta");
                foreach (var x in List)
                {
                    Console.WriteLine(x);
                }
                Console.WriteLine("\n\tMatrix");
                Matrix <GeomFigure> matr = new Matrix <GeomFigure>(3, 3, 3);
                matr[1, 1, 0] = rectangle;
                matr[1, 1, 2] = square;
                matr[2, 2, 1] = circle;
                Console.WriteLine(matr.ToString());

                Console.WriteLine("\n\tSimpleStack");
                SimpleStack <GeomFigure> stack = new SimpleStack <GeomFigure>();
                stack.Push(rectangle);
                stack.Push(square);
                stack.Push(circle);
                Console.WriteLine(stack.Pop());
                Console.WriteLine(stack.Pop());
                Console.WriteLine(stack.Pop());
            } while (AskContinue());
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Rectangle rect   = new Rectangle(5, 4);
            Rectangle square = new Rectangle(5);
            Circle    circle = new Circle(5);

            rect.Print();
            square.Print();
            circle.Print();
            Console.ReadLine();
            ArrayList al = new ArrayList();

            //Добавление объектов в коллекцию
            al.Add(333);
            al.Add(123.123);
            al.Add("строка");
            al.Add(11);
            al.Add("q");
            al.Add(1456);
            al.Add(0.5);
            //Сортировка по типу данных
            foreach (object o in al)
            {
                string type = o.GetType().Name;
                if (type == "Int32")
                {
                    Console.WriteLine("Целое число: " + o.ToString());
                }
                else if (type == "String")
                {
                    Console.WriteLine("Строка: " + o.ToString());
                }
                else
                {
                    Console.WriteLine("Другой тип: " + o.ToString());
                }
            }

            Console.ReadLine();

            //Создание коллекции класса List<Figure>
            List <Figure> li = new List <Figure>();

            //Добавление объектов в коллекцию
            li.Add(rect);
            li.Add(square);
            li.Add(circle);
            //Сортировка по площади фигуры
            var orderedNumbers = from i in li
                                 orderby i.Area()
                                 select i;

            foreach (Figure i in orderedNumbers)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("\nМатрица");
            Matrix <Figure> matrix = new Matrix <Figure>(3, 3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0, 0] = rect;
            matrix[1, 1, 1] = square;
            matrix[2, 2, 2] = circle;
            Console.WriteLine(matrix.ToString());
            Console.ReadLine();
            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();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Кучумов Вячеслав Олегович, ИУ5-33Б");
            Rectangle rect   = new Rectangle(2, 3);
            Quadrat   quad   = new Quadrat(5);
            Circle    circle = new Circle(3);

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

            a1.Add(circle);
            a1.Add(rect);
            a1.Add(quad);
            foreach (var x in a1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nArrayList-sort");
            a1.Sort();

            foreach (var x in a1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nList<Figure>");
            List <Figure> f1 = new List <Figure>();

            f1.Add(circle);
            f1.Add(rect);
            f1.Add(quad);

            foreach (var x in f1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nList<Figure>-sort");
            f1.Sort();

            foreach (var x in f1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nMatrix");
            SparseMatrix <Figure> matrix = new SparseMatrix <Figure>(4, 4, 4, null);

            matrix[0, 0, 0] = rect;
            matrix[1, 1, 1] = quad;
            matrix[3, 3, 3] = circle;
            Console.WriteLine(matrix.ToString());

            Console.WriteLine("\nStack");
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(rect);
            stack.Push(quad);
            stack.Push(circle);
            foreach (var x in stack)
            {
                Console.WriteLine(x.ToString());
            }

            Console.WriteLine("\nStack-pop");
            stack.Pop();
            foreach (var x in stack)
            {
                Console.WriteLine(x.ToString());
            }
        }