-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbus
More file actions
109 lines (104 loc) · 3.19 KB
/
bus
File metadata and controls
109 lines (104 loc) · 3.19 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
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
#include <iostream>
#include <string>
using namespace std;
struct card {
int nym_bus, nym_rout;
bool condit;
string name_driv;
card *next;
};
void my_cin(int &z) {
while (!(cin >> z) || (cin.peek() != '\n')) {
cin.clear();
while (cin.get() != '\n');
cout << "Error input, retry input!" << endl;
}
}
void add_card(card *&bus_park) {
card *ptr = new card;
cout << "Enter name driver: ";
cin >> ptr->name_driv;
cout << "Enter nymber bus: ";
my_cin(ptr->nym_bus);
ptr->nym_rout = ptr->condit = 0;
ptr->next = nullptr;
if (bus_park) {
for (auto ptr2 = bus_park;; ptr2 = ptr2->next)
if (!ptr2->next) {
ptr2->next = ptr;
break;
}
}
else
bus_park = ptr;
}
void send_ret(card &bus_park, int x) {
int y;
cout << "Enter nymber bus: "; my_cin(y);
auto *time_ptr = &bus_park;
for (; time_ptr; time_ptr = time_ptr->next)
if (time_ptr->nym_bus == y)
break;
else if (!time_ptr->next) {
cout << "Nymber bus " << y << " not found...\n";
return;
}
if ((x == 2 && time_ptr->condit) || (x == 3 && !time_ptr->condit)) {
if (x == 2)
cout << "(error) The bus is on the route.\n";
else
cout << "(error) The bus is in park.\n";
return;
}
else
if (x == 2) {
time_ptr->condit = 0;
cout << "The bus return in park.\n";
}
else {
time_ptr->condit = 1;
time_ptr->nym_rout = rand() % 100;
}
}
void show_bus_card(card *&bus_card) {
int c;
cout << "For show bus in route input 1, to show bus in park enter 2: ";
my_cin(c);
for (auto time_ptr(bus_card); time_ptr; time_ptr = time_ptr->next)
if (c == 1 && time_ptr->condit)
cout << "\nBus nymber " << time_ptr->nym_bus <<
"\nDriver " << time_ptr->name_driv <<
"\nRoute nymber " << time_ptr->nym_rout << endl;
else if (c == 2 && !time_ptr->condit)
cout << "\nBus nymber " << time_ptr->nym_bus <<
"\nDriver " << time_ptr->name_driv << endl;
}
int main()
{
card *bus_park(nullptr);
int x(1);
while (x) {
cout << "//-----------------------------------------------------------------------\n";
cout << "To add a driver card input 1, to send bus" <<
" input 2 or to return bus input 3, to show input 4. To exit enter 0: ";
my_cin(x);
cout << "//-----------------------------------------------------------------------\n";
switch (x) {
case 1:
add_card(bus_park);
break;
case 2: case 3:
if (bus_park) send_ret(*bus_park, x);
else cout << "To start, add a record about buses!\n";
break;
case 4:
if (bus_park) show_bus_card(bus_park);
else cout << "To start, add a record about buses!\n";
break;
default:
if (x)
cout << "To enter nymber 1 of 2 or 3 or 4 or 0...\n";
}
}
return 0;
}