学校运动会管理系统

来源:互联网 发布:apk格式的java虚拟机 编辑:程序博客网 时间:2024/04/28 03:55
#include<iostream>#include<fstream>#include<string>using namespace std;void fun1(){   cout<<"******************************"<<endl;    cout<<endl; cout<<"******学校运动会管理系统******"<<endl;cout<<"----数据录入       请按:1----"<<endl;cout<<"----数据修改       请按:2----"<<endl;cout<<"----数据删除       请按:3----"<<endl;cout<<"----数据查询       请按:4----"<<endl;cout<<"----数据显示       请按:5----"<<endl;cout<<"----退出系统       请按:6----"<<endl;cout<<endl;cout<<"*******************************"<<endl;cout<<endl;cout<<"*****请输入一个数据,并按回车键!*****"<<endl;}class Match{public:Match  *next;//为创建链表做准备int number;   //比赛项目编号char call[10];   //比赛项目名称char time[10];         //比赛时间char place[20];   //比赛地点  friendvoid input1();};void input1(){   ofstream fout("e:\\比赛项目.dat",ios::app);char ch;Match a;do{ cout<<"请分别输入比赛项目编号、名称、比赛时间、比赛地点."<<endl;  cin>>a.number>>a.call>>a.place>>a.time;  a.next=NULL;      fout.write((char *)&a,sizeof(Match));  cout<<"是否继续输入,如果继续键入Y|y"<<endl;  cin>>ch;}while(ch=='y'||ch=='Y');  fout.close();}Match  *head1;void creat(){  head1=NULL;   Match *p,*q=head1;   ifstream fin("e:\\比赛项目.dat",ios::in);   if(!fin)   {  cout<<"文件打开失败!"<<endl; exit(0);   }     p=new  Match; fin.read((char*)p,sizeof(Match)); while(!fin.eof())  {  if(head1==NULL)  head1=p;    else  q->next=p;q=p;        p=new  Match;       fin.read((char*)p,sizeof(Match)); }    fin.close();}int change1()           //对比赛项目相关信息修改{cout<<"您正在进行修改比赛项目有关事项操作!"<<endl;creat();    Match *p1;    p1=head1;cout<<"请输入要修改比赛项目的编号:"<<endl;int number1;       //要修改的比赛项目编号int sign=0;        //设置的标记变量cin>>number1;while(p1!=NULL){  if(p1->number==number1)   {sign=1;break;}         p1= p1->next;}    if (sign==0)cout<<"没有找到要修改的记录!"<<endl;    else{cout<<"请选择要修改比赛项目的那些信息"<<endl;cout<<"------修改比赛项目的编号----1"<<endl;cout<<"------修改比赛项目的名称----2"<<endl;cout<<"------修改比赛时间----3"<<endl;cout<<"------修改比赛地点----4"<<endl;cout<<"请输入对应信息的编号"<<endl;int a;int nu;            //新的整形数据char info[20];         //新的字符数组cin>>a;switch(a){case 1:cout<<"请输入新的比赛编号:"<<endl;  cin>>nu;  p1->number=nu;    cout<<"比赛项目编号修改成功!"<<endl;             break;        case 2:cout<<"请输入新的比赛项目名称:"<<endl;cin>>info;            strcpy(p1->call,info);cout<<"比赛项目名称修改成功!"<<endl;           break;        case 3:cout<<"请输入新的比赛时间:"<<endl;cin>>info;strcpy(p1->time,info);cout<<"比赛项目时间修改成功!"<<endl;       break;        case 4:cout<<"请输入新的比赛地点:"<<endl;cin>>info;strcpy(p1->place,info);cout<<"比赛项目地点修改成功!"<<endl;   break;}ofstream fout("e:\\比赛项目.dat",ios::out);p1=head1;     while(p1!=NULL){            fout.write((char*)p1,sizeof(Match));  p1=p1->next;}          fout.close();    }return 0;}int delete1()                        //对比赛项目相关信息进行删除{  creat();   Match *p1,*p2;   p2=p1=head1;cout<<"请选择要删除比赛项目的那些信息"<<endl;cout<<"------删除比赛项目的编号----1"<<endl;cout<<"------删除比赛项目的名称----2"<<endl;    cout<<"请输入对应信息的编号"<<endl;        int n;cin>>n;   int num,flag=0;   char cal[10];   switch(n)   {case 1:  cin>>num;             while(p1!=NULL) {  if(p1->number==num)   {flag=1;break;}                p2=p1;            p1= p1->next; }             if (flag==0)            cout<<"没有找到要删除的记录!"<<endl;               else               p2->next=p1->next;case 2:   cin>>cal;             while(p1!=NULL) {  if(!strcmp(p1->call,cal))   {flag=1;break;}                p2=p1;            p1= p1->next; }             if (flag==0)            cout<<"没有找到要删除的记录!"<<endl;               else               p2->next=p1->next;   }    ofstream fout("e:\\比赛项目.dat",ios::out);    p1=head1;while(p1!=NULL){          fout.write((char*)p1,sizeof(Match));p1=p1->next;}   fout.close();return 0;}void print1(){ creat(); Match *p1=head1; cout<<"请分别输出比赛项目编号、名称、比赛时间、比赛地点."<<endl;while(p1!=NULL){  cout<<p1->number<<'\t'<<p1->call<<'\t'<<p1->time<<'\t'<<p1->place<<endl;        p1=p1->next;}   }void find1(){   creat();    Match *p1;    p1=head1;    int sign=0;//设置的标记变量    cout<<"请选择要查询比赛项目的哪些信息"<<endl;cout<<"------按比赛项目的编号查询----1"<<endl;cout<<"------按比赛项目的名称查询----2"<<endl;cout<<"------按比赛时间查询----3"<<endl;cout<<"------按比赛地点查询----4"<<endl;cout<<"请输入对应信息的编号"<<endl;int a;int nu;                     //查询整形数据条件char info[20];              //查询字符型数据条件cin>>a;switch(a){case 1:cout<<"请输入要查询的比赛编号:"<<endl;  cin>>nu;  while(p1!=NULL)  {  if(p1->number==nu)   {sign=1;break;}                 p1= p1->next;  }              if (sign==0)         cout<<"没有找到要查询的记录!"<<endl;  else              cout<<p1->number<<'\t'<<p1->call<<'\t'<<p1->time<<'\t'<<p1->place<<endl;             break;        case 2:cout<<"请输入要查询的比赛项目名称:"<<endl;cin>>info;            while(p1!=NULL)  {  if(p1->call==info)   {sign=1;break;}                 p1= p1->next;  }              if (sign==0)         cout<<"没有找到要查询的记录!"<<endl;  else              cout<<p1->number<<'\t'<<p1->call<<'\t'<<p1->time<<'\t'<<p1->place<<endl;           break;        case 3:cout<<"请输入要查询的比赛时间:"<<endl;cin>>info;while(p1!=NULL)  {  if(!strcmp(p1->time,info))   {sign=1;break;}                 p1= p1->next;  }              if (sign==0)         cout<<"没有找到要查询的记录!"<<endl;  else              cout<<p1->number<<'\t'<<p1->call<<'\t'<<p1->time<<'\t'<<p1->place<<endl;       break;        case 4:cout<<"请输入要查询的比赛地点:"<<endl;cin>>info;while(p1!=NULL)  {  if(!strcmp(p1->place,info))   {sign=1;break;}                 p1= p1->next;  }              if (sign==0)         cout<<"没有找到要查询的记录!"<<endl;  else              cout<<p1->number<<'\t'<<p1->call<<'\t'<<p1->time<<'\t'<<p1->place<<endl;break;}}class Athlete{public:Athlete *next;int number;          //运动员的编号char name[10];       //运动员的姓名    char part[20];       //运动员所属工作单位或省份char sex[20];            //运动员性别int age;             //运动员年龄friend void input2();};void input2(){   ofstream fout("e:\\运动员.dat",ios::app);char ch;Athlete b;do{cout<<"请分别输入运动员编号、姓名、性别、年龄、所属省份或工作单位."<<endl;  cin>>b.number>>b.name>>b.sex>>b.age>>b.part;b.next=NULL;        fout.write((char *)&b,sizeof(Athlete));    cout<<"是否继续输入,如果继续键入Y|y"<<endl;cin>>ch;}while(ch=='y'||ch=='Y');}Athlete  *head4;void creat2(){  head4=NULL;   Athlete *p,*q=head4;ifstream fin("e:\\运动员.dat",ios::in);    if(!fin){cout<<"文件打开失败!"<<endl; exit(0);}  p=new  Athlete; fin.read((char*)p,sizeof(Athlete)); while(!fin.eof())   {  if(head4==NULL)  head4=p;    else    q->next=p;q=p;        p=new  Athlete;       fin.read((char*)p,sizeof(Athlete)); }    fin.close();}int change2()            //对运动员相关信息修改{cout<<"您正在进行修改运动员基本信息操作!"<<endl;creat2();    Athlete *p1;    p1=head4;cout<<"请输入要修改运动员的编号:"<<endl;int number1;       //要修改的运动员编号int sign=0;        //设置的标记变量cin>>number1;while(p1!=NULL){  if(p1->number==number1)   {sign=1;break;}         p1= p1->next;}     if (sign==0) cout<<"没有找到要修改的记录!"<<endl;  else{cout<<"请选择要修改运动员的哪些信息"<<endl;cout<<"------修改运动员的编号----1"<<endl;cout<<"------修改运动员的姓名----2"<<endl;cout<<"------修改运动员所属工作单位或省份----3"<<endl;cout<<"------修改运动员性别----4"<<endl;        cout<<"------修改运动员年龄----4"<<endl;cout<<"请输入对应信息的编号"<<endl;int a;int nu;                //新的整形数据char info[20];         //新的字符数组    cin>>a;switch(a){case 1:cout<<"请输入新的运动员编号:"<<endl;  cin>>nu;  p1->number=nu;    cout<<"运动员的编号修改成功!"<<endl;             break;    case 2:cout<<"请输入新的运动员姓名:"<<endl;cin>>info;            strcpy(p1->name,info);cout<<"运动员姓名修改成功!"<<endl;           break;case 3:cout<<"请输入新的运动员所属工作单位或省份:"<<endl;cin>>info;strcpy(p1->part,info);cout<<"运动员所属工作单位或省份修改成功!"<<endl;       break;case 4:cout<<"请输入新的性别:"<<endl;cin>>info;strcpy(p1->sex,info);cout<<"运动员性别修改成功!"<<endl;   break;case 5:cout<<"请输入新的年龄:"<<endl;cin>>nu;p1->age=nu,cout<<"运动员年龄修改成功!"<<endl;   break;}ofstream fout("e:\\运动员.dat",ios::out);p1=head4;     while(p1!=NULL){            fout.write((char*)p1,sizeof(Athlete));  p1=p1->next;}   fout.close();    }return 0;}int  delete2()//对运动员相关信息进行删除{  creat2();   Athlete *p1,*p2;   p2=p1=head4;cout<<"请选择要删除运动员的哪些信息"<<endl;cout<<"------删除运动员的编号----1"<<endl;cout<<"------删除运动员的姓名----2"<<endl;    cout<<"请输入对应信息的编号"<<endl;        int n;cin>>n;      int num,flag=0;   char na[10];   switch(n)   {case 1:   cin>>num;             while(p1!=NULL) {  if(p1->number==num)   {flag=1;break;}                p2=p1;            p1= p1->next; }             if (flag==0)            cout<<"没有找到要删除的记录!"<<endl;               else               p2->next=p1->next;case 2:   cin>>na;             while(p1!=NULL) {  if(!strcmp(p1->name,na))   {flag=1;break;}                p2=p1;            p1= p1->next; }             if (flag==0)            cout<<"没有找到要删除的记录!"<<endl;               else               p2->next=p1->next;   }    ofstream fout("e:\\运动员.dat",ios::out);    p1=head4;while(p1!=NULL){          fout.write((char*)p1,sizeof(Athlete));p1=p1->next;}   fout.close();return 0;}void find2(){   creat2();    Athlete *p1;    p1=head4;int sign=0;//设置的标记变量    cout<<"请选择要查询运动员的哪些信息"<<endl;cout<<"------按运动员的编号查询----1"<<endl;cout<<"------按运动员的姓名查询----2"<<endl;cout<<"请输入对应信息的编号"<<endl;int a;int nu;                     //查询整形数据条件char info[20];              //查询字符型数据条件cin>>a;switch(a){case 1:cout<<"请输入要查询的运动员编号:"<<endl;  cin>>nu;  while(p1!=NULL)  {  if(p1->number==nu)   {sign=1;break;}                 p1= p1->next;  }              if (sign==0)         cout<<"没有找到要查询的记录!"<<endl;  else    cout<<p1->number<<'\t'<<p1->name<<'\t'<<p1->part<<'\t'<<p1->sex<<'\t'<<p1->age<<endl;             break;case 2:cout<<"请输入要查询的运动员姓名:"<<endl;cin>>info;            while(p1!=NULL)  {  if(p1->name==info)   {sign=1;break;}                 p1= p1->next;  }              if (sign==0)         cout<<"没有找到要查询的记录!"<<endl;  else          cout<<p1->number<<'\t'<<p1->name<<'\t'<<p1->part<<'\t'<<p1->sex<<'\t'<<p1->age<<endl;           break;}}void print2(){     creat2(); Athlete *p1=head4; cout<<"请分别输出运动员编号、姓名、所属省份或工作单位、性别、年龄."<<endl; while(p1!=NULL){  cout<<p1->number<<'\t'<<p1->name<<'\t'<<p1->part<<'\t'<<p1->sex<<'\t'<<p1->age<<endl; p1=p1->next;}   }class Message{public:Message *next;char name[10];       //运动员姓名char avent[10];      //运动员参加的某比赛项目名称int  score ;          //成绩int  ca;              //名次    friend void input3();};void input3(){  ofstream fout("e:\\比赛赛事.dat",ios::app);char ch;Message c;do{cout<<"请分别输入参赛运动员姓名、比赛名称、比赛成绩、比赛名次."<<endl; cin>>c.name>>c.avent>>c.score>>c.ca;c.next=NULL;       fout.write((char *)&c,sizeof(Message));   cout<<"是否继续输入,如果继续键入Y|y"<<endl;   cin>>ch;}while(ch=='y'||ch=='Y');fout.close();}Message  *head7;void creat3(){  head7=NULL;   Message *p,*q=head7;ifstream fin("e:\\比赛赛事.dat",ios::in);    if(!fin){cout<<"文件打开失败!"<<endl; exit(0);}  p=new  Message; fin.read((char*)p,sizeof(Message)); while(!fin.eof())   {  if(head7==NULL)  head7=p;    else    q->next=p;q=p;        p=new  Message;       fin.read((char*)p,sizeof(Message)); }    fin.close();}int change3()    //修改比赛赛事信息{   cout<<"您正在进行修改比赛赛事有关事项操作!"<<endl;creat3();    Message *p1;    p1=head7;cout<<"请输入参赛运动员姓名及参赛项目名称! "<<endl;char na[20];char info[20];int sign=0;//设置的标记变量cin>>na>>info;while(p1!=NULL){  if((p1->name==na)&&(p1->avent==info))   {sign=1;break;}         p1= p1->next;}     if (sign==0) cout<<"没有找到要修改的记录!"<<endl;     else{cout<<"请选择要修改比赛赛事的哪些信息"<<endl;cout<<"------修改参赛运动员的姓名----1"<<endl;cout<<"------修改比赛项目的名称----2"<<endl;cout<<"------修改比赛成绩----3"<<endl;cout<<"------修改比赛名次----4"<<endl;cout<<"请输入对应信息的编号"<<endl;int a;int nu;                //新的整形数据char info[20];         //新的字符数组        cin>>a;switch(a){case 1:cout<<"请输入新的参赛运动员姓名:"<<endl;  cin>>info;  strcpy(p1->name,info);    cout<<"参赛运动员姓名修改成功!"<<endl;             break;case 2:cout<<"请输入新的比赛项目名称:"<<endl;cin>>info;            strcpy(p1->avent,info);    cout<<"比赛项目名称修改成功!"<<endl;           break;case 3:cout<<"请输入新的比赛成绩:"<<endl;cin>>nu;p1->score=nu;cout<<"比赛项目成绩修改成功!"<<endl;       break;case 4:cout<<"请输入新的比赛名次:"<<endl;cin>>nu;p1->ca=nu;cout<<"比赛名次修改成功!"<<endl;   break;}ofstream fout("e:\\比赛赛事.dat",ios::out);p1=head7;     while(p1!=NULL){            fout.write((char*)p1,sizeof(Message));  p1=p1->next;}       fout.close();}return 0;}int delete3()                        //对比赛赛事相关信息进行删除{  creat3();   Message *p1,*p2;   p2=p1=head7;   cout<<"请输入要删除的参赛运动员姓名及比赛项目名称:"<<endl;   int flag=0;   char na[20];   char info[20];   cin>>na>>info;             while(p1!=NULL) {  if((p1->name==na)&&(p1->avent==info))   {flag=1;break;}                p2=p1;            p1= p1->next; }             if (flag==0)            cout<<"没有找到要删除的记录!"<<endl;               else               p2->next=p1->next;    ofstream fout("e:\\比赛赛事.dat",ios::out);    p1=head7;while(p1!=NULL){          fout.write((char*)p1,sizeof(Message));p1=p1->next;}   fout.close();return 0;}void print3(){ creat3(); Message *p1=head7; cout<<"请分别输出比赛参赛运动员姓名、比赛项目名称、比赛成绩、比赛名次."<<endl; while(p1!=NULL){  cout<<p1->name<<'\t'<<p1->avent<<'\t'<<p1->score<<'\t'<<p1->ca<<endl;       p1=p1->next;}   }void find3(){   creat3();    Message *p1;p1=head7;int sign=0;            //设置的标记变量cout<<"请输入要查询的参赛运动员姓名和比赛项目名称! "<<endl;         char na[20];char info[20];        //查询字符型数据条件cin>>na>>info;while(p1!=NULL)  {  if((p1->name==na)&&(p1->avent==info))   {sign=1;break;}                 p1= p1->next;  }              if (sign==0)         cout<<"没有找到要查询的记录!"<<endl;  else              cout<<p1->name<<'\t'<<p1->avent<<'\t'<<p1->score<<'\t'<<p1->ca<<endl;  }int find()//进行查找{cout<<endl;cout<<"\t\t\t请输入要查询的信息:"<<endl;cout<<"\t\t比赛项目信息查询      请按:1"<<endl;cout<<"\t\t运动员信息查询        请按:2"<<endl;cout<<"\t\t比赛赛事信息查询      请按:3"<<endl;int j;cin>>j;switch(j){case 1:find1();break;case 2:find2();break;case 3:find3();break;default:cout<<"输入数据有误!"<<endl;}  return 0;}int input(){cout<<endl;cout<<"\t\t\t请输入要输入的信息:"<<endl;cout<<"\t\t比赛项目信息输入      请按:1"<<endl;cout<<"\t\t运动员信息输入        请按:2"<<endl;cout<<"\t\t比赛赛事信息输入      请按:3"<<endl;int j;cin>>j;switch(j){case 1:input1();break;case 2:input2();break;case 3:input3();break;default:cout<<"输入数据有误!"<<endl;}  return 0;}int print(){cout<<endl;cout<<"\t\t\t请输入要显示输出的信息:"<<endl;cout<<"\t\t比赛项目信息显示输出      请按:1"<<endl;cout<<"\t\t运动员信息显示输出        请按:2"<<endl;cout<<"\t\t比赛赛事信息显示输出      请按:3"<<endl;int j;cin>>j;switch(j){case 1:print1();break;case 2:print2();break;case 3:print3();break;default:cout<<"输入数据有误!"<<endl;}  return 0;}int change(){cout<<endl;cout<<"\t\t\t请输入要修改的信息:"<<endl;cout<<"\t\t比赛项目信息修改      请按:1"<<endl;cout<<"\t\t运动员信息修改        请按:2"<<endl;cout<<"\t\t比赛赛事信息修改      请按:3"<<endl;int j;cin>>j;switch(j){case 1:change1();break;case 2:change2();break;case 3:change3();break;default:cout<<"输入数据有误!"<<endl;}  return 0;}int deleted(){cout<<endl;cout<<"\t\t\t请输入要删除的信息:"<<endl;cout<<"\t\t比赛项目信息删除      请按:1"<<endl;cout<<"\t\t运动员信息删除        请按:2"<<endl;cout<<"\t\t比赛赛事信息删除      请按:3"<<endl;int j;cin>>j;switch(j){case 1:delete1();break;case 2:delete2();break;case 3:delete3();break;default:cout<<"输入数据有误!"<<endl;}  return 0;}int  main(){   int i;  do  {  fun1();cin>>i;    switch(i)  {  case 1:input();break;  case 2:change();break;  case 3:deleted();break;  case 4:find();break;  case 5: print();break;  case 6: return 0;  default:cout<<"您输入数据有误!"<<endl;  }  }while(1);return 0;}






0 0
原创粉丝点击