运动会分数统计系统——史上最完善的运动会分数统计系统

题目三:运动会分数统计

参加运动会有 n 个学校,学校编号为 1……n。比赛分成 m 个男子项目和 w 个女子项目。项目编号为男子 1……m,女子m+1……m+w。不同的项目取前五名或前三名积分;前五名的积分

为:75321,前三名的积分为:532;哪些取前五名或前三名由学生自己设定。(m<=20,n<=20

1)        可以输入各个项目的前三名或前五名的成绩;

2)        能统计各学校总分;

3)        可以按学校编号或名称、学校总分、男女团体总分排序输出;

4)        可以按学校编号查询学校某个项目的情况;可以按项目编号查询取得前三或前五名的学校;

5)        数据存入文件并能随时查询;

6)        其他要求:

(1)      输入数据:可以输入学校的名称,运动项目的名称;

(2)      输出形式:有中文提示,各学校分数为整型;

(3)      界面要求:有合理的提示,使用者可根据提示,完成相关的功能要求;

(4)      存储结构:根据系统功能要求自行设计,但是要求运动会的相关数据要存储在数据文件中,在实验报告中指明你用到的存储结构;

(5)      测试数据:分别使用合法数据、非法数据进行程序测试,以保证程序的稳定,测试数据及测试结果请在实验报告中写明;

 

 

 

 

 

#include<iostream>
#include<fstream>
#include<vector>
#include <direct.h>
#include<string>
#include<windows.h>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define MAX 40

//数据结构
class school
{
public:
    school()
    {
        for(int i=0; i<MAX; i++)
        {
            grade[i]=0;
            point[i]=0;
        }
        grade_b=0;
        grade_g=0;
        grade_totle=0;
    }
    school(string name)
    {
        name_school=name;
        for(int i=0; i<MAX; i++)
        {
            grade[i]=0;
            point[i]=0;
        }
        grade_b=0;
        grade_g=0;
        grade_totle=0;
    }
    static string name_sport[MAX];//项目名称
    static bool point_way[MAX];//0表示取前五名,1表示取前3名;
    static bool sex_sport[MAX];//1表示男,0表示女
    static int n,m;//n学校数量,m项目数量
    string name_school;//学校名称
    int num;//学校编号
    int grade[MAX];//成绩
    int point[MAX];//积分
    int grade_totle;//总成绩
    int grade_b;//男子团体
    int grade_g;//女子团体
};
int school::n=0;
int school::m=0;
string school::name_sport[MAX]= {};
bool school::point_way[MAX]= {0};
bool school::sex_sport[MAX]= {0};


//工具栏
class toolbar
{
public:
    toolbar(int num,string too[],string too_en[])
    {
        n=num;
        for(int i=0; i<n; i++)
        {
            tool[i]=too[i];
            tool_en[i]=too_en[i];
        }

    }
    void toolbar_show()
    {
        for(int i=0; i<80; i++) cout<<"-";
        for(int i=0; i<n; i++)
            cout<<tool[i]<<"<"<<tool_en[i]<<">"<<"  ";
        cout<<endl;
        for(int i=0; i<80; i++) cout<<"-";
    }
    void set_tool(int num,string too[],string too_en[])
    {
        n=num;
        for(int i=0; i<n; i++)
        {
            tool[i]=too[i];
            tool_en[i]=too_en[i];
        }

    }
    int get_tool_en(string eng)
    {
        for(int i=0; i<n; i++)
            if(tool_en[i][0]==eng[0]||tool_en[i][0]==(char)(eng[0]-32)) return i+1;
        return 0;
    }
private:
    int n;
    string tool[6];
    string tool_en[6];
};

string t0[5]= {"文件","编辑","查看","帮助","退出"};
string t_e0[5]= {"F","E","V","H","Q"};
toolbar tool_0(5,t0,t_e0);
string t1[5]= {"新建","打开","保存","另存为","返回"};
string t_e1[5]= {"N","O","S","A","B"};
toolbar tool_1(5,t1,t_e1);
string t2[4]= {"添加","修改","删除","返回"};
string t_e2[4]= {"I","C","D","B"};
toolbar tool_2(4,t2,t_e2);
string t3[4]= {"查看学校","查看项目","查看所有项目","返回"};
string t_e3[4]= {"S","P","A","B"};
toolbar tool_3(4,t3,t_e3);

//返回当前工具栏是几号工具栏
toolbar *toolbar_now(int num)
{
    switch (num)
    {
    case 0:
        return &tool_0;
    case 1:
        return &tool_1;
    case 2:
        return &tool_2;
    default:
        return &tool_3;
    };
}

