1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
| #include <iostream>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;
ifstream in("in.txt");
ofstream out ("out.txt");
class Figure
{
public:
virtual void Show() = 0;
virtual double Area() = 0;
virtual double Perimeter() = 0;
virtual void Info() = 0;
};
class Rectangle : public Figure
{
protected:
double a;
double b;
public:
Rectangle() : a(0), b(0) {}
Rectangle(double a, double b) : a(a), b(b) {}
void Show()
{
out << "Rectangle: ";
out << "(" << a << ", " << b << ")" << endl;
out << "Perimeter: " << Perimeter() << endl;
out << "Area: " << Area() << endl;
}
void Info()
{
if (a == b)
out << "It's square";
else
out << "Rectangle";
}
double Perimeter()
{
return 2 * (a + b);
}
double Area()
{
return a * b;
}
double GetA()
{
return a;
}
double GetB()
{
return b;
}
};
class Triangle : public Figure
{
protected:
double a;
double b;
double c;
public:
Triangle() : a(0), b(0), c(0) {}
Triangle(double a, double b, double c) : a(a), b(b), c(c) {}
void Show()
{
out << "Triangle: ";
out << "(" << a << "," << b << "," << c << ")" << endl;
out << "Perimeter: " << Perimeter() << endl;
out << "Area: " << Area() << endl;
}
double Perimeter()
{
return a + b + c;
}
double Area()
{
return sqrt((Perimeter() / 2)*((Perimeter() / 2) - a)*((Perimeter() / 2) - b)*((Perimeter() / 2) - c));
}
void Info()
{
if (a == b && b == c && a == c)
out << "Triangle equilateral" << endl;
else
if (a == b || a == c || b == c)
out << "Triangle isosceles" << endl;
}
double GetA()
{
return a;
}
double GetB()
{
return b;
}
double GetC()
{
return c;
}
};
class Point
{
protected:
double a;
double b;
public:
Point() : a(0), b(0) {}
Point(double a, double b) : a(a), b(b) {}
void SetAB(double a, double b)
{
this->a = a;
this->b = b;
}
double GetA()
{
return a;
}
double GetB()
{
return b;
}
void Show()
{
out << "Point: ";
out << " (" << a << ", " << b << ")" << endl;
}
};
class Circle : public Figure
{
protected:
Point *k;
int radius;
public:
Circle() : radius(0)
{
k = new Point();
}
Circle(int a, int b, int radius) : radius(radius)
{
k = new Point(a, b);
}
void Show()
{
out << "Circle: " << endl;
out << "Center: (" << k->GetA() << ", " << k->GetB() << "), " << endl;
out << "Radius: " << radius << endl;
out << "Perimeter: " << Perimeter() << endl;
out << "Area: " << Area() << endl;
}
void Info()
{
out << "Circle" << endl;
}
double Perimeter()
{
return 2 * 3.1415 * radius;
}
double Area()
{
return 3.1415 * (radius*radius);
}
~Circle()
{
delete k;
}
};
int main()
{
Figure *objects[3];
objects[0] = new Circle(0, 0, 3);
objects[1] = new Triangle(2, 2, 3);
objects[2] = new Rectangle(4, 5);
for (int i = 0; i <= 2; i++)
{
objects[i]->Show();
}
for (int i = 0; i <= 2; i++)
{
delete objects[i];
}
out.close();
return 0;
} |