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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
| #include <cstdlib>
#include <iostream>
#include <ctime>
#include <cmath>
#include <stdio.h>
#define m 5
#define n 2
using namespace std;
struct Fio
{
char fam[100];
char name[100];
char otchestvo[100];
};
struct Birthday
{
int day;
int mounth;
int year;
};
struct Address
{
char street[100];
char house[100];
int apart;
};
struct Mark
{
char object[100];
int grade;
};
struct STUDENT
{
Fio f;
Birthday b;
Address a;
char number[10];
char facul[100];
char group[100];
int course;
Mark M[5];
};
int main(void)
{
setlocale(LC_ALL, "rus");
/*№1*/
cout << " [Задание 1]" << endl << "[Ввод с клавиатуры данных в массив, состоящий из 10 структур типа STUDENT]" << endl;
STUDENT s[2];
for (int i = 0; i < n; i++)
{
cout << "Familiya: "; cin >> s[i].f.name;
cout << "Name: "; cin >> s[i].f.name;
cout << "Otchestvo: "; cin >> s[i].f.otchestvo;
cout << "Day: "; cin >> s[i].b.day;
cout << "Mounth: "; cin >> s[i].b.mounth;
cout << "Year: "; cin >> s[i].b.year;
cout << "Street: "; cin >> s[i].a.street;
cout << "House: "; cin >> s[i].a.house;
cout << "Apartment: "; cin >> s[i].a.apart;
cout << "Phone Number: "; cin >> s[i].number;
cout << "Faculty: "; cin >> s[i].facul;
cout << "Group: "; cin >> s[i].group;
cout << "Course: "; cin >> s[i].course;
cout << endl;
cout << "Mark:" << endl;
for (int j = 0; j < m; j++)
{
cout << "Object: "; cin >> s[i].M[j].object;
cout << "Grade: "; cin >> s[i].M[j].grade;
}
cout << endl;
}
cout << endl;
/*№2*/
cout << " [Задание №2]" << endl << "[Вывод на экран данных из массива типа STUDENT]" << endl;
for (int i = 0; i < n; i++)
{
cout << "1) FIO:";
cout << s[i].f.fam << " " << s[i].f.name << " " << s[i].f.otchestvo << endl;
cout << "2) Birthday:";
cout << s[i].b.day << "." << s[i].b.mounth << "." << s[i].b.year << endl;
cout << "3) Adress";
cout << s[i].a.street << "," << s[i].a.house << "," << s[i].a.apart << endl;
cout << "4) Telephone Number:";
cout << s[i].number << endl;
cout << "5) Faculty:" << " ";
cout << s[i].facul << "," << s[i].course << "," << s[i].group << endl;
cout << "6) Mark:" << endl;
for (int j = 0; j < 5; j++)
{
cout << s[i].M[j].object << " : ";
cout << s[i].M[j].grade << endl;
}
}
cout << endl;
/*№3*/
cout << " [Задание №3]" << endl << "[Сортировка массива структур в алфавитном порядке фамилий студентов]" << endl;
bool b;
do
{
b = true;
for (int i = 0; i < n - 1; i++) {
if (strcmp(s[i].f.fam, s[i + 1].f.fam) > 0)
{
STUDENT c = s[i];
s[i] = s[i + 1];
s[i + 1] = c;
b = false;
}
}
} while (b != true);
for (int i = 0; i < 0; i++)
{
cout << "FIO:" << s[i].f.fam << " " << s[i].f.name << " " << s[i].f.otchestvo << endl;
}
cout << endl;
/*№4*/
cout << " [Задание №4]" << endl << "[Сортировка массива структур по дню рождения]" << endl;
do
{
b = true;
for (int i = 0; i < n - 1; i++)
{
if (s[i].b.year > s[i + 1].b.year)
{
STUDENT c = s[i];
s[i] = s[i + 1];
s[i + 1] = c;
b = false;
}
else
if (s[i].b.year == s[i + 1].b.year && s[i].b.mounth > s[i + 1].b.mounth)
{
STUDENT c = s[i];
s[i] = s[i + 1];
s[i + 1] = c;
b = false;
}
else
if (s[i].b.mounth == s[i + 1].b.mounth && s[i].b.day > s[i + 1].b.day)
{
STUDENT c = s[i];
s[i] = s[i + 1];
s[i + 1] = c;
b = false;
}
}
} while (b != true);
for (int i = 0; i < 0; i++)
{
cout << "FIO:" << s[i].f.fam << " " << s[i].f.name << " " << s[i].f.otchestvo << endl;
cout << "Birthday: " << s[i].b.day << "." << s[i].b.mounth << "." << s[i].b.year << endl;
}
cout << endl;
/*№5*/
cout << " [Задание №5]" << endl << "[Сортировка массива структур в порядке убывания среднего балла]" << endl;
do {
b = true;
for (int i = 0; i < n - 1; i++) {
int sred0 = 0, sred1 = 0;
for (int j = 0; j < 5; j++)
{
sred0 += s[i].M[j].grade;
sred1 += s[i + 1].M[j].grade;
}
if (sred0 / 5 < sred1 / 5)
{
STUDENT c = s[i];
s[i] = s[i + 1];
s[i + 1] = c;
b = false;
}
}
} while (b != true);
for (int i = 0; i < n; i++)
{
cout << "FIO:" << s[i].f.fam << " " << s[i].f.name << " " << s[i].f.otchestvo << endl;
cout << "Object and Grade: " << endl;
for (int j = 0; j < 5; j++) {
cout << s[i].M[j].object << ":" << s[i].M[j].grade << endl;
}
}
cout << endl;
/*№7*/
cout << " [Задание №7]" << endl << "[Вывод на экран фамилий студентов, которым уже исполнилось 18 лет]" << endl;
b = false;
for (int i = 0; i < n; i++) {
if (2018 - s[i].b.year >= 18) {
cout << s[i].f.fam << endl;
b = true;
}
if (b != true)
cout << "There is not" << endl;
cout << endl;
}
/*№8*/
cout << " [Задание №8]" << endl << "[Вывод на экран фамилий студентов, родившихся в заданном месяце]" << endl;
b = true;
int w; cout << "Enter mounth: "; cin >> w;
if (w > 0 && w < 13)
{
for (int i = 0; i <= n; i++)
{
if (s[i].b.mounth == w)
{
cout << s[i].f.fam;
if (w == 2) { cout << " Родился во "; }
if (w == 1) { cout << " Родился в "; }
if (w == 3) { cout << " Родился в "; }
if (w > 3) { cout << " Родился в "; }
if (w <= 2) { cout << "-ом месяце"; }
if (w == 3) { cout << "-ем месяце"; }
if (w > 3 && w <= 12) { cout << "-ом месяце"; }
b = true;
}
if (w > 12)
{
b = false;
}
}
if (b == false)
{
cout << "Таких нет" << endl;
}
}
else
{
cout << w << " - Не существует" << endl;
}
cout << endl;
/*№9*/
cout << " [Задание №9]" << endl << "[Вывод на экран фамилий студентов, родившихся в один день]" << endl;
b = false;
for (int i = 0; i < n; i++) {
if (s[i].b.day == s[i + 1].b.day)
{
cout << s[i].f.fam << "," << s[i + 1].f.fam << endl;
b = true;
}
}
if (b != true)
cout << "There is not" << endl;
cout << endl;
/*№10*/
cout << " [Задание №10]" << endl << "[Вывод на экран фамилий студентов, живущих в одном доме]" << endl;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (strcmp(s[i].a.house, s[i].a.house) == 0 && strcmp(s[i].a.street, s[i].a.street) == 0 && i != j) {
cout << s[i].f.fam << "," << s[i + 1].f.fam << endl;
b = true;
}
}
}
if (b != true)
cout << "No one" << endl;
cout << endl;
/*№11*/
cout << " [Задание №11]" << endl << "[Вывод на экран фамилий студентов, которые учатся в группе с номером, введенным с клавиатуры]" << endl;
char group1[100];
cout << "Enter group: "; cin >> group1;
for (int i = 0; i < n; i++) {
if (strcmp(s[i].group, group1) == 0) {
cout << s[i].f.fam << endl;
b = true;
}
}
if (b != true)
cout << "There is not" << endl;
cout << endl;
/*№12*/
cout << " [Задание №12]" << endl << "[Вывод на экран фамилий студентов, сдавших математику, но не сдавших физику]" << endl;
bool x = false; b = false;
for (int i = 0; i < n; i++)
for (int j = 0; j < 5; j++)
{
if (strcmp(s[i].M[j].object, "Math") == 0 && s[i].M[j].grade > 2)
x = true;
if (strcmp(s[i].M[j].object, "Physics") == 0 && s[i].M[j].grade <= 2 && x)
{
cout << s[i].f.fam << endl;
b = true;
}
}
if (b != true)
cout << "There is not" << endl;
cout << endl;
/*№13*/
cout << " [Задание №13]" << endl << "[Вывод на экран фамилий студентов, имеющих хотя бы одну 2]" << endl;
b = false;
for (int i = 0; i < n; i++)
{
x = false;
for (int j = 0; j < 5; j++)
if (s[i].M[j].grade == 2)
x = true;
if (x)
{
cout << s[i].f.fam << endl;
b = true;
}
}
if (b != true)
cout << "There is not" << endl;
cout << endl;
/*№14*/
cout << " [Задание №14]" << endl << "[Вывод на экран фамилий студентов, у которых средний балл выше 4,75]" << endl;
b = false;
for (int i = 0; i < n; i++)
{
int sr = 0;
for (int j = 0; j < 5; j++)
sr += s[i].M[j].grade;
if (sr / 5 > 4.75)
{
cout << s[i].f.fam << endl;
b = true;
}
}
if (b != true)
cout << "There is not" << endl;
/*№15*/
cout << " [Задание №15]" << endl << "[Вывод на экран фамилий студентов, имеющих хотя бы одну 3 и учащихся на факультете, совпадающего с введённым с клавиатуры]" << endl;
int grade1;
cout << "Enter Grade: "; cin >> grade1;
char facul1;
cout << "Enter Faculty: "; cin >> facul1;
for (int i = 0; i < n; i++) {
if ((s[i].M[2], grade1) == 0 && strchr(s[i].facul, facul1) == 0) {
cout << s[i].f.fam << endl;
b = true;
}
}
if (b != true)
cout << "There is not" << endl;
cout << endl;
system("pause");
} |