//显示区域
class display
{
public:
    display()
    {
        g=1;
        pre=3;//设置默认排序
        bit=0;
        name[0]="编号<1>";
        name[1]="校名<2>";
        name[2]="总分<3>";
        name[3]="男总<4>";
        name[4]="女总<5>";
        name[5]="排名";

    }
    void _show()
    {
        cout<<setw(11)<<left<<name[0]
                    <<setw(20)<<left<<name[1]
                    <<setw(11)<<left<<name[2]
                    <<setw(11)<<left<<name[3]
                    <<setw(11)<<left<<name[4]
                    <<setw(11)<<left<<name[5]<<endl;
        cout<<endl;
        if(g)
            for(int i=0; i<school::n; i++)
            {
                cout<<setw(11)<<left<<sch[i].num
                    <<setw(20)<<left<<sch[i].name_school
                    <<setw(11)<<left<<sch[i].grade_totle
                    <<setw(11)<<left<<sch[i].grade_b
                    <<setw(11)<<left<<sch[i].grade_g
                    <<setw(11)<<left<<i+1<<endl;
            }
        else
            for(int i=school::n-1; i>=0; i--)
            {
                cout<<setw(11)<<left<<sch[i].num
                    <<setw(20)<<left<<sch[i].name_school
                    <<setw(11)<<left<<sch[i].grade_totle
                    <<setw(11)<<left<<sch[i].grade_b
                    <<setw(11)<<left<<sch[i].grade_g
                    <<setw(11)<<left<<i+1<<endl;
            }
    }
    void show()
    {
        if(school::n>0)
        {
            if(bit==1) g=!g;
            else _sort(pre);
            _show();
        }
    }
    bool get_str(string str)
    {
        char ch=str[0];
        if(ch>='1'&&ch<'6')
        {
            if(pre==ch-'1'+1)
                bit=1;
            else
            {
                bit=0;
                pre=ch-'1'+1;
            }
            return 1;
        }
        return 0;
    }
    void set_sch(vector<school> sch)
    {
        this->sch=sch;
    }
private:
    void _sort(int tem)
    {
        for(vector<school>::iterator i=sch.begin(); i!=sch.end(); i++)
            for(vector <school>::iterator j=i+1; j!=sch.end(); j++)
                if((tem==1&&j->num>i->num)||(tem==2&&j->name_school>i->name_school)||(tem==3&&j->grade_totle>i->grade_totle)
                        ||(tem==4&&j->grade_b>i->grade_b)||(tem==5&&j->grade_g>i->grade_g))
                {
                    school tem;
                    tem=*i;
                    *i=*j;
                    *j=tem;
                }
    }
    int pre;
    bool g;
    bool bit;
    string name[6];
    vector<school> sch;
};

display dis;
string path_now="";//当前路径
bool change_if=0;//记录内容是否改变

//判断路径格式是否正确
bool path_right(string path)
{
    string name=path.substr(0,3);
    if(GetDriveType(name.c_str())!=DRIVE_REMOVABLE&&GetDriveType(name.c_str())!=DRIVE_FIXED)
    {
        printf("%c",7);
        cout<<"不是有效盘符或盘符格式不正确!(c:)"<<endl;
        Sleep(2000);
        return 0;
    }
    else
    {
        for(size_t i=2; i<path.length(); i++)
            if(path[path.length()-1]=='\\'
                    ||path[path.length()-1]=='/'
                    ||((path[2]!='/')&&(path[2]!='\\'))
                    ||!(('A'<=path[i]&&'Z'>=path[i])
                        ||('a'<=path[i]&&'z'>=path[i])
                        ||('0'<=path[i]&&'9'>=path[i])
                        ||path[i]=='\\'
                        ||path[i]=='/'
                        ||path[i]=='.'))
            {
                printf("%c",7);
                cout<<"路径格式不正确!(只能输入英语字母数字和'\\','/','.')"<<endl;
                Sleep(2000);
                return 0;
            }
    }
    return 1;
}
//创建多级文件夹
bool creat_path(string path)
{
    int i = 0;
    int i_ret;
    int i_len = path.length();
    for (i = 0; i <i_len; i++)
    {
        if (path[i] == '\\' || path[i] == '/')
        {
            path[i] = '\0';

            //如果不存在,创建
            i_ret = _access(path.c_str(),0);
            if (i_ret != 0)
            {
                i_ret = _mkdir(path.c_str());
                if (i_ret != 0)
                {
                    return 0;
                }
            }
            path[i] = '/';
        }
    }
    return 1;
}

//写入文件
void _store(string path ,vector<school> sch)
{
    fstream out;
    out.open(path.c_str(),ios::out);
    out<<school::n<<endl;
    for(int i=0; i<school::n; i++)
        out<<sch[i].name_school<<" ";
    out<<endl;
    out<<school::m<<endl;
    for(int i=0; i<school::m; i++)
    {
        out<<school::name_sport[i]<<" "<<(int )school::point_way[i]<<" ";
        for(int j=0; j<school::n; j++)
            out<<sch[j].grade[i]<<" ";
        out<<endl;
    }
    out.close();
}

