#include <string>
#include <memory>
#include <cmath>
#include <iostream>
const double PI = 3.14;
class Figure {
public:
virtual std::string Name() = 0;
virtual double Perimeter() = 0;
virtual double Area() = 0;
};
class Rect: public Figure {
int width;
int height;
public:
explicit Rect(int width, int height) : width(width), height(height) {}
std::string Name() override { return "RECT"; }
double Perimeter() override { return width + height; }
double Area() override { return width * height; }
};
class Triangle: public Figure {
int a;
int b;
int c;
public:
explicit Triangle(int a, int b, int c) : a(a), b(b), c(c) {}
std::string Name() override { return "TRIANGLE"; }
double Perimeter() override { return a + b + c; }
double Area() override {
double p = this->Perimeter() / 2;
return sqrt(p * (p - a) * (p - b) * (p - c));
}
};
class Circle: public Figure {
int r;
public:
explicit Circle(int r) : r(r) {}
std::string Name() override { return "CIRCLE"; }
double Perimeter() override { return 2 * PI * r; }
double Area() override { return PI * r * r; }
};
std::shared_ptr<Figure> CreateFigure(std::istringstream& is) {
std::string type; is >> type;
if (type[0] == 'R') {
int w, h; is >> w >> h;
auto ptr = std::shared_ptr<Rect>(new Rect(w, h));
return ptr;
} else if (type[0] == 'T') {
int a, b, c; is >> a >> b >> c;
auto ptr = std::shared_ptr<Triangle>(new Triangle(a, b, c));
return ptr;
} else if (type[0] == 'C') {
int r; is >> r;
auto ptr = std::shared_ptr<Circle>(new Circle(r));
return ptr;
} else {
return nullptr;
}
}