#pragma once
#include <memory>
#include <cmath>



class Figure {
public:
	virtual std::string Name() = 0;
	virtual double Perimeter() = 0;
	virtual double Area() = 0;
};

class Triangle: public Figure {
public:
	double per, area;
	Triangle(double a, double b, double c) {
		per = a + b + c;
		double ger = per / 2;
		area = sqrt(ger * (ger - a) * (ger - b) * (ger - c));
	}
	std::string Name() {
		return "TRIANGLE";
	}
	double Perimeter() {
		return per;
	}
	double Area() {
		return area;
	}
};

class Rect: public Figure {
public:
	double per, area;
	Rect(double width, double height) {
		per = 2 * (width + height);
		area = width * height;
	}
	std::string Name() {
		return "RECT";
	}
	double Perimeter() {
		return per;
	}
	double Area() {
		return area;
	}
};

class Circle: public Figure {
public:
	double per, area;
	const double pi = 3.14;
	Circle(double r) {
		per = 2 * pi * r;
		area = pi * pow(r, 2);
	}
	std::string Name() {
		return "CIRCLE";
	}
	double Perimeter() {
		return per;
	}
	double Area() {
		return area;
	}
};

std::shared_ptr<Figure> CreateFigure(std::istringstream &is) {
	using std::make_shared;
	std::string figure_t;
	int64_t a, b, c;
	is >> figure_t;
	if (figure_t == "RECT") {
		is >> a >> b;
		return make_shared<Rect>(a, b);
	}
	else if (figure_t == "TRIANGLE") {
		is >> a >> b >> c;
		return make_shared<Triangle>(a, b, c);
	}
	else {
		is >> a;
		return make_shared<Circle>(a);
	}
}