//从文件读取
bool _read(string path,vector<school> &sch)
{
    fstream in;
    in.open(path.c_str(),ios::in);
    in>>school::n;
    for(int i=0; i<school::n; i++)
    {
        string name;
        in>>name;
        school sch_tem(name);
        sch.push_back(sch_tem);
    }
    in>>school::m;
    for(int i=0; i<school::m; i++)
    {
        in>>school::name_sport[i]>>school::point_way[i];
        for(int j=0; j<school::n; j++)
            in>>sch[j].grade[i];

    }
    in.close();
    if(in.rdstate()) return 0;
    else return 1;

}

bool store_file(string path,vector<school> &sch,bool force=0)
{
    fstream out;
    out.open(path.c_str(),ios::in);
    if(force==0&&out)//文件已存在
    {
        out.close();
        return 0;
    }
    else if(force==1&&out)//强制写入
    {
        out.close();
        _store(path,sch);
        return 1;
    }
    else
    {
        out.open(path.c_str(),ios::out);
        if(!out)//路径中有未创建文件夹
        {
            creat_path(path.c_str());//创建多级目录
            _store(path,sch);
            return 1;
        }
        else
        {
            out.close();
            _store(path,sch);
            return 1;
        }
    }
}


//新建,从控制台读取数据
void new_build(vector<school> &sch)
{

    while(1)
    {
l1:
        system("cls");
        for(vector<school>::iterator i=sch.begin(); i!=sch.end(); i++)
            cout<<i-sch.begin()+1<<":"<<i->name_school<<endl;
        cout<<"请输入学校名称,以#结束"<<endl;
        string name;
        cin>>name;
        if(name=="#") break;
        for(vector<school>::iterator i=sch.begin(); i!=sch.end(); i++)
            if(i->name_school==name)
            {
                printf("%c",7);
                cout<<"学校已存在,请重新输入"<<endl;
                cin.sync();
                Sleep(2000);
                goto l1;
            }
        school sch_tem(name);
        sch.push_back(sch_tem);
        sch.back().num=sch.size();
        school::n=sch.size();
    }
}

void new_build_(vector<school> &sch)
{
    int t=school::m;
    while(1)
    {
l2:
        system("cls");
        for(vector<school>::iterator i=sch.begin(); i!=sch.end(); i++)
            cout<<i-sch.begin()+1<<":"<<i->name_school<<endl;
        int i=t-1;
        if(i>=school::m)
        {
            cout<<school::name_sport[i]<<"  "<<school::point_way[i]<<"  ";
            for(int j=0; j<school::n; j++)
                cout<<sch[j].grade[i]<<"  ";
            cout<<endl;
        }

        cout<<"请依次输入项目名称、积分方式(0表示取前5名,1表示取前3名)和各学校成绩:\n#结束,$撤销上次输入"<<endl;
        cin>>school::name_sport[t];
        if(school::name_sport[t]=="#") break;
        if(school::name_sport[t]=="$")
        {
            if(t>school::m) t--;
            else printf("%c",7);
            goto l2;
        }
        for(int i=0; i<t; i++)
            if(school::name_sport[i]==school::name_sport[t])
            {
                printf("%c",7);
                cout<<"项目已存在,请重新输入"<<endl;
                cin.sync();
                Sleep(2000);
                goto l2;
            }
        cin>>school::point_way[t];
        if(cin.rdstate())
        {
            printf("%c",7);
            cout<<"积分方式输入有误(0表示取前5名,1表示取前3名),请重新输入"<<endl;
            Sleep(2000);
            cin.clear();
            cin.sync();
            goto l2;
        }
        for(int i=0; i<school::n; i++)
            cin>>sch[i].grade[t];
        if(cin.rdstate())
        {
            printf("%c",7);
            cout<<"输入数据有误,请重新输入"<<endl;
            Sleep(2000);
            cin.clear();
            cin.sync();
            goto l2;
        }
        else
        {
            cout<<"录入成功"<<endl;
            cin.sync();
            Sleep(1000);
        }
        t++;
    }
    school::m=t;
}


//处理数据
void computer(vector<school> &sch)
{
    //存储学校编号
    for(vector<school>::iterator i=sch.begin(); i!=sch.end(); i++)
        i->num=i-sch.begin()+1;

    //项目是男子项目还是女子项目
    for(int i=0; i<school::m; i++)
        if(school::name_sport[i].find("女")) school::sex_sport[i]=1;
        else school::sex_sport[i]=0;

    //成绩转换为积分
    for(int i=0; i<school::m; i++)
        for(int j=0; j<school::n; j++)
            sch[j].point[i]=0;
    int p_5[5]= {7,5,3,2,1};
    int p_3[3]= {5,3,2};
    for(int i=0; i<school::m; i++)
        if(school::point_way[i]==0)//取前5名
        {
            int n=school::n;
            for(int p=0; p<min(5,n); p++)
            {
                int max=-1;
                for(int j=0; j<school::n; j++)
                    if(sch[j].grade[i]>max&&sch[j].point[i]==0)
                        max=sch[j].grade[i];
                n++;
                for(int j=0; j<school::n; j++)
                    if(sch[j].grade[i]==max)
                    {
                        sch[j].point[i]=p_5[p];
                        n--;
                    }
            }
        }
        else//取前3名
        {
            int n=school::n;
            for(int p=0; p<min(3,n); p++)
            {
                int max=-1;
                for(int j=0; j<school::n; j++)
                    if(sch[j].grade[i]>max&&sch[j].point[i]==0)
                        max=sch[j].grade[i];
                n++;
                for(int j=0; j<school::n; j++)
                    if(sch[j].grade[i]==max)
                    {
                        sch[j].point[i]=p_3[p];
                        n--;
                    }
            }
        }

    //计算学校总分,男子团体分,女子团体分
    for(int i=0; i<school::n; i++)
    {
        sch[i].grade_totle=0;
        sch[i].grade_b=0;
        sch[i].grade_g=0;
    }
    for(int i=0; i<school::n; i++)
        for(int j=0; j<school::m; j++)
        {
            sch[i].grade_totle+=sch[i].point[j];
            if(school::sex_sport[j]==1) sch[i].grade_b+=sch[i].point[j];
            else sch[i].grade_g+=sch[i].point[j];
        }
}

vector<school> new_()
{
    system("cls");
    vector<school> sch;
    new_build(sch);
    new_build_(sch);
    computer(sch);
    dis.set_sch(sch);
    path_now="";
    change_if=1;
    return sch;
}
vector<school> open_()
{
    vector<school> sch;
l3:
    system("cls");
    cout<<"请输入路径:"<<endl;
    string path;
    cin>>path;
    if(!path_right(path)) goto l3;
    fstream in;
    in.open(path.c_str(),ios::in);
    if(!in)
    {
        printf("%c",7);
        cout<<"文件不存在!"<<endl;
        Sleep(1000);
        cout<<"重新输入<r>      新建文件<n>"<<endl;
        string str;
l9:
        cin>>str;
        if(str[0]=='r'||str[0]=='R') goto l3;
        else if(str[0]=='n'||str[0]=='N') sch=new_();
        else
        {
            printf("%c",7);
            goto l9;
        }
    }
    else
    {
        in.close();
        if(_read(path,sch))
        {
            path_now=path;
            computer(sch);
            dis.set_sch(sch);
        }
        else
        {
            printf("%c",7);
            cout<<"不是运动会分数统计数据文件!"<<endl;
            Sleep(1000);
            cout<<"重新输入<r>      新建文件<n>"<<endl;
            string str;
l10:
            cin>>str;
            if(str[0]=='r'||str[0]=='R') goto l3;
            else if(str[0]=='n'||str[0]=='N') sch=new_();
            else
            {
                printf("%c",7);
                goto l10;
            }
        }
    }
    return sch;
}
void save_(vector <school> sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
    system("cls");
    if(path_now!="")
    {
        store_file(path_now,sch,1);
        cout<<"保存成功!"<<endl;
        Sleep(1000);
    }
    else
    {
        string path;
l5:
        cout<<"请输入路径:"<<endl;
        cin>>path;
        if(!path_right(path))
            goto l5;
        if(store_file(path,sch)==0)
        {
            cout<<"文件已存在!强制写入或重新输入路径?"<<endl;
            printf("%c",7);
            Sleep(1000);
            cout<<"强制写入<f>        重新输入<r>"<<endl;
            string str;
l6:
            cin>>str;
            if(str[0]=='r'||str[0]=='R') goto l5;
            else if(str[0]=='f'||str[0]=='F') store_file(path,sch,1);
            else
            {
                printf("%c",7);
                goto l6;
            }
        }
        cout<<"保存成功!"<<endl;
        Sleep(1000);
        path_now=path;
    }
    change_if=0;
}
void save_as(vector<school> sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
    system("cls");
    string path;
l7:
    cout<<"请输入路径:"<<endl;
    cin>>path;
    if(!path_right(path)) goto l7;
    if(store_file(path,sch)==0)
    {
        cout<<"文件已存在!强制写入或重新输入路径?"<<endl;
        printf("%c",7);
        Sleep(1000);
        cout<<"强制写入<f>        重新输入<r>"<<endl;
        string str;
l8:
        cin>>str;
        if(str[0]=='r'||str[0]=='R') goto l7;
        else if(str[0]=='f'||str[0]=='F') store_file(path,sch,1);
        else
        {
            printf("%c",7);
            goto l8;
        }
    }
    cout<<"保存成功!"<<endl;
    Sleep(1000);
    path_now=path;
    change_if=0;
}

void find_p_all_(vector <school> sch);
void insert_(vector<school> &sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
    system("cls");
    cout<<"添加学校<s>        添加项目<p>"<<endl;
    string str;
l11:
    cin>>str;
    if(str[0]=='s'||str[0]=='S')
    {
        while(1)
        {
            system("cls");
            find_p_all_(sch);
            cout<<"输入学校名称,再依次输入各项成绩,#结束添加"<<endl;
            string name;
l12:
            cin>>name;
            if(name=="#") break;
            for(vector<school>::iterator i=sch.begin(); i!=sch.end(); i++)
                if(i->name_school==name)
                {
                    printf("%c",7);
                    cout<<"学校已存在,请重新输入"<<endl;
                    cin.sync();
                    Sleep(2000);
                    goto l12;
                }
            school sch_tem(name);
            for(int i=0; i<school::m; i++)
                cin>>sch_tem.grade[i];
            if(cin.rdstate())
            {
                printf("%c",7);
                cout<<"输入数据有误,请重新输入"<<endl;
                Sleep(2000);
                cin.clear();
                cin.sync();
                goto l12;
            }
            else
            {
                cout<<"录入成功"<<endl;
                cin.sync();
                Sleep(1000);
            }
            sch.push_back(sch_tem);
            sch.back().num=sch.size();
            school::n=sch.size();
        }
    }
    else if(str[0]=='p'||str[0]=='P')
    {
        new_build_(sch);
    }
    else
    {
        printf("%c",7);
        goto l11;
    }
    computer(sch);
    dis.set_sch(sch);
    change_if=1;
}

void change_s(vector<school> &sch,int i)
{
l16:
    system("cls");
    cout<<"请输入新的学校名称:"<<endl;
    string name;
    cin>>name;
    for(vector<school>::iterator j=sch.begin(); j!=sch.end(); j++)
        if(j->name_school==name)
        {
            printf("%c",7);
            cout<<"学校已存在,请重新输入"<<endl;
            cin.sync();
            Sleep(2000);
            goto l16;
        }
    sch[i].name_school=name;
}

void change_p(vector<school> &sch,int i)
{

l17:
    system("cls");
    cout<<school::name_sport[i]<<"  "<<school::point_way[i]<<":"<<endl;
    cout<<setw(6)<<left<<"编号"
        <<setw(20)<<left<<"学校名称"
        <<setw(6)<<left<<"成绩"<<endl;
    for(int j=0; j<school::n; j++)
        cout<<setw(6)<<left<<j+1
            <<setw(20)<<left<<sch[j].name_school
            <<setw(6)<<left<<sch[j].grade[i]<<endl;
    cout<<"修改项目名称<n> 修改积分方式<w> 修改成绩<学校编号>"<<endl;
    string str;
    cin>>str;
    if(str[0]=='n'||str[0]=='N')
    {
l18:
        system("cls");
        cout<<"请输入新名称:"<<endl;
        string name;
        cin>>name;
        for(int j=0; j<school::m; j++)
            if(str==school::name_sport[j])
            {
                printf("%c",7);
                cout<<"项目已存在,请重新输入"<<endl;
                Sleep(1500);
                goto l18;
            }
        school::name_sport[i]=name;

    }
    else if(str[0]=='w'||str[0]=='W')
    {
l19:
        system("cls");
        cout<<"请输入新的积分方式,0取前5名,1取前3名"<<endl;
        string way;
        cin>>way;
        if(way[0]=='0'||way[0]=='1')
        {
            school::point_way[i]=way[0]-'0';
        }
        else
        {
            printf("%c",7);
            cout<<"请输入0或者1!,请重新输入"<<endl;
            Sleep(1500);
            goto l19;
        }

    }
    else
    {
        int tem=-1;
        bool done=0;
        if('1'<=str[0]&&'9'>=str[0]&&(str[0]-'0'-1<school::n))
        {
            tem=str[0]-'0'-1;
            done=1;
        }
        if('0'<=str[1]&&'9'>=str[1]&&((str[0]-'0')*10+str[1]-'0'-1<school::n))
        {
            tem=(str[0]-'0')*10+str[1]-'0'-1;
            done=1;
        }
        if(done==1)
        {
l20:
            system("cls");
            cout<<"您将要修改 "<<sch[tem].name_school<<" 的 "<<school::name_sport[i]<<" 成绩"<<endl;
            cout<<"原成绩为:"<<sch[tem].grade[i]<<endl;
            cout<<"请输入新成绩:"<<endl;
            cin>>sch[tem].grade[i];
            if(cin.rdstate())
            {
                printf("%c",7);
                cout<<"输入数据有误,请重新输入"<<endl;
                Sleep(2000);
                cin.clear();
                cin.sync();
                goto l20;
            }
        }
        else
        {
            printf("%c",7);
            goto l17;
        }
    }
}


void change_(vector<school> &sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
l14:
    system("cls");
    cout<<"修改学校名称<s>        修改项目内容<p>"<<endl;
    string str;
    cin>>str;
    if(str[0]=='s'||str[0]=='S')
    {
        while(1)
        {
            int tem=-1;
            bool done=0;
            system("cls");
            cout<<"请输入要修改的学校名称或编号,#结束"<<endl;
            string str;
            cin>>str;
            if(str=="#") break;
            if('1'<=str[0]&&'9'>=str[0]&&(str[0]-'0'-1<school::n))
            {
                tem=str[0]-'0'-1;
                done=1;
            }
            if('0'<=str[1]&&'9'>=str[1]&&((str[0]-'0')*10+str[1]-'0'-1<school::n))
            {
                tem=(str[0]-'0')*10+str[1]-'0'-1;
                done=1;
            }
            for(int i=0; i<school::n; i++)
                if(str==sch[i].name_school)
                {
                    tem=i;
                    done=1;
                }
            if(done==0)
            {
                printf("%c",7);
                cout<<"没找到!"<<endl;
                Sleep(1500);
            }
            else
            {
                change_s(sch,tem);
                cout<<"修改成功!"<<endl;
                Sleep(1500);
            }
        }
    }
    else if(str[0]=='p'||str[0]=='P')
    {
        while(1)
        {
            int tem=-1;
            bool done=0;
            system("cls");
            find_p_all_(sch);
            cout<<endl;
            cout<<"请输入要修改的项目名称或编号,#结束"<<endl;
            string str;
            cin>>str;
            if(str=="#") break;
            if('1'<=str[0]&&'9'>=str[0]&&(str[0]-'0'-1<school::m))
            {
                tem=str[0]-'0'-1;
                done=1;
            }
            if('0'<=str[1]&&'9'>=str[1]&&((str[0]-'0')*10+str[1]-'0'-1<school::m))
            {
                tem=(str[0]-'0')*10+str[1]-'0'-1;
                done=1;
            }
            for(int i=0; i<school::m; i++)
                if(str==school::name_sport[i])
                {
                    tem=i;
                    done=1;
                }
            if(done==0)
            {
                printf("%c",7);
                cout<<"没找到!"<<endl;
                Sleep(1500);
            }
            else
            {
                change_p(sch,tem);
                cout<<"修改成功!"<<endl;
                Sleep(1500);
            }
        }
    }
    else
    {
        printf("%c",7);
        goto l14;
    }
    computer(sch);
    dis.set_sch(sch);
    change_if=1;

    change_if=1;
}

void delete_s(vector <school> &sch,int i)
{
    for(int j=i; j<school::n-1; j++)
        sch[j]=sch[j+1];
    sch.pop_back();
    school::n--;
}

void delete_p(vector<school> &sch,int i)
{
    for(int j=i; j<school::m-1; j++)
    {
        school::name_sport[j]=school::name_sport[j+1];
        school::point_way[j]=school::point_way[j+1];
        school::sex_sport[j]=school::sex_sport[j+1];
    }
    school::m--;
}

void delete_(vector <school> &sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
    system("cls");
    cout<<"删除学校<s>        删除项目<p>"<<endl;
    string str;
l14:
    cin>>str;
    if(str[0]=='s'||str[0]=='S')
    {
        while(1)
        {
            int tem=-1;
            bool done=0;
            system("cls");
            cout<<"请输入要删除的学校名称或编号,#结束"<<endl;
            string str;
            cin>>str;
            if(str=="#") break;
            if('1'<=str[0]&&'9'>=str[0]&&(str[0]-'0'-1<school::n))
            {
                tem=str[0]-'0'-1;
                done=1;
            }
            if('0'<=str[1]&&'9'>=str[1]&&((str[0]-'0')*10+str[1]-'0'-1<school::n))
            {
                tem=(str[0]-'0')*10+str[1]-'0'-1;
                done=1;
            }
            for(int i=0; i<school::n; i++)
                if(str==sch[i].name_school)
                {
                    tem=i;
                    done=1;
                }
            if(done==0)
            {
                printf("%c",7);
                cout<<"没找到!"<<endl;
                Sleep(1500);
            }
            else
            {
                delete_s(sch,tem);
                cout<<"删除成功!"<<endl;
                Sleep(1500);
            }
        }
    }
    else if(str[0]=='p'||str[0]=='P')
    {
        while(1)
        {
            int tem=-1;
            bool done=0;
            system("cls");
            find_p_all_(sch);
            cout<<endl;
            cout<<"请输入要删除的项目名称或编号,#结束"<<endl;
            string str;
            cin>>str;
            if(str=="#") break;
            if('1'<=str[0]&&'9'>=str[0]&&(str[0]-'0'-1<school::m))
            {
                tem=str[0]-'0'-1;
                done=1;
            }
            if('0'<=str[1]&&'9'>=str[1]&&((str[0]-'0')*10+str[1]-'0'-1<school::m))
            {
                tem=(str[0]-'0')*10+str[1]-'0'-1;
                done=1;
            }
            for(int i=0; i<school::m; i++)
                if(str==school::name_sport[i])
                {
                    tem=i;
                    done=1;
                }
            if(done==0)
            {
                printf("%c",7);
                cout<<"没找到!"<<endl;
                Sleep(1500);
            }
            else
            {
                delete_p(sch,tem);
                cout<<"删除成功!"<<endl;
                Sleep(1500);
            }
        }
    }
    else
    {
        printf("%c",7);
        goto l14;
    }
    computer(sch);
    dis.set_sch(sch);
    change_if=1;
}

void find_ist_p_top_j(vector<school> sch,int i,int j)
{
    int a[MAX];
    for(int k=0; k<school::n; k++)
        a[k]=sch[k].point[i];
    cout<<school::name_sport[i]<<"  "<<school::point_way[i]<<":"<<endl
        <<setw(20)<<left<<"学校名称"
        <<setw(6)<<left<<"成绩"
        <<"积分"<<endl;
    for(int k=0; k<school::n; k++)
        cout<<setw(20)<<left<<sch[k].name_school
            <<setw(6)<<left<<sch[k].grade[i]
            <<sch[k].point[i]<<endl;
    cout<<"(所有学校)"<<endl;
    for(int k=0; k<school::n; k++)
    {
        int max=-1;
        int tem=0;
        for(int l=0; l<school::n; l++)
            if(a[l]>max&&a[l]>0)
            {
                max=a[l];
                tem=l;
            }
        a[tem]=0;
        if(max>0)
        cout<<setw(20)<<left<<sch[tem].name_school
            <<setw(6)<<left<<sch[tem].grade[i]
            <<sch[tem].point[i]<<endl;
    }
    cout<<"(前"<<j<<"名学校)"<<endl;
}
void find_p_(vector<school> sch,int tem)
{
    cout<<setw(2)<<left<<tem+1<<": "
        <<setw(16)<<left<<school::name_sport[tem]<<" "
        <<setw(2)<<left<<school::point_way[tem];
    if(school::sex_sport[tem]==0) cout<<"女 "<<endl;
    else cout<<"男 "<<endl;
}
void find_p(vector<school> sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
    int tem=-1;
    while(1)
    {
        bool done=0;
        system("cls");
        find_p_all_(sch);
        cout<<endl;
        if(tem>=0)
        {
            if(school::point_way[tem]==0)
                find_ist_p_top_j(sch,tem,min(school::n,5));
            else
                find_ist_p_top_j(sch,tem,min(school::n,3));
        }
        cout<<"请输入要查看的项目名称或编号,#结束"<<endl;
        string str;
        cin>>str;
        if(str=="#") break;
        if('1'<=str[0]&&'9'>=str[0]&&(str[0]-'0'-1<school::m))
        {
            tem=str[0]-'0'-1;
            done=1;
        }
        if('0'<=str[1]&&'9'>=str[1]&&((str[0]-'0')*10+str[1]-'0'-1<school::m))
        {
            tem=(str[0]-'0')*10+str[1]-'0'-1;
            done=1;
        }
        for(int i=0; i<school::m; i++)
            if(str==school::name_sport[i])
            {
                tem=i;
                done=1;
            }
        if(done==0)
        {
            printf("%c",7);
            cout<<"没找到!"<<endl;
            Sleep(1500);
        }
    }
}
void find_s(vector<school> sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
    int tem=-1;
    while(1)
    {
        bool done=0;
        system("cls");
        if(tem>=0)
        {
            cout<<sch[tem].name_school<<":"<<endl;
            cout<<setw(16)<<left<<"项目"
                <<setw(10)<<left<<"积分方式"
                <<setw(6)<<left<<"成绩"
                <<"积分"<<endl;
            for(int i=0; i<school::m; i++)
                cout<<setw(16)<<left<<school::name_sport[i]
                    <<setw(10)<<left<<school::point_way[i]
                    <<setw(6)<<left<<sch[tem].grade[i]
                    <<sch[tem].point[i]<<endl;
        }
        cout<<"请输入要查看学校名称或编号,#结束"<<endl;
        string str;
        cin>>str;
        if(str=="#") break;
        if('1'<=str[0]&&'9'>=str[0]&&(str[0]-'0'-1<school::n))
        {
            tem=str[0]-'0'-1;
            done=1;
        }
        if('0'<=str[1]&&'9'>=str[1]&&((str[0]-'0')*10+str[1]-'0'-1<school::n))
        {
            tem=(str[0]-'0')*10+str[1]-'0'-1;
            done=1;
        }
        for(int i=0; i<school::n; i++)
            if(str==sch[i].name_school)
            {
                tem=i;
                done=1;
            }
        if(done==0)
        {
            printf("%c",7);
            cout<<"没找到!"<<endl;
            Sleep(1500);
        }
    }
}

