-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Poly2.h
91 lines (76 loc) · 1.51 KB
/
Poly2.h
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
#pragma once
// ðàííåå ñâÿçûâàíèå
class EarlyBindingPolymorphismDemo
{
class Transport
{
double speed;
public:
virtual void Drive()
{
cout << "Transport::Drive\n";
}
};
class Car : public Transport
{
public:
/*virtual*/ void Drive()
{
cout << "Car::Drive\n";
}
};
class Bike : public Transport
{
public:
/*virtual*/ void Drive()
{
cout << "Bike::Drive\n";
}
};
class Telega : public Transport // òåëåãà
{
public:
/*virtual*/ void Drive()
{
cout << "Telega::Drive\n";
}
};
static Transport* GetSomeTransport()
{
int r = rand() % 3;
if (r == 0) return new Car;
if (r == 1) return new Telega;
return new Bike;
}
public:
static void Test()
{
int count = 5; // êîëè÷åñòâî òðàíñïîðòíûõ ñðåäñòâ
// cin >> count;
// count = rand() % 20;
Transport** traffic = new Transport* [count];
// íàñòðîéêà
traffic[0] = new Car;
traffic[1] = new Car;
traffic[2] = new Bike;
traffic[3] = new Telega;
traffic[4] = GetSomeTransport();
///////////////////////// æä¸ì ñâåòîôîð...
Application::SetConsoleColor(Application::Color::RED);
cout << "Wait 3 ";
Sleep(1000);
cout << "2 ";
Sleep(1000);
cout << "1 ";
Sleep(1000);
system("cls");
Application::SetConsoleColor(Application::Color::GREEN);
cout << "Go!!!\n\n";
Sleep(1000);
Application::SetConsoleColor(Application::Color::GRAY);
///////////////////////// ïîãíàëè íàøè ãîðîäñêèõ!
for (int i = 0; i < count; i++)
traffic[i]->Drive();
}
};
// EarlyBindingPolymorphismDemo::Test();