校运动会成绩管理系统

这个是校运动会成绩管理系统,还有四个功能未能实现(未在菜单中写入):1.按照项目编号查询各院系该项目的成绩和得分情况,2.按男女生总分排序 3.按照单个项目分数由高到低对所有院系进行排名 4.按学院总得分排名( 功能5未完成)

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <fstream>
#include<math.h> 
#include<io.h>
#include <stdlib.h>
using namespace std;
typedef struct studentNode{//定义选手节点
    string number;//学院编号 
    string name;//学生选手姓名 
    int sex; //性别 
    int project;//比赛项目编号 
    int score;//得分 
    struct studentNode*next;
}*student;
int countOfStudent;
FILE * fp;
void InputStudentInfo(student& studentLink){//录入选手信息 
    cout<<"|-----------------------欢迎进入校运动会成绩管理菜单(录入)-------------------|"<<endl;
    cout<<"|-----------------------1.重新创建-------------------------------------------|"<<endl;
    cout<<"|-----------------------2.引用已有数据---------------------------------------|"<<endl;
    cout<<"|--------------------注意:需要添加新的选手信息请返回主菜单------------------|"<<endl;
    int choice = 0;
    int choice1 = 0;
    studentLink->next=NULL;
    cin>>choice;
    switch (choice){
    case 1:{
               cout<<"请依次输入学院编号,姓名,性别(男:1.女:2),比赛项目编号,选手成绩:" << endl;
               countOfStudent=0;
               while(1){
                   student stu=new studentNode;
                   countOfStudent=countOfStudent + 1;
                   cin>>stu->number>>stu->name>>stu->sex>>stu->project>>stu->score;
                   cout<<stu->number<<stu->name<<stu->sex<<stu->project<<stu->score;
                   stu->next=studentLink->next;
                   studentLink->next=stu;
                   cout<<"\n1.继续输入        2.已完成"<<endl;
                   cin>>choice1;
                   if (choice1 == 2)
                    {
                       fp=fopen("studentFile.txt", "w");
                       fprintf(fp, "%d\n", countOfStudent);
                       student p = studentLink->next;
                       while (p){
                           fprintf(fp, "%s %s %d %d %d \n", p->number.c_str(), p->name.c_str(), p->sex, p->project, p->score);
                           cout << p->number << p->name << p->sex << p->project << p->score;
                           p = p->next;
                       }
                       fclose(fp);
                       break;
                   }
                   else{
                       cout <<"请依次输入学院编号,姓名,性别(男:1.女:2),比赛项目编号,选手成绩:"<< endl;
                   }
               }
               break;
    }
    case 2:  //到指定文件夹读取数据
        int exists = 0;
        if (!access("studentFile.txt", 0))
            exists = 1;
        char a[20];
        char b[30];
        if (exists)
        {
            fp = fopen("studentFile.txt", "rt");
            fscanf(fp, "%d", &countOfStudent);
            for (int i = 0; i<countOfStudent; i++)
            {
                student stu = new studentNode;
                fscanf(fp, "%s %s %d %d %d\n", b, a, &stu->sex, &stu->project, &stu->score);
                stu->number = b;
                stu->name = a;
                //头插法
                stu->next = studentLink->next;
                studentLink->next = stu;
            }
            cout << "已加载完成!" << "已加载" << countOfStudent << "条数据!" << endl;
        }
        else{
            cout << "暂无本地数据,请手动创建!" << endl;
        }
        fclose(fp);
        break;
    }
}
void ShowAllStudentInfo(student& studentLink){//显示所有选手信息
    cout<<"|-----------------------欢迎进入校运动会成绩管理菜单(显示)-------------------|"<<endl;
    student p = studentLink->next;
    cout << "学院编号 " << "    姓名     " << "      性别(1男2女)  " << " 参赛项目     " << "  得分       " << endl;
    while (p){
        cout << p->number << "             " << p->name << "             " << p->sex << "                " << p->project << "              " << p->score << endl;
        p = p->next;
    }
}
void SearchStudentInfo(student& studentLink){//选手信息查询
    cout<<"|-----------------------欢迎进入校运动会成绩管理菜单(查询)-------------------|"<<endl;
    while (1)
    {
        cout<<"|-----------------------1.按照学院编号查询-----------------------------------|"<<endl;
        cout<<"|-----------------------2.按照姓名查询---------------------------------------|"<<endl;
        int choice = 0;
        int choice1 = 0;
        cin >> choice;
        switch (choice){
        case 1:
        {
                  student p = studentLink->next;
                  cout<<"请输入学院编号:"<<endl;
                            string num;
                            cin >> num;
                            bool flag = false;
                            while (p){
                                if (p->number == num)
                                {
                                    flag = true;
                                    cout << "学院编号 " << "    姓名     " << "      性别(1男2女)  " << " 参赛项目     " << "  得分       " << endl;
                                    cout << p->number << "             " << p->name << "             " << p->sex << "                " << p->project << "              " << p->score << endl;
                                    break;
                                }
                                p = p->next;
                            }
                            if (!flag)
                            {
                                cout << "当前学号不存在" << endl;
                            }
                  break; }
        case 2:
        {
                  student p = studentLink->next;
                  cout << "1.按照姓名精确查询。                 2.按照姓氏模糊查询" << endl;
                  cin >> choice1;
                  switch (choice1){
                  case 1:
                  {
                            cout << "请输入精确姓名:" << endl;
                            string name;
                            cin >> name;
                            bool flag = false;
                            while (p){
                                if (p->name == name)
                                {
                                    cout << "学院编号 " << "    姓名     " << "      性别(1男2女)  " << " 参赛项目     " << "  得分       " << endl;
                                    cout << p->number << "             " << p->name << "             " << p->sex << "                " << p->project << "              " << p->score << endl;
                                    flag = true;
                                    break;
                                }
                                p = p->next;
                            }
                            if (!flag)
                            {
                                cout << "当前姓名不存在" << endl;
                            }
                            break;
                  }
                  case 2:
                  {
                            cout << "请输入前缀姓氏:" << endl;
                            string name;
                            bool flag = false;
                            cin >> name;
                            while (p){
                                if (p->name.find(name, 0) == 0)
                                {
                                    if (!flag)
                                    {
                                        cout << "学院编号 " << "    姓名     " << "      性别(1男2女)  " << " 参赛项目     " << "  得分       " << endl;
                                    };
                                    cout << p->number << "             " << p->name << "             " << p->sex << "                " << p->project << "              " << p->score << endl;
                                    flag = true;
                                }
                                p = p->next;
                            }
                            if (!flag)
                            {
                                cout << "当前姓氏不存在" << endl;
                            }
                            break;
                  }
                  }
                  break;
        }
        }
        int choice3 = 0;
        cout << "\n1.继续查询。                 2.查询完成" << endl;
        cin >> choice3;
        if (choice3 == 2)
        {
            break;
        }
    }
}
void ModifyStudentInfo(student& studentLink){//对选手信息进行修改
    cout<<"|-----------------------欢迎进入校运动会成绩管理菜单(修改)-------------------|"<<endl;
    fp = fopen("studentFile.txt", "rt");
    fscanf(fp, "%d", &countOfStudent);
    fclose(fp);
    while (1){
        cout << "1.添加      2.删除      3.修改" << endl;
        int choice = 0;
        cout << "请输入您想要的操作:" << endl;
        cin >> choice;
        switch (choice){
        case 1:
        {

                  cout<<"请依次输入学院编号,姓名,性别(男:1.女:2),比赛项目编号,选手成绩:" << endl;
                  while (1){
                      student stu = new studentNode;
                      countOfStudent = countOfStudent + 1;
                      cin>>stu->number>>stu->name>>stu->sex>>stu->project>>stu->score;
                      cout<<stu->number<<stu->name<<stu->sex<<stu->project<<stu->score;
                      stu->next = studentLink->next;
                      studentLink->next = stu;
                      cout << "\n1.继续输入        2.已完成" << endl;
                      int  choice1 = 0;
                      cout << "请输入选择:" << endl;
                      cin >> choice1;
                      if (choice1 == 2)
                      {
                          break;
                      }
                  }
                  break;
        }
        case 2:
        {
                  cout << "请输入学生姓名" << endl;
                  string number1;
                  cin >> number1;
                  bool flag = false;
                  student p = studentLink;
                  student p1 = p->next;
                  while (p){
                      if (p1)
                      {
                          if (p1->name == number1)
                          {
                              cout << "find" << endl;
                              student p2 = p1;
                              p->next = p2->next;
                              free(p2);
                              flag = true;
                              countOfStudent--;
                          }
                      }
                      p = p->next;
                      if (p)
                      {
                          p1 = p->next;
                      }

                  }
                  if (!flag)
                  {
                      cout << "无此学生!" << endl;
                  }
                  break;
        }
        case 3:
        {
                  cout << "请输入需修改学生的姓名:" << endl;
                  string name;
                  cin >> name;
                  bool flag = false;
                  student p = studentLink->next;
                  while (p){
                      if (p->name == name)
                      {
                          flag = true;
                          cout << "--1.修改学院编号--2.修改姓名--3.修改性别--4.修改参赛项目编号--5.修改成绩--" << endl;
                          int cho = 0;
                          cin >> cho;
                          switch (cho){
                          case 1:{

                                     cout << "请输入新的学院编号:" << endl;
                                     string num;
                                     cin >> num;
                                     p->number = num;
                                     break;
                          }
                          case 2:{
                                     cout << "请输入新的姓名:" << endl;
                                     string name;
                                     cin >> name;
                                     p->name = name;
                                     break;
                          }
                          case 3:{
                                     cout << "请输入新的性别:" << endl;
                                     int num;
                                     cin >> num;
                                     p->sex = num;
                                     break;
                          }
                          case 4:{
                                     cout << "请输入新的参赛项目编号:" << endl;
                                     int num;
                                     cin >> num;
                                     p->project = num;
                                     break;
                          }
                          case 5:{
                                     cout << "请输入新的成绩:" << endl;
                                     int num;
                                     cin >> num;
                                     p->score = num;
                                     break;
                          }
                          }
                      }
                      p = p->next;
                  }
                  if (!flag)
                  {
                      cout << "该姓名不存在" << endl;
                  }
                  break;
        }
        }
        cout << "\n1.继续修改      2.修改完成" << endl;
        int choice7 = 0;
        cin >> choice7;
        if (choice7 == 2)
        {
            student p = studentLink->next;
            cout << "正在录入新的成绩" << endl;//输入完成后将学生信息写入文件
            fp = fopen("studentFile.txt", "w");
            fprintf(fp, "%d\n", countOfStudent);
            while (p){
                fprintf(fp, "%s %s %d %d %d \n", p->number.c_str(), p->name.c_str(), p->sex, p->project, p->score);

                p = p->next;
            }
            fclose(fp);
            break;
        }
    }
}
void RankStudentInfo(student& studentLink){//对学院总成绩排名
     student p = studentLink->next;
     cout<<"请输入学院编号:"<<endl;
     string Num;
     int a[0],b[0],i;
     cin >> Num;
     bool flag = false;
     while (p){
     if (p->number == Num){
     flag = true;
     a[i]=p->score;
     for(i=0;i<10;i++){
         a[i]+=b[i];
     }
     cout <<"该学院得分为: "<< endl;
     cout <<b[i]<<endl; 
     break;
     }
     p = p->next;
     }
     if (!flag){
     cout << "当前学号不存在" << endl;
     }
}
int main(){
    system("color 2F");
    cout<<"|-----------------------欢迎进入校运动会成绩管理菜单-------------------------|"<<endl;
    cout<<"|---学院编号;1.大数据学院   2.建工学院   3.动医学院   4.人文学院   5.马院---|"<<endl;
    cout<<"|---比赛项目编号:1.跳高   2.田径   3.跳远   4.铅球   5.乒乓球 --------------|"<<endl;
    cout<<"|---第一名加10分,第二名加8分,第三名加6分,第四名加4分,第五名加2分---------|"<<endl; 
    cout<<"|--1.录入学生选手信息--------------------------------------------------------|"<<endl;
    cout<<"|--2.查询所有选手信息--------------------------------------------------------|"<<endl;
    cout<<"|--3.查询某一个选手具体信息--------------------------------------------------|"<<endl;
    cout<<"|--4.插入新信息,修改信息,删除信息------------------------------------------|"<<endl;
    cout<<"|--5.学院成绩排名------------------------------------------------------------|"<<endl;
    cout<<"|--6.退出系统----------------------------------------------------------------|"<<endl;
    int choice = 0;
    student studentLink = new studentNode;
    while (1){
        cout << "\n主菜单---请输入您的选择:";
        cin >> choice;
        switch (choice){
        case 1:
            InputStudentInfo(studentLink);
            break;
        case 2:
            ShowAllStudentInfo(studentLink);
            break;
        case 3:
            SearchStudentInfo(studentLink);
            break;
        case 4:
            ModifyStudentInfo(studentLink);
            break;
        case 5:
            RankStudentInfo(studentLink);
            break;
        case 6:
            exit(0);
            break;
        }
    }
    getchar();
    return 0;
}


#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;
}