求一个c++关于学生管理系统的代码

如题所述

等等,代码随后就到

---------------------------------

#include <bits/stdc++.h>

using namespace std;

struct txl

{

  string jlbh="无";//记录编号

  string xh="无";  //学号

  string xm="无";  //姓名

  string csrq="无";//出生日期(年,月)

  string xy="无";  //学院

  string zy="无";  //专业

  string nj="无";  //年级

  string bj="无";  //班级

} a[101];

int top=0;//人数

bool cmp(txl x,txl y)//排序

{

  if(x.xy==y.xy)

  {

    if(x.zy==y.zy)

    {

      if(x.nj==y.nj)

      {

        if(x.bj==y.bj)

        {

          if(x.xm==y.xm)

            return x.xh<y.xh;

          return x.xm<y.xm;

        }

        return x.bj<y.bj;

      }

      return x.nj<y.nj;

    }

    return x.zy<y.zy;

  }

  return x.xy<y.xy;

}

void jz()//加入人员

{

  if(top==100)//判断是否超出

  {

    cout<<"已有100人,请删除\n";

    return;

  }

  top++;//人数+1

  cout<<"请输入记录编号:";

  cin>>a[top].jlbh;

  cout<<"请输入学号:";

  cin>>a[top].xh;

  cout<<"请输入姓名:";

  cin>>a[top].xm;

  cout<<"请输入出生日期(年、月):";

  cin>>a[top].csrq;

  cout<<"请输入学院:";

  cin>>a[top].xy;

  cout<<"请输入专业:";

  cin>>a[top].zy;

  cout<<"请输入年级:";

  cin>>a[top].nj;

  cout<<"请输入班级:";

  cin>>a[top].bj;

  sort(a+1,a+top+1,cmp);

}

void cz()//删除人员

{

  string xh;

  cout<<"请输入删除者的学号:";

  cin>>xh;

  for(int i=1; i<=100; i++)

    if(a[i].xh==xh)

    {

      a[i].jlbh="无";

      a[i].xh="无";

      a[i].xm="无";

      a[i].csrq="无";

      a[i].xy="无";

      a[i].zy="无";

      a[i].nj="无";

      a[i].bj="无";

      top--;//信息归零,人数减一

    }

  sort(a+1,a+top+1,cmp);

}

void xg()//修改信息

{

  string xh,jlbh,xm,csrq,xy,zy,nj,bj;

  cout<<"请输入修改者的学号:";

  cin>>xh;

  cout<<"请输入修改后的记录编号:";

  cin>>jlbh;

  cout<<"请输入修改后的姓名:";

  cin>>xm;

  cout<<"请输入修改后的出生日期(年、月):";

  cin>>csrq;

  cout<<"请输入修改后的学院:";

  cin>>xy;

  cout<<"请输入修改后的专业:";

  cin>>zy;

  cout<<"请输入修改后的年级:";

  cin>>nj;

  cout<<"请输入修改后的:班级";

  cin>>bj;

  for(int i=1; i<=100; i++)

    if(a[i].xh==xh)

    {

      a[i].jlbh=jlbh;

      a[i].xm=xm;

      a[i].csrq=csrq;

      a[i].xy=xy;

      a[i].zy=zy;

      a[i].nj=nj;

      a[i].bj=bj;

    }

  sort(a+1,a+top+1,cmp);

}

void ck()//输出查看

{

  cout<<"  记录编号      学号    姓名  出生日期(年、月)    学院    专业    年级    班级\n";

  for(int i=1; i<=100; i++)

    if(a[i].xm!="无")

      printf

      (

        "%10s%10s%8s%20s%8s%8s%8s%8s\n",

        a[i].jlbh.c_str(),

        a[i].xh.c_str(),

        a[i].xm.c_str(),

        a[i].csrq.c_str(),

        a[i].xy.c_str(),

        a[i].zy.c_str(),

        a[i].nj.c_str(),

        a[i].bj.c_str()

      );

  cout<<"共计 "<<top<<" 人\n";

  getchar();

  getchar();

}

void sc()//生成文件

{

  ofstream outf;

  outf.open("学生管理系统.xls");

  outf<<"记录编号\t学号\t姓名\t出生日期(年、月)\t学院\t专业\t年级\t班级";

  for(int i=1; i<=100; i++)

    if(a[i].xm!="无")

      outf

          <<a[i].jlbh<<"\t"

          <<a[i].xh<<"\t"

          <<a[i].xm<<"\t"

          <<a[i].csrq<<"\t"

          <<a[i].xy<<"\t"

          <<a[i].zy<<"\t"

          <<a[i].nj<<"\t"

          <<a[i].bj<<"\n";

  outf<<"共计 "<<top<<" 人\n";

  outf.close();

  cout<<"生成成功!\n";

  getchar();

  getchar();

}

int main()

{

  while(1)

  {

    system("cls");

    cout<<"学生管理系统\n";

    cout<<" 1.新增成绩\n";

    cout<<" 2.删除成绩\n";

    cout<<" 3.修改成绩\n";

    cout<<" 4.查看成绩\n";

    cout<<" 5.生成表格\n";

    int a;

    cin>>a;

    if(a==1)

      jz();

    else if(a==2)

      cz();

    else if(a==3)

      xg();

    else if(a==4)

      ck();

    else if(a==5)

      sc();

    else

    {

      cout<<"输入错误!\n";

      getchar();

      getchar();

    }

  }

  return 0;

}

------------------------

时间紧凑,如有BUG,请回复

效果图:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-01-10
到网页上去搜吧,很多的,将别人的改一下即可,没谁会给你弄一个和你需求一致的。
相似回答