-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
153 lines (143 loc) · 5.08 KB
/
main.cpp
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
#include <iostream>
//#include <algorithm>
using namespace std;
//MARK: - car
class car
{
public:
friend class police;
friend bool checkPos(car &one);
friend class cam;
friend void workCam(car&bip);
car(string mark, string num, int x){
this -> mark = mark;
this -> num = num;
this -> x = x;
}
string mark;
string num;
void motion(){
if (timeStop == 0){
this -> spd = 51 + rand()%16;
this -> x = this -> x + spd;
}else {
this -> spd = 0;
timeStop--;
}
}
void showX(){
cout << this -> x << " ";
}
int counter = 0;
private:
int spd;
int x;
int checkCam = -1; // проверка от повторного штрафа
int spamCam = -1; // Проверка от спама принадлжености к области действия камеры
int spamPolice = -1; // Проверка от спама принедлежности к области действия сотрудника
int stoped = -1; // номер сотрудника, останивившего автомобиль
int timeStop = 0;
};
//MARK: - police
class police{
friend class cam;
friend void workCam(car &bip);
public:
police(int x, int num){
this -> x = x;
this -> num = num;
}
bool checkPos ( car &bip ){
if (( bip.x > this -> x - 100)&&(bip.x < this -> x + 100 )){
return true;
}else {
return false;
}
}
void work(car &bip){
if (checkPos(bip)){
if (bip.spamPolice != this -> num){
cout << "Автомобиль марки " << bip.mark << " находится в зоне видимости сотрудника полиции ["<< num << "]." << endl;
bip.spamPolice = this -> num;
}
if ((bip.counter != 0)&&(bip.x > this -> x - 40 && bip.x < this -> x + 40)){
// если есть штраф = останавливаем
if(bip.stoped != this -> num){
bip.x = this -> x;
cout << "Автомобиль с гос.номером " << bip.num << " был остановлен сотрудиком полиции [" << this -> num << "]" << endl;
bip.timeStop = 10;
bip.spd = 0;
bip.stoped = this -> num;
}
}
if (bip.stoped == num && bip.spd != 0){
cout << "Сотрудник полиции [" << this -> num << "] отпустил автомобиль марки " << bip.mark << endl;
}
}
}
private:
int x;
int num;
};
//MARK: - cam
class cam : public police{
public:
cam(int x, int y, int lim) : police (x, y){
this -> lim = lim;
}
void workCam(car &bip){
if (checkPos(bip)){
if (bip.spamCam != this -> num){
cout << "Автомобиль марки " << bip.mark << " находится в зоне видимости камеры под номером " << this -> num << endl;
}
if ( bip.spd > this -> lim){
if (bip.checkCam != this -> num){
bip.counter++;
bip.checkCam = num;
cout << "На номер " << bip.num << " был выписан штраф. Скорость т/с " << bip.spd << " км/ч.Разрешенная скорость " << this -> lim << " км/ч" << endl;
} else {
cout << "На номер " << bip.num << " уже был выписан штраф" << endl;
}
}
}
}
private:
int lim;
};
bool operator < (const car &bmw, const car &lada){
return bmw.counter < lada.counter;
}
bool operator == ( const car &bmw, const car &lada){
return bmw.counter == lada.counter;
}
int operator + ( const car &one, const car &two){
return one.counter + two.counter;
}
//MARK: - main
int main(){
police Vitalii(300, 15);
cam photo(2,4,44);
cam street(200, 13,60);
cam Most(1,228,60);
car carFirst("BMW", "B868PY",0);
car carSecond("Lada", "A987BA",184);
for ( int i = 0; i < 60; i++ ){
carFirst.motion();
//carFirst.showX();
carSecond.motion();
Most.workCam(carFirst);
Most.workCam(carSecond);
Vitalii.work(carSecond);
Vitalii.work(carFirst);
}
if (carFirst == carSecond){
cout << "Количество штрафов у " << carFirst.mark << " и у " << carSecond.mark << " одинаково." << endl;
} else {
if ( carFirst < carSecond){
cout << "В этот раз водитель " << carFirst.mark << " нарушил ПДД меньше, чем водитель " << carSecond.mark << endl;
} else {
cout << "В этот раз водитель " << carSecond.mark << " нарушил ПДД меньше, чем водитель " << carFirst.mark << endl;
}
}
cout << "Общее количество штрафов = " << carFirst + carSecond << endl;
}