123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #define pi 3.14
- class Shape {
- public:
- virtual double GetArea() const = 0;
- virtual ~Shape() {}
- };
- class Circle : public Shape {
- private:
- double radius;
- public:
- Circle(double r) : radius(r) {}
- double GetArea() const override {
- return pi * radius * radius;
- }
- };
- class Rectangle : public Shape {
- private:
- double length;
- double width;
- public:
- Rectangle(double l, double w) : length(l), width(w) {}
- double GetArea() const override {
- return length * width;
- }
- };
- class Square : public Rectangle {
- public:
- Square(double side) : Rectangle(side, side) {}
- };
- int main() {
- double radius;
- std::cin >> radius;
- Circle* circle = new Circle(radius);
- std::cout << "The area of the Cirele is:" << circle->GetArea() << std::endl;
- delete circle;
- double length, width;
- std::cin >> length >> width;
- Rectangle* rectangle = new Rectangle(length, width);
- std::cout << "The area of the Recanale is:" << rectangle->GetArea() << std::endl;
- delete rectangle;
- double side;
- std::cin >> side;
- Square* square = new Square(side);
- std::cout << "The area of the Recanale is:" << square->GetArea() << std::endl;
- delete square;
- return 0;
- }
|