public static void Main(string[] args) { double a, b; a = AskNumber("Введите ширину прямоугольника: "); b = AskNumber("Введите высоту прямоугольника: "); Rect rect = new Rect(a, b); rect.Print(); Console.WriteLine(); a = AskNumber("Введите сторону квадрата: "); Quadr quadr = new Quadr(a); quadr.Print(); Console.WriteLine(); a = AskNumber("Введите радиус круга: "); Circle circle = new Circle(a); circle.Print(); Console.WriteLine(); rect.Print(); quadr.Print(); circle.Print(); Console.WriteLine(); Console.WriteLine("Сортировка ArrayList"); ArrayList al = new ArrayList(); al.Add(rect); al.Add(quadr); al.Add(circle); al.Sort(); foreach (Figure fig in al) { fig.Print(); } Console.WriteLine(); Console.WriteLine("Сортировка List<Figure>"); List <Figure> li = new List <Figure> (); li.Add(rect); li.Add(quadr); li.Add(circle); li.Sort(); foreach (Figure fig in li) { fig.Print(); } }
static void Main(string[] args) { Console.Title = "Алпеев Владислав ИУ5-34Б"; Circle cir = new Circle(5); cir.Print(); Rectangle rect = new Rectangle(3, 6); //экземпляры классов для коллекции rect.Print(); Square sqr = new Square(2); sqr.Print(); Console.WriteLine("\n\tArrayList"); ArrayList Arr = new ArrayList(); //коллекция ArrayList Arr.Add(rect); Arr.Add(sqr); Arr.Add(cir); foreach (GeoFigure obj in Arr) { Console.WriteLine(obj.Area()); } Console.WriteLine("\n\tList"); List <GeoFigure> Lis = new List <GeoFigure>(); //коллекция класса List GeoFigure buf; Lis.Add(rect); Lis.Add(sqr); Lis.Add(cir); for (int i = 0; i < Lis.Count; i++) //сортировка { for (int j = 0; j < (Lis.Count - (i + 1)); j++) { if (Lis[j].CompareTo(Lis[j + 1]) == 1) { buf = Lis[j]; Lis[j] = Lis[j + 1]; Lis[j + 1] = buf; } } } foreach (GeoFigure obj in Lis) { Console.WriteLine(obj.Area()); } Console.WriteLine("\n\tMatrix"); Matrix <GeoFigure> matr = new Matrix <GeoFigure>(3, 3, 3); //пример использования матрицы matr[1, 1, 0] = rect; matr[1, 1, 2] = sqr; matr[2, 2, 1] = cir; Console.WriteLine(matr.ToString()); Console.WriteLine("\n\tSimpleStack"); SimpleStack <GeoFigure> stack = new SimpleStack <GeoFigure>(); stack.Push(rect); stack.Push(sqr); stack.Push(cir); Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Pop()); Console.ReadKey(); }
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()); }
static void Main(string[] args) { Circle circle = new Circle(5); Square square = new Square(5); Rectangle rectangle = new Rectangle(5, 4); circle.Print(); square.Print(); rectangle.Print(); List <Figura> li1 = new List <Figura> { circle, square, rectangle }; Console.WriteLine(); Console.WriteLine("Сортировка коллекции класса List<Figure>"); li1.Sort(); foreach (var x in li1) { Console.WriteLine(x); } ArrayList li2 = new ArrayList(); li2.Add(circle); li2.Add(square); li2.Add(rectangle); li2.Sort(); Console.WriteLine(); Console.WriteLine("Сортировка коллекции класса ArrayList"); foreach (var x in li2) { Console.WriteLine(x); } Console.WriteLine(); Console.WriteLine("\n Разреженная матрица"); Matrix <Figura> matrix = new Matrix <Figura>(3, 3, 3, new FigureMatrixCheckEmpty()); matrix[0, 0, 0] = rectangle; matrix[1, 1, 1] = square; matrix[2, 2, 2] = circle; Console.WriteLine(matrix.ToString()); Console.WriteLine(); Console.WriteLine("\n Стэээк"); SimpleStack <Figura> stack = new SimpleStack <Figura>(); //добавление данных в стек stack.Push(rectangle); stack.Push(square); stack.Push(circle); //чтение данных из стека while (stack.Count > 0) { Figura f = stack.Pop(); Console.WriteLine(f); } Console.ReadLine(); }
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(); }