Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace FirstTask
- {
- class Triangle // Класс "Треугольник".
- {
- private double side; // Поле "Сторона треугольника".
- public Triangle() // Коннструктор по-умолчанию.
- {
- side = 0;
- }
- public Triangle(double side) // Конструктор с задачей стороны.
- {
- this.side = side;
- }
- public double Side // Свойства класса.
- {
- get
- {
- return side;
- }
- set
- {
- side = value;
- }
- }
- public virtual double GetSquare() // Вычисление площади треугольника.
- {
- return Math.Round((((side * side) * Math.Sqrt(3)) / 4), 3);
- }
- public virtual void Show() // Получить информацию о фигуре.
- {
- Console.WriteLine();
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("Название фигуры: Треугольник");
- Console.WriteLine($"Длина стороны: {Side}");
- Console.WriteLine($"Количество вершин: {3}");
- Console.WriteLine($"Количество рёбер: {3}");
- Console.WriteLine($"Количество граней: {1}");
- Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine();
- }
- }
- class Tetrahedron : Triangle // Класс тетраэдра.
- {
- private int topNum = 4; // Количество вершин.
- public int TopNum => topNum;
- private int edgNum = 6; // Количество рёбер.
- public int EdgNum => edgNum;
- private int faceNum = 4; //Количество граней.
- public int FaceNum => faceNum;
- public Tetrahedron() // Конструктор по-умолчанию.
- {
- Side = 0;
- }
- public Tetrahedron(double side) // Конструктор с задачей стороны.
- {
- Side = side;
- }
- public override double GetSquare() //Переопределение площади.
- {
- return faceNum * base.GetSquare();
- }
- public override void Show() // Получить информацию о фигуре.
- {
- Console.WriteLine();
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("Название фигуры: Тэтраэдр");
- Console.WriteLine($"Длина стороны: {Side}");
- Console.WriteLine($"Количество вершин: {topNum}");
- Console.WriteLine($"Количество рёбер: {edgNum}");
- Console.WriteLine($"Количество граней: {faceNum}");
- Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine();
- }
- }
- class Octahedron : Triangle // Класс октаэдра.
- {
- private int topNum = 6; // Количество вершин.
- public int TopNum => topNum;
- private int edgNum = 12; // Количество рёбер.
- public int EdgNum => edgNum;
- private int faceNum = 8; //Количество граней.
- public int FaceNum => faceNum;
- public Octahedron() // Конструктор по-умолчанию.
- {
- Side = 0;
- }
- public Octahedron(double side) // Конструктор с задачей стороны.
- {
- Side = side;
- }
- public override double GetSquare() //Переопределение площади.
- {
- return faceNum * base.GetSquare();
- }
- public override void Show() // Получить информацию о фигуре.
- {
- Console.WriteLine();
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("Название фигуры: Октаэдр");
- Console.WriteLine($"Длина стороны: {Side}");
- Console.WriteLine($"Количество вершин: {topNum}");
- Console.WriteLine($"Количество рёбер: {edgNum}");
- Console.WriteLine($"Количество граней: {faceNum}");
- Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine();
- }
- }
- class Icosuhedron : Triangle // Класс икосаэдра.
- {
- private int topNum = 12; // Количество вершин.
- public int TopNum => topNum;
- private int edgNum = 30; // Количество рёбер.
- public int EdgNum => edgNum;
- private int faceNum = 20; //Количество граней.
- public int FaceNum => faceNum;
- public Icosuhedron() // Конструктор по-умолчанию.
- {
- Side = 0;
- }
- public Icosuhedron(double side) // Конструктор с задачей стороны.
- {
- Side = side;
- }
- public override double GetSquare() //Переопределение площади.
- {
- return faceNum * base.GetSquare();
- }
- public override void Show() // Получить информацию о фигуре.
- {
- Console.WriteLine();
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("Название фигуры: Икосаэдр");
- Console.WriteLine($"Длина стороны: {Side}");
- Console.WriteLine($"Количество вершин: {topNum}");
- Console.WriteLine($"Количество рёбер: {edgNum}");
- Console.WriteLine($"Количество граней: {faceNum}");
- Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Triangle[] array = new Triangle[10];
- Console.Write("Сколько фигур будем считать? ");
- int n = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- Console.Write("Какую фигуру будем считать сейчас? (Т/О/И) ");
- char fig = Convert.ToChar(Console.ReadLine());
- Console.Write("Введите длину стороны: ");
- int side = Convert.ToInt32(Console.ReadLine());
- switch (fig)
- {
- case 'Т':
- array[i] = new Tetrahedron(side);
- break;
- case 'О':
- array[i] = new Octahedron(side);
- break;
- case 'И':
- array[i] = new Icosuhedron(side);
- break;
- }
- array[i].Show();
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment