-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.cpp
More file actions
75 lines (62 loc) · 1.5 KB
/
Shape.cpp
File metadata and controls
75 lines (62 loc) · 1.5 KB
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
#include <iostream>
#include <locale>
using namespace std;
class Shape {
protected:
string color;
public:
Shape(string c)
{
color = c;
}
virtual void draw() = 0;
};
class Circle : public Shape {
private:
int x;
int y;
int radius;
public:
Circle(string c, int xCoord, int yCoord, int r) : Shape(c)
{
x = xCoord;
y = yCoord;
radius = r;
}
void draw() override {
cout << "Ðèñóåì êðóã ñ êîîðäèíàòàìè (" << x << ", " << y << "), ðàäèóñîì " << radius << " è öâåòîì " << color << endl;
}
};
class Rectangle : public Shape {
private:
int x;
int y;
int width;
int height;
public:
Rectangle(string c, int xCoord, int yCoord, int w, int h) : Shape(c)
{
x = xCoord;
y = yCoord;
width = w;
height = h;
}
void draw() override {
cout << "Ðèñóåì ïðÿìîóãîëüíèê ñ êîîðäèíàòàìè (" << x << ", " << y << "), ðàçìåðîì " << width << "x" << height << " è öâåòîì " << color << endl;
}
};
int main() {
setlocale(LC_ALL, "RUS");
const int numShapes = 3;
Shape* shapes[numShapes];
shapes[0] = new Circle("êðàñíûé", 0, 0, 5);
shapes[1] = new Rectangle("ñèíèé", 2, 2, 3, 7);
shapes[2] = new Circle("çåë¸íûé", 3, 1, 8);
for (int i = 0; i < numShapes; ++i) {
shapes[i]->draw();
}
for (int i = 0; i < numShapes; ++i) {
delete shapes[i];
}
return 0;
}