Вот код переделал но вот в чем беда в колледже мы вектора не проходили...
Надо переделать под На массив типа workers СРОЧНО ПРОШУ !!!!
C++ |
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
| #include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
int i = 0;
ofstream file("workers.txt");
bool added = false;
struct worker {
int id;
int age;
string name;
string surname;
string secname;
string post;
};
vector <worker> workers;
int add() {
system("cls");
worker temp;
string name, surname, secname, post;
int age, n;
cout << "Введите кол-во работников: ";
while (!(cin >> n) || (n <= 0 || n > 120)) {
system("cls");
cout << "Error!" << endl;
system("pause");
cin.clear();
while (cin.get() != '\n');
system("cls");
cout << "Введите кол-во работников: ";
}
n += i;
while (i < n) {
cout << "Введите имя, фамилию, отчество работника: ";
cin >> name >> surname >> secname;
cout << "Введите должность работника: ";
cin >> post;
cout << "Введите возраст работника: ";
while (!(cin >> age) || (age < 16 || age > 62)) {
system("cls");
cout << "Error!" << endl;
system("pause");
cin.clear();
while (cin.get() != '\n');
system("cls");
cout << "Введите кол-во работников: " << n << endl;
cout << "Введите имя, фамилию, отчество работника: "
<< " " << name << " " << surname << " " << secname << endl;
cout << "Введите должность работника: " << post << endl;
cout << "Введите возраст работника: ";
}
name[0] = (char)toupper(name[0]);
for (int i = 1; i < name.length(); i++)
name[i] = (char)tolower(name[i]);
surname[0] = (char)toupper(surname[0]);
for (int i = 1; i < surname.length(); i++)
surname[i] = (char)tolower(surname[i]);
secname[0] = (char)toupper(secname[0]);
for (int i = 1; i < secname.length(); i++)
secname[i] = (char)tolower(secname[i]);
post[0] = (char)toupper(post[0]);
for (int i = 1; i < post.length(); i++)
post[i] = (char)tolower(post[i]);
temp.name = name;
temp.surname = surname;
temp.secname = secname;
temp.post = post;
temp.age = age;
temp.id = i + 1;
workers.push_back(temp);
file << i + 1 << " " << name << " " << surname << " " << secname << " " << post <<
" " << age << endl;
i++;
}
added = true;
}
void printall() {
system("cls");
if (workers.size() == 0) {
cout << "Файл пуст!" << endl;
system("pause");
return;
}
for (int i = 0; i < workers.size() - 1; i++) {
for (int j = 0; j < workers.size() - i - 1; j++) {
if (workers[j].id > workers[j + 1].id) {
swap(workers[j], workers[j + 1]);
}
}
}
for (int i = 0; i < workers.size(); i++) {
cout << "ID: " << workers[i].id << endl;
cout << "Name: " << workers[i].name << endl;
cout << "Surname: " << workers[i].surname << endl;
cout << "Secname: " << workers[i].secname << endl;
cout << "Post: " << workers[i].post << endl;
cout << "Age: " << workers[i].age << endl << endl;
}
system("pause");
}
void printtw() {
system("cls");
if (workers.size() == 0) {
cout << "Файл пуст!" << endl;
system("pause");
return;
}
int a = 0;
for (int i = 0; i < workers.size() - 1; i++) {
for (int j = 0; j < workers.size() - i - 1; j++) {
if (workers[j].age > workers[j + 1].age) {
swap(workers[j], workers[j + 1]);
}
}
}
for (int i = 0; i < workers.size(); i++) {
if (workers[i].age > 25) {
cout << "ID: " << workers[i].id << endl;
cout << "Name: " << workers[i].name << endl;
cout << "Surname: " << workers[i].surname << endl;
cout << "Secname: " << workers[i].secname << endl;
cout << "Post: " << workers[i].post << endl;
cout << "Age: " << workers[i].age << endl << endl;
a++;
}
}
if (a == 0)
cout << "В списке нет работников старше 25 лет!" << endl;
system("pause");
}
int main(int argc, char** argv) {
setlocale(LC_ALL, "RUS");
int menuChoice;
do {
system("cls");
cout << "Worker 1.2" << endl;
cout << "1) Add" << endl;
cout << "2) Print All" << endl;
cout << "3) Print 25" << endl;
cout << "4) Exit" << endl;
cout << "Your choice: ";
while (!(cin >> menuChoice) || (menuChoice < 1 || menuChoice > 4)) {
system("cls");
cout << "Error!" << endl;
system("pause");
cin.clear();
while (cin.get() != '\n');
system("cls");
cout << "Worker 1.2" << endl;
cout << "1) Add" << endl;
cout << "2) Print All" << endl;
cout << "3) Print 25" << endl;
cout << "4) Exit" << endl;
cout << "Your choice: ";
}
switch (menuChoice) {
case 1: add(); break;
case 2: printall(); break;
case 3: printtw(); break;
case 4:
cout << "See you later." << endl;
system("pause");
return 0;
break;
}
} while (menuChoice != 0);
return 0;
} |
|