Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace Figure
- {
- abstract class Figure
- {
- public abstract double Area();
- public abstract double Perimeter();
- public abstract void ShowInfo();
- }
- class Rectangle : Figure
- {
- double a, b;
- public Rectangle(double a, double b)
- {
- this.a = a;
- this.b = b;
- }
- public override double Area()
- {
- return a * b;
- }
- public override double Perimeter()
- {
- return (a + b) * 2;
- }
- public override void ShowInfo()
- {
- Console.WriteLine("Прямоугольник со сторонами {0} и {1}", a, b);
- }
- }
- class Triangle : Figure
- {
- double a, b, c;
- public Triangle(double a, double b, double c)
- {
- this.a = a;
- this.c = c;
- this.b = b;
- }
- public override double Perimeter()
- {
- return a + b + c;
- }
- public override double Area()
- {
- double p = Perimeter() / 2;
- return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
- }
- public override void ShowInfo()
- {
- Console.WriteLine("Треугольник со сторонами {0}, {1}, {2}", a, b, c);
- }
- }
- class Circle : Figure
- {
- const double pi = 3.14;
- double r;
- public Circle(double r)
- {
- this.r = r;
- }
- public override double Area()
- {
- return pi * r * r;
- }
- public override double Perimeter()
- {
- return 2 * pi * r;
- }
- public override void ShowInfo()
- {
- Console.WriteLine("Круг c радиусом {0}.", r);
- }
- }
- class Program
- {
- static void Main()
- {
- Figure[] arFigs = {
- new Rectangle(2,4),
- new Triangle(2,3,4),
- new Circle(5)
- };
- for (int i = 0; i < arFigs.Length; i++)
- {
- arFigs[i].ShowInfo();
- Console.Write("Периметр: {0}; Площадь: {1}\n\n", arFigs[i].Perimeter(), arFigs[i].Area());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement