Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- using namespace std;
- //enum type { state, contractor };
- struct Student
- {
- string Name;
- bool Type;
- float Scholarship;
- int Marks[5];
- Student* StudentNext;
- };
- struct Group
- {
- string NumOfGroup;
- int Quantity;
- Student* StudentTop;
- Group* GroupNext;
- } *List = NULL;
- struct Queue
- {
- Student* QueInfo;
- Queue* QueNext;
- } *Root = NULL;
- void MainPage();
- void Menu();
- void Choose();
- Group *ConsoleInput();
- Group *FileInput();
- void GroupAdd();
- void GroupEdit();
- void GroupDelete();
- void ChangeGroupName();
- void StudentAdd();
- void StudentEdit();
- void StudentDelete();
- void FirstPersonalTask();
- void SecondPersonalTask();
- void ConsoleOutput();
- void FileOutput();
- void Que();
- void Sort();
- void Swap(Queue *Obj1, Queue *Obj2);
- int main()
- {
- MainPage();
- return 0;
- }
- void MainPage()
- {
- while(1)
- {
- Menu();
- Choose();
- }
- }
- void Menu()
- {
- cout << "==========CourseWork==========\n";
- cout << "Press 1 for Console input.\n";
- cout << "Press 2 for File input.\n";
- cout << "Press 3 for edit a group.\n";
- cout << "Press 4 for output in lexicographical order of all contractors who have twos on exams.\n";
- cout << "Press 5 for output number of group then average mark on group ";
- cout << "and last quantity of contractor in this group.\n";
- cout << "Press 6 for console output.\n";
- cout << "Press 7 for file output.\n";
- cout << "Press 0 for exit.\n";
- cout << "Enter your choice: ";
- }
- void Choose()
- {
- int choice;
- cin >> choice;
- switch(choice)
- {
- case 1:
- {
- List = ConsoleInput();
- break;
- }
- case 2:
- {
- List = FileInput();
- break;
- }
- case 3:
- {
- GroupEdit();
- break;
- }
- case 4:
- {
- FirstPersonalTask();
- break;
- }
- case 5:
- {
- SecondPersonalTask();
- break;
- }
- case 6:
- {
- ConsoleOutput();
- break;
- }
- case 7:
- {
- FileOutput();
- break;
- }
- case 0:
- {
- exit(EXIT_SUCCESS);
- }
- default:
- {
- cout << "Wrong key.\n";
- MainPage();
- }
- }
- }
- Group *ConsoleInput()
- {
- string str;
- Group *GroupTop = List, *GroupBack = List;
- Group *GroupCreate = NULL;
- Student *StudentRoot = NULL, *StudentCreate = NULL, *StudentBack = NULL;
- while(1)
- {
- cout << "Enter the group number:\n";
- cout << "Enter exit for quit.\n";
- cin >> str;
- if(str.compare("exit"))
- {
- GroupCreate = new Group;
- GroupCreate->NumOfGroup = str;
- GroupCreate->Quantity = 0;
- GroupCreate->StudentTop = NULL;
- GroupCreate->GroupNext = NULL;
- StudentRoot = GroupCreate->StudentTop;
- if(!GroupTop)
- {
- GroupTop = GroupCreate;
- GroupBack = GroupCreate;
- }
- else
- {
- while(GroupBack->GroupNext) GroupBack = GroupBack->GroupNext;
- GroupBack->GroupNext = GroupCreate;
- GroupBack = GroupCreate;
- }
- while (1)
- {
- cout << "Enter NextGroup for add new group.\n";
- cout << "Enter exit for quit.\n";
- cout << "Enter the student name:\n";
- cin >> str;
- if(!str.compare("exit)"))
- return GroupTop;
- if(str.compare("NextGroup"))
- {
- GroupCreate->Quantity++;
- StudentCreate = new Student;
- StudentCreate->Name = str;
- cout << "Enter his marks: ";
- for(int i = 0; i < 5; i++) cin >> StudentCreate->Marks[i];
- cout << "Enter his scholarship";
- cin >> StudentCreate->Scholarship;
- cout << "Enter his type:\n";
- cout << "0 - statement, 1 - contractor.\n";
- cin >> StudentCreate->Type;
- if(!StudentRoot)
- {
- StudentRoot = StudentCreate;
- StudentBack = StudentCreate;
- }
- else
- {
- StudentBack->StudentNext = StudentCreate;
- StudentBack = StudentCreate;
- }
- }
- else
- {
- StudentBack->StudentNext = NULL;
- break;
- }
- }
- }
- else
- {
- GroupBack->GroupNext = NULL;
- break;
- }
- }
- return GroupTop;
- }
- Group *FileInput()
- {
- char buff[30];
- cin >> buff;
- ifstream fin(buff);
- string str;
- Group *GroupTop = List, *GroupCreate = NULL, *GroupBack = NULL;
- Student *StudentRoot = NULL, *StudentCreate = NULL, *StudentBack = NULL;
- while(1)
- {
- cout << "Enter:\n";
- cout << "Group number(exit for leave)";
- cout << "Student name(NextGroup for add new group).\n";
- cout << "His marks.\n";
- cout << "His scholarship.\n";
- cout << "His status(0 - statement, 1 - contractor).\n";
- cin >> str;
- if(str.compare("exit"))
- {
- GroupCreate = new Group;
- GroupCreate->NumOfGroup = str;
- GroupCreate->Quantity = 0;
- GroupCreate->StudentTop = NULL;
- GroupCreate->GroupNext = NULL;
- StudentRoot = GroupCreate->StudentTop;
- if(!GroupTop)
- {
- GroupTop = GroupCreate;
- GroupBack = GroupCreate;
- }
- else
- {
- GroupBack->GroupNext = GroupCreate;
- GroupBack = GroupCreate;
- }
- while (1)
- {
- fin >> str;
- if(!str.compare("exit"))
- break;
- if(str.compare("NextGroup"))
- {
- GroupCreate->Quantity++;
- StudentCreate = new Student;
- StudentCreate->Name = str;
- for(int i = 0; i < 5; i++) fin >> StudentCreate->Marks[i];
- fin >> StudentCreate->Scholarship;
- fin >> StudentCreate->Type;
- if(!StudentRoot)
- {
- StudentRoot = StudentCreate;
- StudentBack = StudentCreate;
- }
- else
- {
- StudentBack->StudentNext = StudentCreate;
- StudentBack = StudentCreate;
- }
- }
- else
- {
- StudentBack->StudentNext = NULL;
- break;
- }
- }
- }
- else
- {
- GroupBack->GroupNext = NULL;
- break;
- }
- }
- fin.close();
- return GroupTop;
- }
- void GroupEdit()
- {
- cout << "Press 1 for change group name.\n";
- cout << "Press 2 for add group.\n";
- cout << "Press 3 for delete group.\n";
- cout << "Press 4 for student add.\n";
- cout << "Press 5 for student edit.\n";
- cout << "Press 6 for student delete.\n";
- cout << "Press 0 for back";
- int choice;
- cin >> choice;
- switch(choice)
- {
- case 1:
- {
- ChangeGroupName();
- break;
- }
- case 2:
- {
- GroupAdd();
- break;
- }
- case 3:
- {
- GroupDelete();
- break;
- }
- case 4:
- {
- StudentAdd();
- break;
- }
- case 5:
- {
- StudentEdit();
- break;
- }
- case 6:
- {
- StudentDelete();
- break;
- }
- case 0:
- {
- return;
- }
- }
- }
- void ChangeGroupName()
- {
- string NewGroupName, OldGroupName;
- cout << "Enter old group name: ";
- cin >> OldGroupName;
- cout << "Enter new group name: ";
- cin >> NewGroupName;
- Group *GroupTop, *GroupCurrent;
- GroupCurrent = GroupTop = List;
- if(!GroupTop)
- {
- cout << "This group wasn't created.\n";
- return;
- }
- else
- {
- while(GroupCurrent->GroupNext)
- {
- if(GroupCurrent->NumOfGroup == OldGroupName)
- {
- GroupCurrent->NumOfGroup = NewGroupName;
- }
- GroupCurrent = GroupCurrent->GroupNext;
- }
- }
- }
- void GroupAdd()
- {
- Group *GroupTop, *GroupCreate, *GroupCurrent;
- GroupCurrent = GroupTop = List;
- Student *StudentCreate, *StudentBack;
- string str;
- GroupCreate = new Group;
- cout << "Enter the group number: ";
- cin >> GroupCreate->NumOfGroup;
- GroupCreate->Quantity = 0;
- GroupCreate->StudentTop = NULL;
- GroupCreate->GroupNext = NULL;
- StudentCreate = StudentBack = GroupCreate->StudentTop;
- if(!GroupTop)
- {
- GroupTop = GroupCreate;
- }
- else
- {
- while(GroupCurrent->GroupNext)
- {
- GroupCurrent = GroupCurrent->GroupNext;
- }
- GroupCurrent->GroupNext = GroupCreate;
- }
- while (1)
- {
- cout << "Enter exit for quit.\n";
- cout << "Enter the student name:\n";
- cin >> str;
- if (str.compare("Stop"))
- {
- GroupCreate->Quantity++;
- StudentCreate = new Student;
- StudentCreate->Name = str;
- cout << "Enter his marks: ";
- for(int i = 0; i < 5; i++) cin >> StudentCreate->Marks[i];
- cout << "Enter his scholarship: ";
- cin >> StudentCreate->Scholarship;
- cout << "Enter his status: ";
- cin >> StudentCreate->Type;
- if(!GroupCreate->StudentTop)
- {
- GroupCreate->StudentTop = StudentCreate;
- StudentBack = StudentCreate;
- }
- else
- {
- StudentBack->StudentNext = StudentCreate;
- StudentBack = StudentCreate;
- }
- }
- else
- {
- StudentBack->StudentNext = NULL;
- break;
- }
- }
- }
- void GroupDelete()
- {
- string _NumOfGroup;
- cout << "Enter the group number: ";
- cin >> _NumOfGroup;
- Student *StudCurrent, *StudParent;
- Group *GroupCurrent, *GroupParent;
- GroupCurrent = List;
- while (GroupCurrent)
- {
- GroupParent = GroupCurrent;
- if (GroupCurrent->NumOfGroup == _NumOfGroup)
- {
- StudParent = StudCurrent = GroupCurrent->StudentTop;
- while (StudCurrent)
- {
- StudCurrent = StudCurrent->StudentNext;
- delete StudParent;
- StudParent = StudCurrent;
- }
- if(GroupCurrent == List)
- {
- GroupCurrent = GroupCurrent->GroupNext;
- delete List;
- List = GroupCurrent;
- break;
- }
- else
- {
- GroupParent->GroupNext = GroupCurrent->GroupNext;
- delete GroupCurrent;
- GroupCurrent = GroupParent->GroupNext;
- break;
- }
- }
- GroupCurrent = GroupCurrent->GroupNext;
- }
- }
- void StudentAdd()
- {
- string _NumOfGroup;
- cout << "Enter the group number: ";
- cin >> _NumOfGroup;
- Group *GroupCurrent = List;
- Student *StudentCurrent = NULL, *StudentParent = NULL, *StudentCreate = NULL;
- while(GroupCurrent)
- {
- if(GroupCurrent->NumOfGroup == _NumOfGroup)
- {
- StudentCreate = new Student;
- cout << "Enter the studet name: ";
- cin >> StudentCreate->Name;
- cout << "Enter his status: ";
- cin >> StudentCreate->Type;
- cout << "Enter his scholarship: ";
- cin >> StudentCreate->Scholarship;
- cout << "Enter his marks: ";
- for(int i = 0; i < 5; i++) cin >> StudentCreate->Marks[i];
- StudentCreate->StudentNext = NULL;
- StudentCurrent = GroupCurrent->StudentTop;
- while(StudentCurrent)
- {
- StudentParent = StudentCurrent;
- StudentCurrent = StudentCurrent->StudentNext;
- }
- StudentParent->StudentNext = StudentCreate;
- GroupCurrent->Quantity++;
- }
- }
- }
- void StudentEdit()
- {
- string _NumOfGroup, _Name;
- cout << "Enter the group number: ";
- cin >> _NumOfGroup;
- cout << "Enter the student name: ";
- cin >> _Name;
- Group *GroupCurrent = List;
- Student *StudentCurrent;
- while(GroupCurrent)
- {
- if(GroupCurrent->NumOfGroup == _NumOfGroup)
- {
- while(StudentCurrent)
- {
- if(StudentCurrent->Name == _Name)
- {
- cout << "Enter his status: ";
- cin >> StudentCurrent->Type;
- cout << "Enter his scholarship: ";
- cin >> StudentCurrent->Scholarship;
- cout << "Enter his marks: ";
- for(int i = 0; i < 5; i++) cin >> StudentCurrent->Marks[i];
- }
- StudentCurrent = StudentCurrent->StudentNext;
- }
- }
- GroupCurrent = GroupCurrent->GroupNext;
- }
- }
- void StudentDelete()
- {
- string _NumOfGroup, _Name;
- cout << "Enter the group number: ";
- cin >> _NumOfGroup;
- cout << "Enter the student name: ";
- cin >> _Name;
- Group *GroupCurrent = List;
- Student *StudentCurrent, *StudentParent;
- while(GroupCurrent)
- {
- if(GroupCurrent->NumOfGroup == _NumOfGroup)
- {
- StudentCurrent = GroupCurrent->StudentTop;
- while(StudentCurrent)
- {
- StudentParent = StudentCurrent;
- if(StudentCurrent->Name == _Name)
- {
- StudentParent->StudentNext = StudentCurrent->StudentNext;
- delete StudentCurrent;
- StudentCurrent = StudentParent->StudentNext;
- }
- StudentCurrent = StudentCurrent->StudentNext;
- }
- }
- GroupCurrent = GroupCurrent->GroupNext;
- }
- }
- void FirstPersonalTask()
- {
- if(!Root) Que();
- Queue *QueCurrent = Root;
- while(QueCurrent)
- {
- cout << QueCurrent->QueInfo->Name << ' ';
- switch(QueCurrent->QueInfo->Type)
- {
- case 0://this situation can't be
- {
- cout << " State ";
- break;
- }
- case 1:
- {
- cout << " Contractor ";
- break;
- }
- }
- cout << QueCurrent->QueInfo->Scholarship << ' ';
- for(int i = 0; i < 5; i++)
- {
- cout << QueCurrent->QueInfo->Marks[i] << ' ';
- }
- cout << '\n';
- QueCurrent = QueCurrent->QueNext;
- }
- }
- void Que()
- {
- Queue *Create, *QueCurrent;
- Create = new Queue;
- Group *GroupCurrent = NULL;
- Student *StudentCurrent = NULL;
- QueCurrent = Root = Create;
- GroupCurrent = List;
- while(GroupCurrent->GroupNext)
- {
- StudentCurrent = GroupCurrent->StudentTop;
- while(StudentCurrent->StudentNext)
- {
- if(StudentCurrent->Type)
- {
- for(int i = 0; i < 5; i++)
- {
- if(StudentCurrent->Marks[i] == 2)
- {
- Create->QueInfo = StudentCurrent;
- Create->QueNext = NULL;
- while(QueCurrent->QueNext)
- {
- QueCurrent = QueCurrent->QueNext;
- }
- QueCurrent->QueNext = Create;
- break;
- }
- }
- }
- Create = new Queue;
- StudentCurrent = StudentCurrent->StudentNext;
- }
- GroupCurrent = GroupCurrent->GroupNext;
- }
- Sort();
- }
- void Sort()
- {
- Queue *QueCurrent, *QueSwap, *QueMinimum;
- QueCurrent = QueSwap = QueMinimum = Root;
- while(QueSwap->QueNext)
- {
- while(QueCurrent)
- {
- if(QueCurrent->QueNext->QueInfo->Name < QueMinimum->QueInfo->Name)
- {
- QueMinimum = QueCurrent;
- }
- }
- Swap(QueMinimum, QueSwap);
- QueSwap = QueSwap->QueNext;
- }
- }
- void Swap(Queue *Obj1, Queue *Obj2)
- {
- Queue *Temp = new Queue;
- Temp->QueInfo->Name = Obj1->QueInfo->Name;
- Obj1->QueInfo->Name = Obj2->QueInfo->Name;
- Obj2->QueInfo->Name = Temp->QueInfo->Name;
- Temp->QueInfo->Scholarship = Obj1->QueInfo->Scholarship;
- Obj1->QueInfo->Scholarship = Obj2->QueInfo->Scholarship;
- Obj2->QueInfo->Scholarship = Temp->QueInfo->Scholarship;
- Temp->QueInfo->Type = Obj1->QueInfo->Type;
- Obj1->QueInfo->Type = Obj2->QueInfo->Type;
- Obj2->QueInfo->Type = Temp->QueInfo->Type;
- for(int i = 0; i < 5; i++)
- {
- Temp->QueInfo->Marks[i] = Obj1->QueInfo->Marks[i];
- Obj1->QueInfo->Marks[i] = Obj2->QueInfo->Marks[i];
- Obj2->QueInfo->Marks[i] = Temp->QueInfo->Marks[i];
- }
- delete Temp;
- }
- void SecondPersonalTask()
- {
- Group *GroupCurrent;
- Student *StudentCurrent;
- GroupCurrent = List;
- int AverageMark = 0;
- int QuantityContractor = 0;
- while(GroupCurrent)
- {
- StudentCurrent = GroupCurrent->StudentTop;
- cout << GroupCurrent->NumOfGroup << '\t';
- while(StudentCurrent)
- {
- for(int i = 0; i < 5; i++)
- {
- AverageMark += StudentCurrent->Marks[i];
- }
- if(StudentCurrent->Type)
- {
- QuantityContractor++;
- }
- StudentCurrent = StudentCurrent->StudentNext;
- }
- cout << " Average Mark " << AverageMark << '\t';
- cout << " Quantity of contactor " << QuantityContractor << '\n';
- AverageMark = 0;
- QuantityContractor = 0;
- GroupCurrent = GroupCurrent->GroupNext;
- }
- }
- void ConsoleOutput()
- {
- Group *GroupCurrent;
- Student *StudentCurrent;
- GroupCurrent = List;
- while(GroupCurrent)
- {
- StudentCurrent = GroupCurrent->StudentTop;
- cout << GroupCurrent->NumOfGroup << '\n';
- while(StudentCurrent)
- {
- cout << StudentCurrent->Name << ' ';
- cout << StudentCurrent->Type << ' ';
- cout << StudentCurrent->Scholarship << ' ';
- for(int i = 0; i < 5; i++)
- {
- cout << StudentCurrent->Marks[i] << ' ';
- }
- cout << '\n';
- StudentCurrent = StudentCurrent->StudentNext;
- }
- GroupCurrent = GroupCurrent->GroupNext;
- }
- }
- void FileOutput()
- {
- char buff[30];
- cin >> buff;
- ofstream fout(buff);
- Group *GroupCurrent;
- Student *StudentCurrent;
- GroupCurrent = List;
- while(GroupCurrent)
- {
- StudentCurrent = GroupCurrent->StudentTop;
- fout << GroupCurrent->NumOfGroup << '\n';
- while(StudentCurrent)
- {
- fout << StudentCurrent->Name << ' ';
- fout << StudentCurrent->Type << ' ';
- fout << StudentCurrent->Scholarship << ' ';
- for(int i = 0; i < 5; i++)
- {
- fout << StudentCurrent->Marks[i] << ' ';
- }
- fout << '\n';
- StudentCurrent = StudentCurrent->StudentNext;
- }
- GroupCurrent = GroupCurrent->GroupNext;
- }
- fout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement