Advertisement
Gillito

Untitled

Jun 18th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 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 ConsoleApplication48
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<Shape> ShapeList = new List<Shape>();
  14.  
  15.             Shape square1 = new Square(4);
  16.             ShapeList.Add(square1);
  17.  
  18.             Shape circle1 = new Circle(3);
  19.             ShapeList.Add(circle1);
  20.  
  21.             Shape triangle1 = new Triangle(6, 8);
  22.             ShapeList.Add(triangle1);
  23.  
  24.             foreach (Shape item in ShapeList)
  25.             {
  26.                 Console.WriteLine(item.GetSquare());
  27.             }
  28.         }
  29.     }
  30.  
  31.     abstract class Shape
  32.     {
  33.         public abstract int GetSquare();
  34.     }
  35.  
  36.     class Square : Shape
  37.     {
  38.         int len;
  39.         public Square(int l)
  40.         {
  41.             len = l;
  42.         }
  43.         public override int GetSquare()
  44.         {
  45.             return len * len;
  46.         }
  47.     }
  48.  
  49.     class Circle : Shape
  50.     {
  51.         int radius;
  52.  
  53.         public Circle(int r)
  54.         {
  55.             radius = r;
  56.         }
  57.         public override int GetSquare()
  58.         {
  59.             return (int)Math.PI * radius * radius;
  60.         }
  61.  
  62.     }
  63.  
  64.     class Triangle : Shape
  65.     {
  66.         int foundation, height;
  67.  
  68.         public Triangle(int f, int h)
  69.         {
  70.             foundation = f;
  71.             height = h;
  72.         }
  73.         public override int GetSquare()
  74.         {
  75.             return foundation * height / 2;
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement