Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- abstract class Shape
- {
- public string Name { get; set; }
- public string Color { get; set; }
- public abstract double GetPerimeter();
- public Shape(string name,string color)
- {
- this.Name = name;
- this.Color = color;
- }
- }
- class MyCircle : Shape
- {
- public double Radius { get; set; }
- public MyCircle(string name,string color,double radius)
- :base(name,color)
- {
- this.Radius = radius;
- }
- public override double GetPerimeter()
- {
- return Math.PI * Radius * 2;
- }
- }
- class MyRectangle : Shape
- {
- public double A { get; set; }
- public double B { get; set; }
- public MyRectangle(string name,string color,double a,double b)
- :base(name,color)
- {
- this.A = a;
- this.B = b;
- }
- public override double GetPerimeter()
- {
- return (A + B) * 2;
- }
- }
- public double A { get; set; }
- public double B { get; set; }
- public double C { get; set; }
- public MyTriangle(string name,string color,double a,double b,double c)
- :base(name,color)
- {
- this.A = a;
- this.B = b;
- this.C = c;
- }
- public override double GetPerimeter()
- {
- return A + B + C;
- }
- static void Main(string[] args)
- {
- MyCircle circle = new MyCircle("circle1","green",2);
- MyRectangle rectangle = new MyRectangle("rectangle1","black",4,2);
- MyTriangle triangle = new MyTriangle("triangle1","red",2,4,9);
- List<Shape> shapes = new List<Shape>();
- shapes.Add(circle);
- shapes.Add(rectangle);
- shapes.Add(triangle);
- foreach (Shape item in shapes)
- {
- Console.WriteLine(item.Name+", "+item.Color+", "+item.GetPerimeter());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement