数据结构课程设计(考试管理系统)

为考试报名管理人员编写一个考试报名管理系统 ,用菜单选择方式完成下列功能:

1.考生报名信息添加:包括准考证号、姓名、性别、年龄、学院、专业、班级、身份证号、报考科目(eg. CET4/CET6)等。

2.考生报名信息查询:分别按姓名、学院、专业、班级、报考科目等进行查询。

3.排序:分别根据姓名、年龄、学院等按升序进行排序。

4.考生报名信息的修改、删除:按准考证号进行考生信息的修改和删除。


长期手懒,现在写的程序越来越瓜皮了。

先贴一个cpp文件

#include
#include
#include
#include
#include
#include
#include"datastructure.h"
using namespace std;
#define maxn 1000
int menu()
{
    cout<<"\t\t欢迎来到考试报名系统!选择你想要的服务"<     cout<<"\t\t\t 1.考生报名信息添加"<     cout<<"\t\t\t 2.考生报名信息查询"<     cout<<"\t\t\t 3.考生排序"<     cout<<"\t\t\t 4.考生信息修改和删除"<     return 0;
}
int ask(char ch)
{
    cout<<"是否继续此操作?(y/n)"<     ch=getche();
    if(ch=='y')
    {
    system("cls");
    menu();
    return 1;
    }
    else
    {
    system("cls");
    menu();
    return 0;
    }
}
int InitList(SQL &L)
{
        L.s = new CET[maxn];
        if (!L.s) exit(-1);
        else
                L.length = 0;
        return 0;
}
int add(SQL &L,int i)
{
        cout << "请输入第"<         cout << "准考证号:" << endl;
        cin >> L.s[L.length].adcard;
        cout << "姓名:" << endl;
        cin >> L.s[L.length].name;
        cout << "性别:" << endl;
        cin >> L.s[L.length].sex;
        cout << "年龄:" << endl;
        cin >> L.s[L.length].age;
        cout << "学院:" << endl;
        cin >> L.s[L.length].academy;
        cout << "专业:" << endl;
        cin >> L.s[L.length].major;
        cout << "班级:" << endl;
        cin >> L.s[L.length].grade;
        cout << "身份证号:" << endl;
        cin >> L.s[L.length].idcard;
        cout << "报考科目:" << endl;
        cin >> L.s[L.length].subject;
        ++L.length;
        cout<<"信息添加成功!"<         return 0;
}
int print_info(SQL &L, int i)
{
        cout << "姓名:  " << L.s[i].name << endl;
        cout << "准考证号:  " << L.s[i].adcard << endl;
        cout << "年龄:  " << L.s[i].age << endl;
        cout << "性别:  " << L.s[i].sex << endl;
        cout << "学院:  " << L.s[i].academy << endl;
        cout << "专业:  " << L.s[i].major << endl;
        cout << "班级:  " << L.s[i].grade << endl;
        cout << "身份证号:  " << L.s[i].idcard << endl;
        cout << "报考科目:  " << L.s[i].subject << endl<         return 0;
}

int besearch(SQL &L)
{
        bool flag = false;
        string s;
        cout << "填入你要查找的信息:" << endl;
        cout << "1.   姓名"<         cin >> s;
        getchar();
        for (int i = 0; i < L.length; i++)
        {
            if ((L.s[i].name == s||L.s[i].academy==s||L.s[i].major==s||L.s[i].subject==s)&&L.s[i].have)
                {
                flag = true;
                print_info(L, i);
                }
        }
        if (!flag) cout << "查找失败!" << endl;
        return 0;
}
int sort_info(SQL &L)
{
    char op;
    cout<<"1.  按姓名排序"<     cin>>op;
    if(op=='1')
    {
        for(int i=0;i             for(int j=0;j             if(L.s[j].name             {
            CET* p=new CET;
            *p=L.s[j];
            L.s[j]=L.s[j+1];
            L.s[j+1]=*p;
            }
    }
    if(op=='2')
    {
        for(int i=0;i             for(int j=0;j             if(L.s[j].age             {
            CET* p=new CET;
            *p=L.s[j];
            L.s[j]=L.s[j+1];
            L.s[j+1]=*p;
            }
    }
    return 0;
}
int modify(SQL &L)
{
    bool flag = false;
    string s;
    char op,op2;
    int i;
    cout<<"选择你所需要的服务:"<     cin>>op;
    cout<<"输入准考证号:"<     cin>>s;
    for (i = 0; i < L.length; i++)
    {
        if (L.s[i].adcard == s&&L.s[i].have)
        {
        flag = true;
        print_info(L, i);
        }
    }
    if (!flag) {cout << "查找失败!" << endl; return -1;}
    if(op=='1')
    {
        cout<<"选择你需要修改的项目!"<         cout << "1.   姓名"<         cout << "6.   学院"<         op2=getchar();
        switch(op2)
        {
            case '1': cout << "性别:" << endl;cin >> L.s[i].sex; break;
            case '2': cout << "年龄:" << endl;cin >> L.s[i].age; break;
            case '3': cout << "性别:" << endl;cin >> L.s[i].sex; break;
            case '4': cout << "身份证号:" << endl;cin >> L.s[i].idcard; break;
            case '5': cout << "准考证号:" << endl;cin >> L.s[i].adcard; break;
            case '6': cout << "学院:" << endl;cin >> L.s[i].academy; break;
            case '7': cout << "专业:" << endl;cin >> L.s[i].major; break;
            case '8': cout << "班级:" << endl;cin >> L.s[i].grade; break;
            case '9': cout << "报考科目:" << endl;cin >> L.s[i].subject; break;
        }
        cout<<"修改成功!"<     }
    if(op=='2')
    {
    L.s[i].have=false;
    cout<<"删除成功!"<     }
    return 0;
}



然后main文件
#include
#include
#include
#include
#include
#include
#include"datastructure.h"
using namespace std;
int main()
{
    int n;
    char op,ch;
    SQL L;
 InitList(L);
    menu();
 while(cin>>op)
    {
    if(op=='1')
    {
        for(;;)
        {
        cout<<"\t请输入学生人数!"<         cin>>n;
        for(int i=0;i         add(L,i+1);
        if(!ask(ch)) break;
        }
    }
    else if(op=='2')
    {
        for(;;)
        {
            besearch(L);
            if(!ask(ch)) break;
        }
    }
    else if(op=='3')
    {
        for(;;)
        {
        sort_info(L);
        cout<<"排序成功,是否需要输出?(y/n)"<         char c;
        cin>>c;
        if(c=='y')
        for (int i = 0; i < L.length; i++)
        print_info(L,i);
        if(!ask(ch)) break;
        }
    }
    else if(op=='4')
    {
        for(;;)
        {
        modify(L);
        if(!ask(ch)) break;
        }
    }
    else    {cout<<"输入错误,请重新输入!\n";continue;}
    }
 return 0;
}

最后头文件
#ifndef DATASTRUCTURE_H_INCLUDED
#define DATASTRUCTURE_H_INCLUDED
#include
#include
#include
using namespace std;
struct CET
{
    bool have=true;
 string adcard,name,sex,academy,major,idcard,subject;
 int age,grade;
};
struct SQL
{
 CET *s;
 int length;
};
int menu();
int ask(char ch);
int InitList(SQL &L);
int add(SQL &L,int i);
int print_info(SQL &L,int i);
int besearch(SQL &L);
int sort_info(SQL &L);
int modify(SQL &L);

#endif // DATASTRUCTURE_H_INCLUDED

你可能感兴趣的:(数据结构)