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); }
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(); }