#include #include #include #include #include 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;iscores[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;iuniq_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; }