Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication37
- {
- class Program
- {
- static void Main(string[] args)
- {
- int usrChoise;
- List<Shape> lib = new List<Shape>();
- do
- {
- Console.WriteLine("Создайте три фигуры.");
- Console.WriteLine("1) Квадрат");
- Console.WriteLine("2) Круг");
- Console.WriteLine("3) Треугольник");
- Console.WriteLine("4) Выход \n");
- usrChoise = int.Parse(Console.ReadLine());
- if (usrChoise == 1)
- {
- Console.WriteLine("Введите сторону квадрата, чтобы получить его площадь \n");
- int a = int.Parse(Console.ReadLine());
- Shape sqr = new Square(a);
- lib.Add(sqr);
- }
- else if (usrChoise == 2)
- {
- Console.WriteLine("Введите радиус круга, чтобы получить его площадь \n");
- int a = int.Parse(Console.ReadLine());
- Shape sqr = new Circle(a);
- lib.Add(sqr);
- }
- else if (usrChoise == 3)
- {
- Console.WriteLine("Введите основание и высоту треугольника, чтобы получить его площадь \n");
- Console.WriteLine("Основание: \n");
- int a = int.Parse(Console.ReadLine());
- Console.WriteLine("Высота: \n");
- int h = int.Parse(Console.ReadLine());
- Shape sqr = new Triangle(a, h);
- lib.Add(sqr);
- }
- }
- while (usrChoise != 4);
- Console.WriteLine();
- foreach (Shape i in lib)
- Console.WriteLine(i.GetSquare());
- }
- }
- class Shape
- {
- public virtual double GetSquare()
- {
- return 0;
- }
- }
- class Square : Shape
- {
- public int a;
- public Square(int b)
- {
- a = b;
- }
- public override double GetSquare()
- {
- int result = a * a;
- return result;
- }
- }
- class Circle : Shape
- {
- public int rad;
- public Circle(int r)
- {
- rad = r;
- }
- public override double GetSquare()
- {
- double result = Math.PI * rad * rad;
- return result;
- }
- }
- class Triangle : Shape
- {
- public int a, h;
- public Triangle(int aa, int hh)
- {
- a = aa;
- h = hh;
- }
- public override double GetSquare()
- {
- int result = a * h / 2;
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement