Advertisement
Gillito

Untitled

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