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 ConsoleApplication48
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Shape> ShapeList = new List<Shape>();
- Shape square1 = new Square(4);
- ShapeList.Add(square1);
- Shape circle1 = new Circle(3);
- ShapeList.Add(circle1);
- Shape triangle1 = new Triangle(6, 8);
- ShapeList.Add(triangle1);
- foreach (Shape item in ShapeList)
- {
- Console.WriteLine(item.GetSquare());
- }
- }
- }
- abstract class Shape
- {
- public abstract int GetSquare();
- }
- class Square : Shape
- {
- int len;
- public Square(int l)
- {
- len = l;
- }
- public override int GetSquare()
- {
- return len * len;
- }
- }
- class Circle : Shape
- {
- int radius;
- public Circle(int r)
- {
- radius = r;
- }
- public override int GetSquare()
- {
- return (int)Math.PI * radius * radius;
- }
- }
- class Triangle : Shape
- {
- int foundation, height;
- public Triangle(int f, int h)
- {
- foundation = f;
- height = h;
- }
- public override int GetSquare()
- {
- return foundation * height / 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement