include iostream include conio include string include fstream include

  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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
struct stud{
string name;
int uniq_id;
int scores[4];
stud *next;
stud *prev;
};
class students{
public:
stud *listHead;
stud *listEnd;
int stNum;
students(){
listHead = NULL;
listEnd = NULL;
stNum = 0;
}
~students(){
listDelete();
}
void add(string name, int scores[]){
stud *new_st = new stud();
if(listHead == NULL){
new_st->prev = NULL;
listHead = new_st;
new_st->uniq_id = 1;
}else{
listEnd->next = new_st;
new_st->uniq_id = listEnd->uniq_id + 1;
}
new_st->name = name;
new_st->scores[0] = scores[0];
new_st->scores[1] = scores[1];
new_st->scores[2] = scores[2];
new_st->scores[3] = scores[3];
new_st->next = NULL;
new_st->prev = listEnd;
listEnd = new_st;
stNum++;
}
void find_best(int find_by){
stud *student = listHead;
int best_score = listHead->scores[find_by-1];
string best_student[this->stNum];
if(listHead == NULL){
cout << "ERROR: spisok pystoi" << endl;
}else{
while(student != NULL){
if(student->scores[find_by-1] > best_score){
best_score = student->scores[find_by-1];
}
student = student->next;
}
stud *student = listHead;
int c=0;
while(student != NULL){
if(student->scores[find_by-1] == best_score){
best_student[c] = student->name;
c++;
}
student = student->next;
}
cout << "Samui ly4wui bal -> " << best_score << " y stydentov [";
for(int i=0;i<c;i++){
cout << best_student[i];
if(i!=c-1){
cout << ", ";
}else{
cout << "";
}
}
cout << "]";
}
}
void find_bad(int find_by){
stud *student = listHead;
int bad_score = listHead->scores[find_by-1];
string bad_student[this->stNum];
if(listHead == NULL){
cout << "ERROR: spisok pystoi" << endl;
}else{
while(student != NULL){
if(student->scores[find_by-1] < bad_score){
bad_score = student->scores[find_by-1];
}
student = student->next;
}
stud *student = listHead;
int c=0;
while(student != NULL){
if(student->scores[find_by-1] == bad_score){
bad_student[c] = student->name;
c++;
}
student = student->next;
}
cout << "Samui xydwui bal -> " << bad_score << " y stydentov [";
for(int i=0;i<c;i++){
cout << bad_student[i];
if(i!=c-1){
cout << ", ";
}else{
cout << "";
}
}
cout << "]";
}
}
void print(int unit_print, int unit_num){
stud *student = listHead;
if(listHead == NULL){
cout << "ERROR: spisok pystoi" << endl;
}else{
//cout << "Stydent" << setw(20) << "Pervui modyl`" << setw(20) << "Vtoroi modyl`" << "RGZ/Semestr" << endl;
if(unit_print == 0){
while(student != NULL){
//string student_row = student->uniq_id + ". " + student->name;
cout << setw(3) << student->uniq_id
<< setw(2) << ". "
<< setw(13) << student->name
<< setw(5) << student->scores[0]
<< setw(5) << student->scores[1]
<< setw(5) << student->scores[2]
<< setw(5) << student->scores[3]
<< endl;
student = student->next;
}
}else if(unit_print == 1){
stud *student = listHead;
for(int i=listHead->uniq_id; i!=unit_num;){
student = student->next;
i=student->uniq_id ;
}
cout << setw(3) << student->uniq_id
<< setw(2) << ". "
<< setw(13) << student->name
<< setw(5) << student->scores[0]
<< setw(5) << student->scores[1]
<< setw(5) << student->scores[2]
<< setw(5) << student->scores[3]
<< endl;
}
}
}
void printFindBy(int find_by, int find){
switch(find_by){
case 1:{
if(find == 1){
cout << "Lychwui stydent po pervomy modylu:" << endl;
}else if(find == 0){
cout << "Xydwui stydent po pervomy modylu:" << endl;
}
break;
}
case 2:{
if(find == 1){
cout << "Lychwui stydent po vtoromy modylu:" << endl;
}else if(find == 0){
cout << "Xydwui stydent po vtoromy modylu:" << endl;
}
break;
}
case 3:{
if(find == 1){
cout << "Lychwui stydent po ocenke za RGZ:" << endl;
}else if(find == 0){
cout << "Xydwui stydent po ocenke za RGZ:" << endl;
}
break;
}
case 4:{
if(find == 1){
cout << "Lychwui stydent po ocenke za semestr:" << endl;
}else if(find == 0){
cout << "Xydwui stydent po ocenke za semestr:" << endl;
}
break;
}
}
}
void listDelete(){
stud *student = listHead;
while(student != NULL){
student = student->next;
delete student;
}
listHead = NULL;
listEnd = NULL;
stNum = 0;
}
void set_score(int student_id, int score, int where_in){
stud *student = listHead;
for(int i=listHead->uniq_id; i!=student_id;){
student = student->next;
i=student->uniq_id ;
}
student->scores[where_in-1] = score;
}
void studentDelete(int num){
stud *student = listHead;
if((stNum == 1 and num == listHead->uniq_id) or (stNum == 1 and num == listEnd->uniq_id)){
stud *student = listHead;
delete student;
listHead = NULL;
listEnd = NULL;
stNum = 0;
}else{
for(int i=listHead->uniq_id; i!=num;){
student = student->next;
i=student->uniq_id ;
}
if(student->prev == NULL){
student->next->prev = NULL;
listHead = student->next;
delete student;
stNum--;
}
if(student->next == NULL){
student->prev->next = NULL;
listEnd = student->prev;
delete student;
stNum--;
}
if(student->prev != NULL && student->next != NULL){
student->prev->next = student->next;
student->next->prev = student->prev;
delete student;
stNum--;
}
}
}
bool find_student(int num){
stud *student = listHead;
bool check;
if(num<=listEnd->uniq_id){
for(int i=listHead->uniq_id; i<=num;){
if(student->uniq_id == num){
return true;
}else{
student = student->next;
i=student->uniq_id ;
}
}
}
return false;
}
void writeToFile(int unit_write, int unit_num){
stud *student = listHead;
ofstream file_in("journal.txt");
ofstream unit_file_in("unit_journal.txt");
if(listHead == NULL){
cout << "ERROR: spisok pystoi" << endl;
}else{
if(unit_write == 0){
while(student != NULL){
file_in << setw(3) << student->uniq_id
<< setw(2) << ". "
<< setw(13) << student->name
<< setw(5) << student->scores[0]
<< setw(5) << student->scores[1]
<< setw(5) << student->scores[2]
<< setw(5) << student->scores[3]
<< endl;
student = student->next;
}
}else if(unit_write == 1){
stud *student = listHead;
for(int i=listHead->uniq_id; i!=unit_num;){
student = student->next;
i=student->uniq_id ;
}
unit_file_in << setw(3) << student->uniq_id
<< setw(2) << ". "
<< setw(13) << student->name
<< setw(5) << student->scores[0]
<< setw(5) << student->scores[1]
<< setw(5) << student->scores[2]
<< setw(5) << student->scores[3]
<< endl;
}
}
}
};
int main() {
restart:
string st_add;
bool stop_add = false;
int action, num, where_in, find_by, new_score, scores[4];//0-ìîäóëü1; 1-ìîäóëü2; 2-ðãç; 3-ñåìåñòð;
students *student = new students();
cout << "Vvedite familii:" << endl;
cout << "Dlya prekraweniya dobavleniya elementov napechataite \"stop\"" << endl << endl;
while(stop_add == false){
cout << "Dobavit` studenta: "; cin >> st_add;
if(st_add != "stop"){
cout << "-Ocenka za pervui modyl`: "; cin >> scores[0];
cout << "-Ocenka za vtoroi modyl`: "; cin >> scores[1];
cout << "-Ocenka za RGZ: "; cin >> scores[2];
cout << "-Ocenka za semestr: "; cin >> scores[3];
cout << endl;
student->add(st_add, scores);
}else{
stop_add = true;
}
}
if(stop_add == true){
cout << endl << "==========================" << endl << endl;
choice:
cout << "Viberite deystvie: " << endl;
cout << "1 - Naiti lychwego stydenta" << endl;
cout << "2 - Naiti xydshego stydenta" << endl;
cout << "3 - Dobavit' studenta v jurnal" << endl;
cout << "4 - Nazna4it' studenty ocenky" << endl;
cout << "5 - Nauti koli4estvo studentov" << endl;
cout << "6 - Pokazat` jurnal" << endl;
cout << "7 - Pokazat` dannue odnogo stydenta" << endl;
cout << "8 - Ydalit' jurnal" << endl;
cout << "9 - Ydalit' odnogo studenta iz jurnala" << endl;
cout << "10 - Novui jurnal" << endl;
cout << "11 - Soxranit' jurnal v fail" << endl;
cout << "12 - Soxranit' v fail dannue odnogo stydenta" << endl;
cout << "0 - Exit" << endl;
cout << endl << "deystvie #"; cin >> action;
while(action !=0){
switch(action){
case 1:{
cout << "1. Lychwui za pervui modyl`;" << endl;
cout << "2. Lychwui za vtoroi modyl`;" << endl;
cout << "3. Lychwui po ocenke za RGZ; " << endl;
cout << "4. Lychwui za semestr;" << endl;
cin >> find_by;
student->printFindBy(find_by, 1);
student->find_best(find_by);
break;
}
case 2:{
cout << "1. Xydwui za pervui modyl`;" << endl;
cout << "2. Xydwui za vtoroi modyl`;" << endl;
cout << "3. Xydwui po ocenke za RGZ; " << endl;
cout << "4. Xydwui za semestr;" << endl;
cin >> find_by;
student->printFindBy(find_by, 0);
student->find_bad(find_by);
break;
}
case 3:{
cout << "Dobavit` studenta: "; cin >> st_add;
cout << "-Ocenka za pervui modyl`: "; cin >> scores[0];
cout << "-Ocenka za vtoroi modyl`: "; cin >> scores[1];
cout << "-Ocenka za RGZ: "; cin >> scores[2];
cout << "-Ocenka za semestr: "; cin >> scores[3];
student->add(st_add, scores);
cout << endl;
cout << "Obnovlennui spisok: "; cout << endl; student->print(0, 0);
break;
}
case 4:{
cout << "Ykajite nomer stydenta: "; cin >> num;
bool in_list = student->find_student(num);
if(in_list == false){
cout << "Stydent ne naiden!" << endl;
}else{
cout << "Kakyu ocenky vu xotite nazna4it'? :" << endl;
cout << "1. Ocenka za pervui modyl`;" << endl;
cout << "2. Ocenka za vtoroi modyl`;" << endl;
cout << "3. Ocenka za RGZ; " << endl;
cout << "4. Ocenka za semestr;" << endl;
cin >> where_in;
cout << "Ykajite ocenky: "; cin >> new_score;
student->set_score(num, new_score, where_in);
cout << "Obnovlennui spisok: "; cout << endl; student->print(0, 0);
}
break;
}
case 5:{
cout << "Koli4estvo stydentov v jyrnale: " << student->stNum;
break;
}
case 6:{
student->print(0, 0);
break;
}
case 7:{
cout << "Ykajite nomer stydenta: "; cin >> num;
bool in_list = student->find_student(num);
if(in_list == false){
cout << "Stydent ne naiden!" << endl;
}else{
student->print(1, num);
}
break;
}
case 8:{
student->listDelete();
cout << "Spisok yspeshno ydalen!";
cout << endl << endl << "==========================" << endl << endl;
goto restart;
break;
}
case 9:{
cout << "Ykajite nomer stydenta dlya ydaleniya: ";cin >> num;
bool in_list = student->find_student(num);
if(in_list == false){
cout << "Stydent ne naiden!" << endl;
}else{
student->studentDelete(num);
cout << "Stydent #" << num << " yspeshno ydalen iz jyrnala!";
if(student->stNum > 0){
cout << endl << "Novui spisok: " << endl; student->print(0, 0);
}else if(student->stNum == 0){
cout << endl << endl << "Jyrnal bul polnostui ochishen!" << endl <<"==========================" << endl << endl;
goto restart;
}
}
break;
}
case 10:{ student->listDelete(); goto restart; break; }
case 11:{
student->writeToFile(0, 0);
cout << "Zapis' v fail yspewno proizvedena!";
break;
}
case 12:{
cout << "Ykajite nomer stydenta: "; cin >> num;
bool in_list = student->find_student(num);
if(in_list == false){
cout << "Stydent ne naiden!" << endl;
}else{
student->writeToFile(1, num);
cout << "Zapis' v fail yspewno proizvedena!";
}
break;
}
default:{
cout << "Takogo varianta ne sywestvyet! Vuberite sna4ala" << endl << endl;
goto choice;
}
}
cout << endl << endl << "==========================" << endl << endl;
cout << "Viberite deystvie: " << endl;
cout << "1 - Naiti lychwego stydenta" << endl;
cout << "2 - Naiti xydshego stydenta" << endl;
cout << "3 - Dobavit' studenta v jurnal" << endl;
cout << "4 - Nazna4it' studenty ocenky" << endl;
cout << "5 - Nauti koli4estvo studentov" << endl;
cout << "6 - Pokazat` jurnal" << endl;
cout << "7 - Pokazat` dannue odnogo stydenta" << endl;
cout << "8 - Ydalit' jurnal" << endl;
cout << "9 - Ydalit' odnogo studenta iz jurnala" << endl;
cout << "10 - Novui jurnal" << endl;
cout << "11 - Soxranit' jurnal v fail" << endl;
cout << "12 - Soxranit' v fail dannue odnogo stydenta" << endl;
cout << "0 - Exit" << endl;
cout << endl << "deystvie #"; cin >> action;
}
}
delete student;
getch();
return 0;
}