#include #include #include #include #include #include #include #include #include #include #include #include using std::string; using std::shared_ptr; using std::cout; using std::endl; using std::ws; using std::vector; using std::istringstream; using std::fixed; using std::cin; using std::setprecision; class Figure { public: virtual string Name() = 0; virtual double Perimeter() = 0; virtual double Area() = 0; }; class Triangle : public Figure { private: int a, b, c; public: Triangle(int a, int b, int c) : a(a), b(b), c(c) {} string Name() override { return "TRIANGLE"; } double Perimeter() override { return a + b + c; } double Area() override { int s = (a + b + c) / 2; return sqrt(s * (s - a) * (s - b) * (s - c)); } }; class Rect : public Figure { private: int width, height; public: Rect(int w, int h) : width(w), height(h) {} string Name() override { return "RECT"; } double Perimeter() override { return (width * 2) + (height * 2); } double Area() override { return width * height; } }; class Circle : public Figure { private: int r; public: explicit Circle(int r) : r(r) {} string Name() override { return "CIRCLE"; } double Perimeter() override { return 2 * 3.14 * r; } double Area() override { return 3.14 * r * r; } }; shared_ptr
CreateFigure(std::istringstream &stream) { string name; stream >> name; if (name == "TRIANGLE") { int a, b, c; stream >> a >> b >> c; return shared_ptr
(new Triangle(a, b, c)); } else if (name == "RECT") { int w, h; stream >> w >> h; return shared_ptr
(new Rect(w, h)); } else { int r; stream >> r; return shared_ptr
(new Circle(r)); } } int main() { vector> figures; for (string line ; getline(cin, line) ;) { istringstream is(line); string command; is >> command; if (command == "ADD") { is >> ws; figures.push_back(CreateFigure(is)); } else if (command == "PRINT") { for (const auto ¤t_figure : figures) { cout << fixed << setprecision(3) << current_figure->Name() << " " << current_figure->Perimeter() << " " << current_figure->Area() << endl; } } } return 0; }