Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //курсовая работа Вариант 13 Щеглов В.А. 19ВИ1
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <set>
- using namespace std;
- struct ege
- {
- string fam;
- string name;
- string otch;
- string sch;
- int phis=0;
- int math=0;
- int inf=0;
- ege* next;
- ege* prev;
- };
- void peren(ege* start){
- ifstream fil("курсач.txt");
- string n;
- fil>>n;
- fil.close();
- ifstream file("курсач.txt");
- if(n!=""){
- ege *sp,*prev;
- string phis,math,inf;
- file>>start->fam;
- file>>start->name;
- file>>start->otch;
- file>>start->sch;
- file>>phis;
- file>>math;
- file>>inf;
- start->phis=stoi(phis);
- start->math=stoi(math);
- start->inf=stoi(inf);
- sp=start;
- while(!(file.eof())){
- ege *node=new ege;
- sp->next=node;
- prev=sp;
- sp=sp->next;
- sp->prev=prev;
- file>>sp->fam;
- file>>sp->name;
- file>>sp->otch;
- file>>sp->sch;
- file>>phis;
- file>>math;
- file>>inf;
- sp->phis=stoi(phis);
- sp->math=stoi(math);
- sp->inf=stoi(inf);
- }
- file.close();
- sp->next=NULL;
- }
- }
- void pokaz(ege *start){
- ege *sp;
- if(start->fam!=""){
- sp=start;
- while(sp!=NULL){
- cout<<endl<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
- sp=sp->next;
- }
- }else cout<<"Документ пуст";
- }
- void dob_elem(ege* start){
- ege *sp,*prev;
- cout<<"Сколько хотите добавить элементов?";
- int c;
- cin>>c;
- ofstream fi ("курсач.txt", ios::app);
- if(start->fam==""){
- cout<<"Фамилия сдавшего ЕГЭ: ";
- cin>>start->fam;
- cout<<"Имя сдавшего ЕГЭ: ";
- cin>>start->name;
- cout<<"Отчество сдавшего ЕГЭ: ";
- cin>>start->otch;
- cout<<"Школа сдавшего ЕГЭ: ";
- cin>>start->sch;
- cout<<"Баллы по физике сдавшего ЕГЭ: ";
- cin>>start->phis;
- cout<<"Баллы по математике сдавшего ЕГЭ: ";
- cin>>start->math;
- cout<<"Баллы по информатике сдавшего ЕГЭ: ";
- cin>>start->inf;
- fi<<start->fam<<" "<<start->name<<" "<<start->otch<<" "<<start->sch<<" "<<start->phis<<" "<<start->math<<" "<<start->inf;
- c--;
- start->next=NULL;
- start->prev=NULL;
- }
- sp=start;
- while(!(sp->next==NULL)){
- sp=sp->next;
- }
- for(int i=1;i<=c;i++){
- ege *node=new ege;
- sp->next=node;
- prev=sp;
- sp=sp->next;
- sp->prev=prev;
- sp->next=NULL;
- cout<<"Фамилия сдавшего ЕГЭ: ";
- cin>>sp->fam;
- cout<<"Имя сдавшего ЕГЭ: ";
- cin>>sp->name;
- cout<<"Отчество сдавшего ЕГЭ: ";
- cin>>sp->otch;
- cout<<"Школа сдавшего ЕГЭ: ";
- cin>>sp->sch;
- cout<<"Баллы по физике сдавшего ЕГЭ: ";
- cin>>sp->phis;
- cout<<"Баллы по математике сдавшего ЕГЭ: ";
- cin>>sp->math;
- cout<<"Баллы по информатике сдавшего ЕГЭ: ";
- cin>>sp->inf;
- fi<<endl<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
- }
- fi.close();
- }
- void find(ege *start){
- ege *sp;
- if(start->fam!=""){
- cout<<"По какому параметру хотите произвести поиск(Фамилия, Школа)?";
- string b;
- cin>>b;
- if (b=="Фамилия"){
- cout<<"Данные по ученикам с какой Фамилией вы хотите найти?";
- string c;
- cin>>c;
- sp=start;
- while(sp!=NULL){
- if(sp->fam==c){
- cout << sp->fam << " " << sp->name << " " << sp->otch << " " << sp->sch << " " << sp->phis << " " << sp->math << " " << sp->inf<<endl;
- cout<<"Хотите удалить этот элемент?";
- string d;
- cin>>d;
- if(d=="Да"){
- if(sp->prev==NULL){
- if(sp->next!=NULL){
- sp=sp->next;
- sp->prev=NULL;
- start=sp;
- }else {
- start->fam="";
- start->name="";
- start->otch="";
- start->sch="";
- start->phis=0;
- start->math=0;
- start->inf=0;
- start->next=NULL;
- start->prev=NULL;
- sp=start;
- }
- }else{
- if(sp->next==NULL){
- sp->prev->next=NULL;
- free(sp);
- }else{
- sp->prev->next=sp->next;
- sp->next->prev=sp->prev;
- free(sp);
- }
- }
- }
- }
- sp=sp->next;
- }
- }
- if (b=="Школа"){
- cout<<"Данные по ученикам из какой школы вы хотите найти?";
- string c;
- cin>>c;
- sp=start;
- while(sp!=NULL){
- if(sp->sch==c){
- cout << sp->fam << " " << sp->name << " " << sp->otch << " " << sp->sch << " " << sp->phis << " " << sp->math << " " << sp->inf<<endl;
- cout<<"Хотите удалить этот элемент?";
- string d;
- cin>>d;
- if(d=="Да"){
- if(sp->prev==NULL){
- if(sp->next!=NULL){
- sp=sp->next;
- sp->prev=NULL;
- start=sp;
- }else {
- start->fam="";
- start->name="";
- start->otch="";
- start->sch="";
- start->phis=0;
- start->math=0;
- start->inf=0;
- start->next=NULL;
- start->prev=NULL;
- sp=start;
- }
- }else{
- if(sp->next==NULL){
- sp->prev->next=NULL;
- free(sp);
- }else{
- sp->prev->next=sp->next;
- sp->next->prev=sp->prev;
- free(sp);
- }
- }
- }
- }
- sp=sp->next;
- }
- }
- ofstream f("курсач.txt");
- sp=start;
- if(sp->fam!=""){
- f<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
- sp=sp->next;
- while(sp!=NULL){
- f<<endl<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
- sp=sp->next;
- }
- }
- f.close();
- }else cout<<"Документ Пуст";
- }
- void max_min(ege* start){
- if(start->fam!=""){
- float max=0;
- string max_sc;
- float min=900;
- string min_sc;
- set<string>myset;
- ege *sp,*st;
- sp=start;
- while(sp!=NULL){
- if(!(myset.count(sp->sch))){
- float sum=0;
- float kol=0;
- st=start;
- while(st!=NULL){
- if(sp->sch==st->sch){
- sum+=st->phis+st->math+st->inf;
- kol++;
- }
- st=st->next;
- }
- if ((sum/kol)>max){
- max=sum/kol;
- max_sc=sp->sch;
- }
- if ((sum/kol)<min){
- min=sum/kol;
- min_sc=sp->sch;
- }
- myset.insert(sp->sch);
- }
- sp=sp->next;
- }
- cout<<"Школа с минимальным средним баллом: "<<min_sc<<endl;
- cout<<"Школа с максимальным средним баллом: "<<max_sc<<endl;
- } else cout<<"Данных нет";
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- ege start;
- char r;
- start.prev=NULL;
- peren(&start);
- while(r!='0'){
- cout<<"Меню:"<<endl<<"1)Показать данные"<<endl<<"2)Добавить Элемент"<<endl<<"3)Найти данные по элементу"<<endl<<"4)Определить школы с максимальным средним баллом по ЕГЭ и минимальным"<<endl<<"0)Закрыть"<<endl<<"Выберите действие(0..4) ";
- cin>>r;
- switch(r){
- case '1':
- pokaz(&start);
- cout<<endl;
- break;
- case '2':
- dob_elem(&start);
- break;
- case '3':
- find(&start);
- break;
- case '4':
- max_min(&start);
- }
- }
- }
Add Comment
Please, Sign In to add comment