Advertisement
Gillito

Untitled

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