#include #include class Figure { public: virtual std::string Name() = 0; virtual double Perimeter() = 0; virtual double Area() = 0; }; class Triangle : public Figure { public: Triangle(const int& one, const int& two, const int& three) { a = one; b = two; c = three; } std::string Name() { return "TRIANGLE"; } double Perimeter() { return a + b + c; } double Area() { double p = (a + b + c) / 2.0; return sqrt(p * (p - a) * (p - b) * (p - c)); } private: int a, b, c; }; class Rect : public Figure { public: Rect(const int& one, const int& two) { a = one; b = two; } std::string Name() { return "RECT"; } double Perimeter() { return 2.0 * (a + b); } double Area() { return a * b; } private: int a, b; }; class Circle : public Figure { public: explicit Circle(const int& one) { a = one; } std::string Name() { return "CIRCLE"; } double Perimeter() { return 2 * 3.14 * a; } double Area() { return 3.14 * a * a; } private: int a; }; std::shared_ptr
CreateFigure(std::istringstream& is) { std::string fig; is >> fig; if (fig == "RECT") { int a, b; is >> a >> std::ws >> b; return std::make_shared(a, b); } else if (fig == "TRIANGLE") { int a, b, c; is >> a >> std::ws >> b >> std::ws >> c; return std::make_shared(a, b, c); } else { int a; is >> a; return std::make_shared(a); } }