首页 > 编程 > C++ > 正文

C++学校运动会管理系统的实现

2020-05-23 13:25:50
字体:
来源:转载
供稿:网友

本文实例为大家分享了C++实现运动会管理系统的具体代码,供大家参考,具体内容如下

#include <iostream>#include <cstdio>#include <string>#include <windows.h>#include <set>#include <map>using namespace std;const int MAXN = 100005;typedef long long LL;map< pair<string, string>, int> mtable;//男生参赛成绩map< pair<string, string>, int> wtable;//女生参赛成绩multimap<string, string> parti;//学号对应参赛项目set <string> st;//有哪些学生学号map<string, int> mitem;//参加该项目的女学生数map<string, int> witem;//参加该项目的男学生数map<string, int> item;//项目数参加人数map<string, int> acad;//学院的总得分map<string, int> macad;//学院男生得分map<string, int> wacad;//学院女生得分int cnt;struct student{ string number; string name; string acad; string sex; int participate;} stu[MAXN];void menu(){ cout<<"**************系统菜单功能项*****************/n"; cout<<"1.运动会报名/n"; cout<<"2.参赛信息查询/n"; cout<<"3.竞赛检录/n"; cout<<"4.竞赛成绩录入/n"; cout<<"5.竞赛成绩查询/n"; cout<<"6.竞赛成绩排序/n"; cout<<"7.退出程序/n"; return ;}void apply()//报名{ system("cls"); string s1,s2,s3,s4,s5; cout<<"请输入学生信息/n"; cout<<"请分别输入学生所属学院名,学生姓名,学生学号, 学生性别,学生参加的项目名/n"; cin>>s1>>s2>>s3>>s4>>s5; if(st.find(s3)==st.end()) { stu[cnt].acad=s1; stu[cnt].name=s2; stu[cnt].number=s3; stu[cnt].sex=s4; stu[cnt++].participate++; st.insert(s3); } else { for(int i=0; i<cnt; ++i) {  if(s3==stu[i].number)  {  if(stu[i].participate+1<=3)   stu[i].participate++;  else  {   printf("此学生已经报满3项,无法继续填报/n");   return ;  }  } } } parti.insert(make_pair(s3,s5)); acad.insert(make_pair(s1,0)); item[s5]++; if(s4=="男") { mitem[s5]=mitem[s5]+1; macad.insert(make_pair(s1,0)); mtable[pair<string, string>(s3,s5)]=0; } else { witem[s5]=witem[s5]+1; wacad.insert(make_pair(s1,0)); wtable[pair<string, string>(s3,s5)]=0; } return ;}void query()//查询{ printf("信息查询的结果如下/n"); for(int i=0; i<cnt; ++i) { cout<<"学生学号"<<stu[i].number<<" "<<"学生姓名"<<stu[i].name<<" "<<"学生性别"<<stu[i].sex<<" "<<"学生所属院系"<<stu[i].acad<<" "<<"学生参加项目数"<<stu[i].participate<<endl;; cout<<"同学姓名:"<<" "<<stu[i].name<<" "<<"参加了以下项目/n"; multimap<string,string>::iterator it=parti.begin(); for(; it!=parti.end(); it++) {  if(it->first==stu[i].number)  {  cout<<it->second<<" ";  } } cout<<"/n"; } return ;}void registration()//检录{ system("cls"); cout<<"请输入即将检录的比赛项目名字"<<endl; string s; cin>>s; cout<<"请一下同学前来检录"<<"/n"; int flag=0; multimap<string, string>::iterator it = parti.begin(); for(; it!=parti.end(); ++it) { if(it->second==s) {  flag=1;  cout<<it->first<<endl; } } if(!flag) cout<<"没有人报名该比赛/n"<<endl; return ;}void record()//录入成绩{ printf("请输入学生学号,和项目名字以及项目的名次/n"); string s1,s2; int grade, ans=0; cin>>s1>>s2>>grade; for(int i=0; i<cnt; ++i) { if(stu[i].number==s1) {  if(stu[i].sex=="男")  {  if(mitem[s2]>6)  {   if(grade==1)   ans=7;   else if(grade==2)   ans=5;   else if(grade==3)   ans=3;   else if(grade==4)   ans=2;   else if(grade==5)   ans=1;   else   ans=0;  }  else  {   if(grade==1)   ans=5;   else if(grade==2)   ans=3;   else if(grade==3)   ans=2;   else   ans=0;  }  macad[stu[i].acad]+=ans;  mtable[pair<string,string>(s1,s2)]=ans;  }  else  {  if(witem[s2]>6)  {   if(grade==1)   ans=7;   else if(grade==2)   ans=5;   else if(grade==3)   ans=3;   else if(grade==4)   ans=2;   else if(grade==5)   ans=1;   else   ans=0;  }  else  {   if(grade==1)   ans=5;   else if(grade==2)   ans=3;   else if(grade==3)   ans=2;   else   ans=0;  }  wacad[stu[i].acad]+=ans;  wtable[pair<string, string>(s1,s2)]=ans;  }  acad[stu[i].acad]+=ans; } }}void menu2(){ cout<<"1.按学院查看/n"; cout<<"2.按参赛项目查看/n"; cout<<"3.按参赛运动员查看/n"; cout<<"4.退出/n"; cout<<"请输入您的选择/n"; return ;}void query_contest1(){ map<string, int>::iterator it=acad.begin(); for(; it!=acad.end(); ++it) { cout<<"学院名字:"<<it->first<<endl; for(int i=0; i<cnt; ++i) {  if(stu[i].acad==it->first)  {  multimap<string, string>::iterator iter=parti.begin();  for(; iter!=parti.end(); ++iter)  {   if(stu[i].number!=iter->first)   continue;   if(stu[i].sex=="男")   cout<<"姓名: "<<stu[i].name<<"项目: "<<iter->second<<"成绩: "<<mtable[pair<string,string>(iter->first,iter->second)]<<endl;   else   cout<<"姓名: "<<stu[i].name<<"项目: "<<iter->second<<"成绩: "<<wtable[pair<string,string>(iter->first,iter->second)]<<endl;  }  } } }}void query_contest2(){ map<string, int>::iterator it=item.begin(); for(; it!=item.end(); it++) { cout<<"项目名称:"<<it->first<<endl; multimap<string, string>::iterator iter=parti.begin(); for(; iter!=parti.end(); iter++) {  if(iter->second==it->first)  {  for(int i=0; i<cnt; ++i)  {   if(iter->first==stu[i].number)   {   if(stu[i].sex=="男")    cout<<"姓名: "<<stu[i].name<<"项目: "<<iter->second<<"成绩: "<<mtable[pair<string,string>(iter->first,iter->second)]<<endl;   else    cout<<"姓名: "<<stu[i].name<<"项目: "<<iter->second<<"成绩: "<<wtable[pair<string,string>(iter->first,iter->second)]<<endl;   }  }  } } }}void query_contest3(){ for(int i=0; i<cnt; ++i) { cout<<"姓名: "<<stu[i].name<<"/n"; multimap<string, string>::iterator iter=parti.begin(); for(; iter!=parti.end(); iter++) {  if(iter->first==stu[i].number)  {  if(stu[i].sex=="男")   cout<<"项目: "<<iter->second<<"成绩: "<<mtable[pair<string,string>(iter->first,iter->second)]<<endl;  else   cout<<"项目: "<<iter->second<<"成绩: "<<wtable[pair<string,string>(iter->first,iter->second)]<<endl;  } } }}void query_contest()//比赛成绩查询{ system("cls"); menu2(); int op; if(cnt==0) { printf("当前无人报名比赛,请先报名比赛/n"); return ; } scanf("%d", &op); switch(op) { case 1: query_contest1(); break; case 2: query_contest2(); break; case 3: query_contest3(); break; case 4: return; break; default: printf("输入有误,请重新输入/n"); }}void sort_contest()//比赛成绩排序{ int Size=acad.size(); for(int i=0; i<Size; ++i) { int Max=-1; string Maxs=""; map<string, int >::iterator it = acad.begin(); map<string, int >::iterator iter; for(; it!=acad.end(); ++it) {  if(Max<it->second)  {  Max=it->second;  Maxs=it->first;  iter=it;  } } acad.erase(iter); cout<<"学院名称:"<<Maxs<<" 学院总分:"<<Max<<endl; cout<<"男生总得分:"<<macad[Maxs]<<" 女生总得分"<<wacad[Maxs]<<endl; }}int main(){ int op; cout<<("**************学校运动会管理系统*****************/n");// printf("请分别输入参赛学院个数,男子竞赛项目数和女子竞赛项目数/n");// scanf("%d %d %d", &c, &n, &m);// if(c<0||n<0||m<0)// {// printf("输入值有误,请重新输入/n");// scanf("%d %d %d", &c, &n, &m);// } cnt=0; while(1) { menu(); scanf("%d", &op); switch(op) { case 1:  apply();  break; case 2:  query();  break; case 3:  registration();  break; case 4:  record();  break; case 5:  query_contest();  break; case 6:  sort_contest();  break; case 7:  return 0;  break; default:  cout<<"错误输入, 请重新输入/n";  break; } } return 0;}

效果图:

C++,运动会,管理系统

C++,运动会,管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持VEVB武林网。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表