#include <iostream>
#include <vector>
// *****************************************************************************
class Figure {
public:
virtual double Area() = 0;
void PrintName() {
std::cout << "Фигура = " << Name() << " ";
}
private:
virtual std::string Name() = 0;
};
// *****************************************************************************
class Rectangle: public Figure {
public:
explicit Rectangle(double h, double w): H(h), W(w) {}
double Area() override {
return H*W;
}
private:
double H,W;
std::string Name() override {
return "Прямоугольник";
}
};
// *****************************************************************************
class Square: public Rectangle {
public:
explicit Square(double l): Rectangle (l,l) {}
private:
std::string Name() override {
return "Квадрат";
}
};
// *****************************************************************************
class Ellipse: public Rectangle {
public:
explicit Ellipse(double a, double b): Rectangle (a,b) {}
double Area() override {
return Rectangle::Area()*3.1415;
}
private:
std::string Name() override {
return "Эллипс";
}
};
// *****************************************************************************
int main() {
std::vector<Figure*> V;
V.push_back(new Rectangle(2,3));
V.push_back(new Square(4));
V.push_back(new Ellipse(2,3));
for(const auto &i:V) {
i->PrintName();
std::cout << ", площадь: " << i->Area() << std::endl;
delete i;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKLy8gKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCmNsYXNzIEZpZ3VyZSB7CiAgcHVibGljOgogICAgdmlydHVhbCBkb3VibGUgQXJlYSgpID0gMDsKICAgIHZvaWQgUHJpbnROYW1lKCkgewogICAgICBzdGQ6OmNvdXQgPDwgItCk0LjQs9GD0YDQsCA9ICIgPDwgTmFtZSgpIDw8ICIgIjsKICAgIH0KICBwcml2YXRlOgogICAgdmlydHVhbCBzdGQ6OnN0cmluZyBOYW1lKCkgPSAwOwp9OwoKLy8gKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCmNsYXNzIFJlY3RhbmdsZTogcHVibGljIEZpZ3VyZSB7CiAgcHVibGljOgogICAgZXhwbGljaXQgUmVjdGFuZ2xlKGRvdWJsZSBoLCBkb3VibGUgdyk6IEgoaCksIFcodykge30KICAgIGRvdWJsZSBBcmVhKCkgb3ZlcnJpZGUgewogICAgICByZXR1cm4gSCpXOyAgICAJCiAgICB9CiAgcHJpdmF0ZToKICAgIGRvdWJsZSBILFc7CiAgICBzdGQ6OnN0cmluZyBOYW1lKCkgb3ZlcnJpZGUgewogICAgICByZXR1cm4gItCf0YDRj9C80L7Rg9Cz0L7Qu9GM0L3QuNC6IjsKICAgIH0KfTsKCi8vICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgpjbGFzcyBTcXVhcmU6IHB1YmxpYyBSZWN0YW5nbGUgewogIHB1YmxpYzoKICAgIGV4cGxpY2l0IFNxdWFyZShkb3VibGUgbCk6IFJlY3RhbmdsZSAobCxsKSB7fQogIHByaXZhdGU6CiAgICBzdGQ6OnN0cmluZyBOYW1lKCkgb3ZlcnJpZGUgewogICAgICByZXR1cm4gItCa0LLQsNC00YDQsNGCIjsKICAgIH0KfTsKCi8vICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgpjbGFzcyBFbGxpcHNlOiBwdWJsaWMgUmVjdGFuZ2xlIHsKICBwdWJsaWM6CiAgICBleHBsaWNpdCBFbGxpcHNlKGRvdWJsZSBhLCBkb3VibGUgYik6IFJlY3RhbmdsZSAoYSxiKSB7fQogICAgZG91YmxlIEFyZWEoKSBvdmVycmlkZSB7CiAgICAgIHJldHVybiBSZWN0YW5nbGU6OkFyZWEoKSozLjE0MTU7ICAgIAkKICAgIH0KICBwcml2YXRlOgogICAgc3RkOjpzdHJpbmcgTmFtZSgpIG92ZXJyaWRlIHsKICAgICAgcmV0dXJuICLQrdC70LvQuNC/0YEiOwogICAgfQp9OwoKLy8gKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCmludCBtYWluKCkgewogIHN0ZDo6dmVjdG9yPEZpZ3VyZSo+IFY7CiAgVi5wdXNoX2JhY2sobmV3IFJlY3RhbmdsZSgyLDMpKTsKICBWLnB1c2hfYmFjayhuZXcgU3F1YXJlKDQpKTsKICBWLnB1c2hfYmFjayhuZXcgRWxsaXBzZSgyLDMpKTsKICBmb3IoY29uc3QgYXV0byAmaTpWKSB7CiAgICBpLT5QcmludE5hbWUoKTsKICAgIHN0ZDo6Y291dCA8PCAiLCDQv9C70L7RidCw0LTRjDogIiA8PCBpLT5BcmVhKCkgPDwgc3RkOjplbmRsOwogICAgZGVsZXRlIGk7CiAgfQogIHJldHVybiAwOwp9