最简单最实用的C语言/C++ 学生管理系统(非常合适初学者)

#include"fstream.h"
#include"windows.h"
#include<stdio.h>
#include"string.h"
#include"cc.h"
struct stu
{
    char name[50];
    char gender[70];
    int stunum;
    double chinese;
    double math;
    double english;
}stu[100],x,y;

 

void choose();
void face();
void dayin();
void maxscore();
void scoreface();
void appstudent();
void addstudent();
void revisestudent();
void seekstudent();
void deletestudent();
void overstudent();
void revisestudent();


void addstudent()//******************录入信息
{    
    int flag;
    fstream file;
    system("cls");
    cout<<"    ------------------------------"<<endl;
    cout<<"    |请问您要录入几个学生的信息?|"<<endl;
    cout<<"    ------------------------------"<<endl;
    cout<<"请输入:";
    file.open("E:/flag.txt",ios::in|ios::out|ios::binary);
    cin>>flag;
    file.write((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::out|ios::binary);
    for(int i=0;i<flag;i++)
    {
        cout<<"-----------------------------------"<<endl;
        cout<<"请输入第"<<i+1<<"个学生的姓名:";
        cin>>x.name;
        cout<<"请输入第"<<i+1<<"个学生的性别:";
        cin>>x.gender;
        cout<<"请输入第"<<i+1<<"个学生的学号:";
        cin>>x.stunum;
        cout<<"请输入第"<<i+1<<"个学生的语文成绩:";
        cin>>x.chinese;
        cout<<"请输入第"<<i+1<<"个学生的数学成绩:";
        cin>>x.math;
        cout<<"请输入第"<<i+1<<"个学生的英语成绩:";
        cin>>x.english;
        
        cout<<"-----------------------------------"<<endl;
        file.write((char*)&x,sizeof(x));
    }
    file.close();
    face();
}
void appstudent()//******************添加信息
{
    int k,flag;
    fstream file;
    system("cls");
    cout<<"请问你要添加几个人的信息?"<<endl;
    cout<<"请输入:";
    cin>>k;
    file.open("E:/flag.txt",ios::in|ios::out|ios::binary);
    file.read((char*)&flag,sizeof(flag));
    flag=flag+k;
    file.seekg(0,ios::beg);
    file.write((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::out|ios::in|ios::binary|ios::app);
    for(int i=0;i<k;i++)
    {
        cout<<"-----------------------------------"<<endl;
        cout<<"请输入添加的第"<<k<<"个学生的姓名:";
        cin>>x.name;
        cout<<"请输入添加的第"<<k<<"个学生的性别:";
        cin>>x.gender;
        cout<<"请输入添加的第"<<k<<"个学生的学号:";
        cin>>x.stunum;
        cout<<"请输入添加的第"<<k<<"个学生的语文成绩:";
        cin>>x.chinese;
        cout<<"请输入添加的第"<<k<<"个学生的数学成绩:";
        cin>>x.math;
        cout<<"请输入添加的第"<<k<<"个学生的英语成绩:";
        cin>>x.english;
        file.write((char*)&x,sizeof(x));
    }
    file.close();
    system("cls");
    face();

}
void revisestudent()//***************修改信息
{
        int n,flag,i,k=0,m;
    fstream file;
    cout<<"    --------------------------------"<<endl;
    cout<<"    |请问您要修改的学生学号是多少?|"<<endl;
    cout<<"    --------------------------------"<<endl;
    cout<<"请输入:";
    cin>>n;
    file.open("E:/flag.txt",ios::in|ios::out);
    file.read((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::in|ios::out|ios::binary);
    for(i=0;i<=flag;i++)
    {
        file.read((char*)&stu[i],sizeof(stu[i]));
    }
    file.close();
    for(k;k<flag;k++)
    {
        if(stu[k].stunum==n)
        {
            cout<<"请重新输入这个学生的姓名:";
            cin>>stu[k].name;
            cout<<"请重新输入这个学生的性别:";
            cin>>stu[k].gender;
            cout<<"请重新输入这个学生的学号:";
            cin>>stu[k].stunum;
            cout<<"请重新输入这个学生的语文成绩:";
            cin>>stu[k].chinese;
            cout<<"请重新输入这个学生的数学成绩:";
            cin>>stu[k].math;
            cout<<"请重新输入这个学生的英语成绩:";
            cin>>stu[k].english;
            cout<<"修改完毕"<<endl;
            system("pause");
            file.open("E:/student.txt",ios::out|ios::binary);
            for(m=0;m<flag;m++)
            {
                file.write((char*)&stu[m],sizeof(stu[m]));
            }
            file.close();
            face();
        }
        
        
        
    }
    if(stu[k].stunum!=n)
        {
            cout<<"您的输入有误!"<<endl;
            system("pause");
            face();
        }
    
}
void seekstudent()//*****************查找信息
{
    fstream file;
    int n,flag,i=0,k=0;
    system("cls");
    cout<<"    --------------------------------"<<endl;
    cout<<"    |请问您要查找的学生学号是多少?|"<<endl;
    cout<<"    --------------------------------"<<endl;
    cout<<"请输入:";
    cin>>n;
    file.open("E:/flag.txt",ios::in|ios::out);
    file.read((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::in|ios::out|ios::binary);
    for(i=0;i<=flag;i++)
    {
        file.read((char*)&stu[i],sizeof(stu[i]));
    }
    file.close();
    for(k;k<flag;k++)
    {
        if(stu[k].stunum==n)
        {
                cout<<"这个学生的资料如下:"<<endl;
                cout<<"-------------------------"<<endl;
                cout<<"姓名:       "<<stu[k].name<<endl;
                cout<<"性别:       "<<stu[k].gender<<endl;
                cout<<"学号:       "<<stu[k].stunum<<endl;
                cout<<"语文成绩:   "<<stu[k].chinese<<endl;
                cout<<"数学成绩:   "<<stu[k].math<<endl;
                cout<<"英语成绩:   "<<stu[k].english<<endl;
                cout<<"-------------------------"<<endl;
                system("pause");
                face();
        }
        }
        
        if(stu[k].stunum!=n)
        {
            system("cls");
            cout<<"查无此人!"<<endl;
            choose();
        }
    

}
void sortstudent()//*****************排序信息
{
    int flag;
    fstream file; 
    file.open("E:/flag.txt",ios::in|ios::out);
    file.read((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::in|ios::binary);    
    for(int i=0;i<=flag;i++)
    {
        file.read((char*)&stu[i],sizeof(stu[i]));
    }

    for(i=0;i<flag-1;i++)
        for(int j=i+1;j<flag;j++)
         {
            if (stu[i].stunum>stu[j].stunum)
            {
                y=stu[i];
                stu[i]=stu[j];
                 stu[j]=y;
              }
         }
    file.close();
    file.open("E:/student.txt",ios::out|ios::trunc|ios::binary);
    for(i=0;i<flag;i++)
    {
        file.write((char*)&stu[i],sizeof(stu[i]));
    }
    file.close();
    cout<<"排序完毕!"<<endl;
    system("pause");
    face();

}
void deletestudent()//***************删除信息
{
    char c;
    int flag;
    int n;
    fstream file; 
    cout<<"请输入您要删除的学生的学号!"<<endl;
    cout<<"请输入:";
    cin>>n;
    file.open("E:/flag.txt",ios::in|ios::out);
    file.read((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::in|ios::out|ios::binary);    
    for(int i=0;i<=flag;i++)
    {
        file.read((char*)&stu[i],sizeof(stu[i]));
    }
    for(int k=0;k<flag;k++)
    {
        if(stu[k].stunum==n)
        {
            cout<<" -----------------------"<<endl;
            cout<<"|  Y:删除  N:不删除   |"<<endl;
            cout<<" -----------------------"<<endl;
            cin>>c;
            flag=flag-1;
            if (c == 'Y')
            {
                for(int j=k;j<flag;j++)
                {
                    stu[j]=stu[j+1];
                }
            }
            else
            {
                face();
            }
        }    
    }
    file.close();
    file.open("E:/flag.txt",ios::in|ios::binary|ios::out);
    
    file.seekg(0,ios::beg);
    file.write((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::out|ios::trunc|ios::binary);
    for(int m=0;m<flag;m++)
    {
        file.write((char*)&stu[m],sizeof(stu[m]));
    }
    file.close();
    cout<<"动作完成!"<<endl;
    system("pause");
    face();

}
void overstudent()//*****************浏览信息
{
    int flag;
    system("cls");
    fstream file;
    file.open("E:/flag.txt",ios::in|ios::out);
    file.read((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::in|ios::binary);
    for(int i=0;i<flag;i++)
    {
        file.read((char*)&stu[i],sizeof(stu[i]));
        cout<<"      -------第"<<i+1<<"位学生---------"<<endl;
        cout<<"      -------------------------"<<endl;
        cout<<"      姓名:       "<<stu[i].name<<endl;
        cout<<"      性别:       "<<stu[i].gender<<endl;
        cout<<"      学号:       "<<stu[i].stunum<<endl;
        cout<<"      语文成绩:   "<<stu[i].chinese<<endl;
        cout<<"      数学成绩:   "<<stu[i].math<<endl;
        cout<<"      英语成绩:   "<<stu[i].english<<endl;
        cout<<"      -------------------------"<<endl;
    }
    file.close();
    system("pause");
    system("cls");
    face();
}
void scoreface()
{
    int i;
    system("cls");
    BLACK_GREEN;cout<<"---------------------------------------------------"<<endl;
    BLACK_RED;cout<<"     〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
    BLACK_YELLOW;cout<<"    ●++++★◤  【1→打印  学生  成绩】  ◥★++++●"<<endl;
    BLACK_BLUE;cout<<"    ▍ ++++★   【2→最高分数与平均分】   ★++++  ▍"<<endl;
    BLACK_WHITE;cout<<"    ▍  ++★    【3→返回主      界面】    ★++   ▍"<<endl;
    BLACK_GREEN;cout<<"    ●++++★◣  【0→退 出      系 统】  ◢★++++●"<<endl;
    BLACK_RED;cout<<"      〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
    BLACK_GREEN;cout<<"    ----------------------------"<<endl;
    cout<<"    | 要输入对应的序号进行选择 |"<<endl;
    cout<<"    ----------------------------"<<endl;
    cout<<"请输入:";
    cin>>i;
    switch(i)
    {
        case 1:
            dayin();
            break;
        case 2:
            maxscore();
            break;
        case 3:
            face();
            break;
        case 0:
            exit(0);
            break;
        default:
            cout<<"选择有误!请重新选择!"<<endl;
            system("pause");
            face();
    }
}
void dayin()
{
    int flag;
    system("cls");
    fstream file;
    file.open("E:/flag.txt",ios::in|ios::out);
    file.read((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::in|ios::binary);
    for(int i=0;i<flag;i++)
    {
        file.read((char*)&stu[i],sizeof(stu[i]));
        cout<<"      -------第"<<i+1<<"位学生---------"<<endl;
        cout<<"      -------------------------"<<endl;
        cout<<"      姓名:       "<<stu[i].name<<endl;
        cout<<"      语文成绩:   "<<stu[i].chinese<<endl;
        cout<<"      数学成绩:   "<<stu[i].math<<endl;
        cout<<"      英语成绩:   "<<stu[i].english<<endl;
        cout<<"      -------------------------"<<endl;
    }
    file.close();
    system("pause");
    system("cls");
    face();
}
void maxscore()
{
    int flag;
    double maxchinese,maxmath,maxenglish;
    double pchinese=0,pmath=0,penglish=0;
    system("cls");
    fstream file;
    file.open("E:/flag.txt",ios::in|ios::out);
    file.read((char*)&flag,sizeof(flag));
    file.close();
    file.open("E:/student.txt",ios::in|ios::binary);
    for(int i=0;i<flag;i++)
    {
        file.read((char*)&stu[i],sizeof(stu[i]));
        maxchinese=stu[0].chinese;
        maxmath=stu[0].math;
        maxenglish=stu[0].english;
        if(maxchinese<stu[i].chinese)
        {
            maxchinese=stu[i].chinese;
        }
        if(maxmath<stu[i].math)
        {
            maxmath=stu[i].math;
        }
        if(maxenglish<stu[i].english)
        {
            maxenglish=stu[i].english;
        }
        
        pchinese+=stu[i].chinese;
        pmath+=stu[i].math;
        penglish+=stu[i].english;
    }
    cout<<"      -------------------------"<<endl;
    cout<<"      语文成绩的最高分为:"<<maxchinese<<endl;
    cout<<"      语文成绩的平均分为:"<<pchinese/flag<<endl;
    cout<<"      数学成绩的最高分为:"<<maxmath<<endl;
    cout<<"      数学成绩的平均分为:"<<pmath/flag<<endl;
    cout<<"      英语成绩的最高分为:"<<maxenglish<<endl;
    cout<<"      英语成绩的平均分为:"<<penglish/flag<<endl;
    cout<<"      -------------------------"<<endl;
    file.close();
    system("pause");
    system("cls");
    face();
}
/*-------------------------主界面*/
void face()
{
    int i;
    system("cls");
    cout<<"Welcome to the student information management system!"<<endl;
    BLACK_GREEN;cout<<"---------------------------------------------------"<<endl;
    BLACK_RED;cout<<"     〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
    BLACK_YELLOW;cout<<"    ●++++★◤  【1→录入学生信息】  ◥★++++●"<<endl;
    BLACK_BLUE;cout<<"    ▍ ++++★   【2→添加学生信息】   ★++++  ▍"<<endl;
    BLACK_WHITE;cout<<"    ▍  ++★    【3→修改学生信息】    ★++   ▍"<<endl;
    BLACK_GREEN;cout<<"    ▍   ★     【4→查找学生信息】     ★    ▍"<<endl;
    BLACK_RED;cout<<"    ▍   ★     【5→排序学生信息】     ★    ▍"<<endl;
    BLACK_YELLOW;cout<<"    ▍  ++★    【6→删除学生信息】    ★++   ▍"<<endl;
    BLACK_BLUE;cout<<"    ▍ ++++★   【7→浏览学生信息】   ★++++  ▍"<<endl;
    BLACK_GREEN;cout<<"    ▍ ++++★   【8→学生成绩信息】   ★++++  ▍"<<endl;
    BLACK_WHITE;cout<<"    ●++++★◣  【0→退 出  系 统】  ◢★++++●"<<endl;
    BLACK_RED;cout<<"      〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
    BLACK_GREEN;cout<<"    ----------------------------"<<endl;
    cout<<"    | 要输入对应的序号进行选择 |"<<endl;
    cout<<"    ----------------------------"<<endl;
    cout<<"请输入:";
    cin>>i;
    switch(i)
    {
        case 1:
            addstudent();
            break;
        case 2:
            appstudent();
            break;
        case 3:
            revisestudent();
            break;
        case 4:
            seekstudent();
            break;
        case 5:
            sortstudent();
            break;
        case 6:
            deletestudent();
            break;
        case 7:
            overstudent();
            break;
        case 8:
            scoreface();
                break;
        case 0:
            exit(0);
            break;
        default:
            cout<<"选择有误!请重新选择!"<<endl;
            system("pause");
            face();
    }
}


void choose()
{
    char c;
    cout<<" -----------------------"<<endl;
    cout<<" |  Y:继续  N:返回   |"<<endl;
    cout<<" -----------------------"<<endl;
    cin>>c;
    if(c=='Y'||c=='y')
        seekstudent();
    else if(c=='N'||c=='n')
        face();
    else
        choose();
}
void main(void)
{
    face();
}

 

 

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值