void find_p_all_(vector<school> sch)
{
    system("cls");
    for(int i=0; i<school::m; i++)
    {
        cout<<setw(2)<<left<<i+1<<": "
            <<setw(16)<<left<<school::name_sport[i]<<" "
            <<setw(2)<<left<<school::point_way[i];
        if(school::sex_sport[i]==0) cout<<"女 "<<endl;
        else cout<<"男 "<<endl;
    }

}
void find_p_all(vector<school> sch)
{
    if(school::n==0)
    {
        printf("%c",7);
        return ;
    }
    find_p_all_(sch);
    Sleep(1000);
    cout<<"输入任意字符继续"<<endl;
    Sleep(1500);
    find_p_all_(sch);
    string ss;
    cin>>ss;
}
void help_()
{
    system("cls");
    cout<<"     本程序为吉林大学计算机学院大二小学期实验题,花费本人数十个小时,程序中'<>'中的字母为可操作指令),以下下是原题:"<<endl
        <<endl
        <<"题目:运动会分数统计" <<endl
        <<"     参加运动会有 n 个学校,学校编号为 1……n。比赛分成 m 个男子项目和 w 个女子项目。项目编号为男子 1……m,女子 m+1……m+w。不同的项目取前五名或前三名积分;前五名的积分为:7、5、3、2、1,前三名的积分为:5、3、2;哪些取前五名或前三名由学生自己设定。(m<=20,n<=20)"<<endl
        <<"     1)可以输入各个项目的前三名或前五名的成绩"<<endl
        <<"     2)能统计各学校总分;"<<endl
        <<"     3)可以按学校编号或名称、学校总分、男女团体总分排序输出; "<<endl
        <<"     4)可以按学校编号查询学校某个项目的情况;可以按项目编号查询取得前三或前五名的学校; "<<endl
        <<"     5)数据存入文件并能随时查询; "<<endl
        <<"     6)其他要求: "<<endl
        <<"         (1)输入数据:可以输入学校的名称,运动项目的名称;"<<endl
        <<"         (2)输出形式:有中文提示,各学校分数为整型;"<<endl
        <<"         (3)界面要求:有合理的提示,使用者可根据提示,完成相关的功能要求;"<<endl
        <<"         (4)存储结构:根据系统功能要求自行设计,但是要求运动会的相关数据要存储在数据文件中,在实验报告中指明你用到的存储结构;"<<endl
        <<"         (5)测试数据:分别使用合法数据、非法数据进行程序测试,以保证程序的稳定,测试数据及测试结果请在实验报告中写明 "<<endl
        <<"输入任意字符结束!"<<endl;
    string str;
    cin>>str;
}

bool quit(vector<school> sch)
{
    system("cls");
    if(change_if==1)
    {
        if(path_now=="")
            cout<<"未保存!是否保存?"<<endl;
        else
            cout<<"内容已更改!是否保存?"<<endl;
        Sleep(1000);
        cout<<"<s>保存      <q>退出"<<endl;
        string str;
l4:
        cin>>str;
        if(str[0]=='s'||str[0]=='S')
        {
            save_(sch);
            return 1;
        }
        else if(str[0]=='q'||str[0]=='Q') return 1;
        else
        {
            printf("%c",7);
            goto l4;
        }
    }
    return 1;
}
int main()
{
    cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<欢迎使用运动会分数统计系统>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
    Sleep(2000);
    int tem1=0;
    vector<school> sch;
    while(1)
    {
        system("cls");
        toolbar_now(tem1)->toolbar_show();
        dis.show();
        string str;
        cin>>str;
        int t=toolbar_now(tem1)->get_tool_en(str);
        if(t)
        {
            if(tem1==0)
            {
                if(t==5)
                {
                    if(quit(sch)) exit(0);
                }
                else if(t==4) help_();
                else tem1=t;
            }
            else
            {
                if(str[0]=='B'||str[0]=='b') tem1=0;
                else if(tem1==1&&t==1) sch=new_();
                else if(tem1==1&&t==2) sch=open_();
                else if(tem1==1&&t==3) save_(sch);
                else if(tem1==1&&t==4) save_as(sch);
                else if(tem1==2&&t==1) insert_(sch);
                else if(tem1==2&&t==2) change_(sch);
                else if(tem1==2&&t==3) delete_(sch);
                else if(tem1==3&&t==1) find_s(sch);
                else if(tem1==3&&t==2) find_p(sch);
                else if(tem1==3&&t==3) find_p_all(sch);
            }
        }
        else if(dis.get_str(str))
        {
        }
        else
        {
            printf("%c",7);
            cout<<"指令不正确,请重新输入!"<<endl;
            Sleep(1500);
        }
    }
    return 0;
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值