Advertisement
Gillito

Untitled

Jun 9th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication37
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int usrChoise;
  14.             List<Shape> lib = new List<Shape>();
  15.  
  16.             do
  17.             {
  18.                 Console.WriteLine("Создайте три фигуры.");
  19.                 Console.WriteLine("1) Квадрат");
  20.                 Console.WriteLine("2) Круг");
  21.                 Console.WriteLine("3) Треугольник");
  22.                 Console.WriteLine("4) Выход \n");
  23.                 usrChoise = int.Parse(Console.ReadLine());
  24.  
  25.                 if (usrChoise == 1)
  26.                 {
  27.                     Console.WriteLine("Введите сторону квадрата, чтобы получить его площадь \n");
  28.                     int a = int.Parse(Console.ReadLine());
  29.                     Shape sqr = new Square(a);
  30.                     lib.Add(sqr);
  31.                 }
  32.  
  33.                 else if (usrChoise == 2)
  34.                 {
  35.                     Console.WriteLine("Введите радиус круга, чтобы получить его площадь \n");
  36.                     int a = int.Parse(Console.ReadLine());
  37.                     Shape sqr = new Circle(a);
  38.                     lib.Add(sqr);
  39.                 }
  40.  
  41.                 else if (usrChoise == 3)
  42.                 {
  43.                     Console.WriteLine("Введите основание и высоту треугольника, чтобы получить его площадь \n");
  44.                     Console.WriteLine("Основание: \n");
  45.                     int a = int.Parse(Console.ReadLine());
  46.                     Console.WriteLine("Высота: \n");
  47.                     int h = int.Parse(Console.ReadLine());
  48.                     Shape sqr = new Triangle(a, h);
  49.                     lib.Add(sqr);
  50.                 }
  51.             }
  52.             while (usrChoise != 4);
  53.             Console.WriteLine();
  54.  
  55.             foreach (Shape i in lib)
  56.                 Console.WriteLine(i.GetSquare());
  57.         }
  58.     }
  59.  
  60.     class Shape
  61.     {
  62.         public virtual double GetSquare()
  63.         {
  64.             return 0;
  65.         }
  66.     }
  67.  
  68.     class Square : Shape
  69.     {
  70.         public int a;
  71.         public Square(int b)
  72.         {
  73.             a = b;
  74.         }
  75.         public override double GetSquare()
  76.         {
  77.             int result = a * a;
  78.             return result;
  79.         }
  80.     }
  81.  
  82.     class Circle : Shape
  83.     {
  84.         public int rad;
  85.         public Circle(int r)
  86.         {
  87.             rad = r;
  88.         }
  89.         public override double GetSquare()
  90.         {
  91.             double result = Math.PI * rad * rad;
  92.             return result;
  93.         }
  94.     }
  95.  
  96.     class Triangle : Shape
  97.     {
  98.         public int a, h;
  99.         public Triangle(int aa, int hh)
  100.         {
  101.             a = aa;
  102.             h = hh;
  103.         }
  104.         public override double GetSquare()
  105.         {
  106.             int result = a * h / 2;
  107.             return result;
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement