# Untitled

May 29th, 2022
829
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include "iostream"
2. #include "cmath"
3.
4. using namespace std;
5.
6. class Figure{
7. protected:
8.     string TypeFigure;
9. public:
10.     Figure(){}
11.     virtual ~Figure() {}
12.     string GetTypeFigure() { return TypeFigure; }
13.     virtual double Area() = 0;
14. };
15.
16.
17. class Triangle : public Figure{
18.     double AB, BC, AC;
19. public:
20.     Triangle(){}
21.     Triangle(double AB, double BC, double AC){
22.         this->AB = AB;
23.         this->BC = BC;
24.         this->AC = AC;
25.         TypeFigure = "Triangle";
26.     };
27.     double Area(){
28.         double p = (AB+BC+AC)/2;
29.         return sqrt(p*(p-AB)*(p-BC)*(p-AC));
30.     }
31. };
32.
33. class Rectangle : public Figure{
34.     double AB, BC;
35. public:
36.     Rectangle(){}
37.     Rectangle(double AB, double BC){
38.         this->AB = AB;
39.         this->BC = BC;
40.         TypeFigure = "Rectangle";
41.     }
42.     double Area(){
43.         return AB*BC;
44.     }
45. };
46.
47. class Circle : public Figure{
48.     double R;
49. public:
50.     Circle(){}
51.     Circle(double R){
52.         this->R = R;
53.         TypeFigure = "Circle";
54.     }
55.     double Area(){
56.         return 3.14*R*R;
57.     }
58. };
59.
60. int main(){
61.     string Type;
62.     cin >> Type;
63.     Figure *temp;
64.     if (Type == "Triangle"){
65.         double AB, BC, AC;
66.         cin >> AB >> BC >> AC;
67.         temp = new Triangle(AB,BC,AC);
68.     }
69.     else if (Type == "Rectangle"){
70.         double AB, BC;
71.         cin >> AB >> BC;
72.         temp = new Rectangle(AB, BC);
73.     }
74.     else if (Type == "Circle"){
75.         double R;
76.         cin >> R;
77.         temp = new Circle(R);
78.     }
79.     else{
80.         cout << "Input error" << endl;
81.         return 0;
82.     }
83.     cout << "Area " << temp->GetTypeFigure() <<  " = "<< temp->Area();
84.     delete temp;
85.     return 0;
86. }