高校学籍管理系统

#include<iostream.h>

#include<string.h>

#include<fstream.h>

#include<iomanip.h>  

#include<windows.h>                   

class student                           

{protected:                             

int number;                                //学号

char name[20];                             //姓名

char sex[6];                               //性别

char place[20];                            //籍贯

char nation[6];                            //民族

char birth[20];                            //出生日期

char party[10];                            //政治面貌

char id[20];                               //身份证号

char mail[20];                             //邮箱

float score[3];                            //成绩

public:                             

student *next;                     

student(){ }                     

~student(){ }                       

char* getname(){ return name; }               

int getnumber(){ return number;}

float getscore(int i) { return score[i];}

float getg(){ return (score[0]+score[1]+score[2]); }

//录入信息

void input()

{int e=1;

cout<<"按提示输入:"<<endl;

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

cin>>number;

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

cin>>name;

do

{cout<<"请输入性别: ";

  cin>>sex;

  if(strcmp(sex,"男")==0 || strcmp(sex,"女")==0)

  {cout<<"请输入籍贯: ";

    cin>>place;

    cout<<"请输入民族: ";

    cin>>nation;

    cout<<"请输入生日: ";

    cin>>birth;

    cout<<"请输入政治面貌: ";

    cin>>party;

    cout<<"请输入身份证号: ";

cin>>id;

cout<<"请输入邮箱: ";

cin>>mail;

    cout<<"请输入数学分数: ";

    cin>>score[0];

    cout<<"请输入英语分数: ";

    cin>>score[1];

    cout<<"请输入计算机分数: ";

    cin>>score[2];

    e=0;}

    else

  {cout<<"无此类型性别!重新输入!"<<endl;

    e=1;}}while(e);return ;}

void input(ifstream & is)                   

{is>>number>>name>>sex>>place>>nation>>birth>>party>>id

  >>score[0]>>score[1]>>score[2];

is.get();                         }

//显示信息

void output()

{cout<<"学生基本信息如下:"<<endl;

cout<<" 编号:"<<number

    <<" 姓名:"<<name

    <<" 性别:"<<sex

   <<" 籍贯:"<<place

   <<" 民族:"<<nation

   <<" 生日:"<<birth

   <<" 政治面貌:"<<party<<endl

   <<" 身份证号:"<<id

   <<" 邮箱:"<<mail

   <<" 数学:"<<score[0]

   <<" 英语:"<<score[1]

   <<" 计算机:"<<score[2]

   <<" 总分:"<<getg()<<endl<<endl;}

void output(ofstream & os)               

{os<<setw(6)<<number

  <<setw(15)<<name

  <<setw(6)<<sex

  <<setw(20)<<place

  <<setw(6)<<nation

  <<setw(20)<<birth

  <<setw(20)<<party

  <<setw(20)<<id 

  <<setw(20)<<mail

  <<setw(6)<<score[0]

  <<setw(6)<<score[1]

  <<setw(6)<<score[2]<<endl;}};

class school                           

{public:                               

school(){ head=new student; head->next=NULL; key=0; }

~school(){ delete head; }                   

void input();                                    //录入函数

void mend();                                     //修改函数

void del();                                      //删除函数

int find(student **p,int num,char *pn="^");      //子查找函数

void found();                                    //查找函数

void show();                                     //显示函数

void count();                                    //统计函数

void save();                                     //保存函数

void begin();                                    //初始化函数

void clear();                                    //清空函数

char mainmenu();                                 //主菜单函数

int getkey(){ return key;}

void setkey(int k){ key=k; }

private:                             

  student *head;                       int key;};//录入函数

void school::input()

{student *p,*p2=NULL;

p=head;                             

int n;

while(p->next)

p=p->next;

while(n)

{ p2=new student;

  p2->input();

  p->next=p2;

  p2->next=NULL;

  p=p->next;                       

school::setkey(1);

  cout<<"按1继续,按0返回 : ";

  cin>>n;}}//子查找函数

int school::find(student **p1,int num,char *pn)

{ student *p; p=head;

while(p->next)

{(*p1)=p;

 if( (p->next)->getnumber()==num||!strcmp( (p->next)->getname(),pn ) )

 return 1;

 p=p->next;}

return 0;}//查找函数

void school::found()

{student *p;

int num=-1,n=9;

char name[20]="^";

do

{ cout<<"1:按编号查找,2:按姓名查找: ";

  cin>>n;

}while(n<1||n>2);

if(n==1)

{cout<<"请输入编号: ";

  cin>>num;}

if(n==2)

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

cin>>name;}

if(!find(&p,num,name) )

{cout<<"SORRY!找不到你要查找的内容!"<<endl;

return;}

(p->next)->output();}

//删除函数

void school::del()

{student *p,*p2;

int num;

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

cin>>num;

if( !find(&p,num,"^") )

{cout<<"SORRY!找不到你要删除的内容!"<<endl;

return;}

(p->next)->output();

p2=p->next;

p->next=p2->next;

delete p2;

school::setkey(1);}

//显示函数

void school::show()

{student *p;p=head;

while(p->next)

{(p->next)->output();

p=p->next;}}//修改函数

void school::mend()

{student *p;

int num=-1,n;

char name[20]="^";

do

{ cout<<"1:按编号修改,2:按姓名修改: ";

  cin>>n;

}while(n<1||n>2);

if(n==1)

{cout<<"请输入编号: ";

  cin>>num;}

if(n==2)

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

cin>>name;}

if( !find(&p,num,name) )

{cout<<"SORRY!找不到你要修改的内容!"<<endl;

return;}

(p->next)->output();

(p->next)->input();

school::setkey(1);}//保存函数

void school::save()

{student *p;

p=head;

ofstream os("student.txt",ios::out);

if (school::getkey()==1)

{ while(p->next)

{ (p->next)->output(os);

    p=p->next;}}

cout<<"文件已保存! "<<endl;

school::setkey(0);}

//初始化函数

void school::begin()

{student *p,*p2;

p=head;

clear();

long t;

ifstream is("student.txt",ios::in); 

if(!is)

{ofstream os("student.txt",ios::out);

os.close();

return ;}

int num=-1;

while(1)

{ num=-1;

  t=is.tellg();

  is>>num;

is.seekg(t);

  if(num<0)

{ is.close();

  return;}

p2=new student;

p2->input(is);

p->next=p2;

p2->next=NULL;

p=p->next;}}

//清空函数 

void school::clear()

{student *p,*p2;

p=head->next;

while( p )

{p2=p;

p=p->next;

delete p2;}}

//统计函数     

void school::count()

{student *p;

p=head;

int n=0;

double g[3]={0,0,0};

float j[3]={0,0,0};

while(p->next)

{ p=p->next; 

  n++;

  for(int i=0;i<3;i++)

  { g[i]=g[i]+(p->getscore(i) );

  (p->getscore(i) )>=60? i++ : 0 ;}}

cout<<"数学总分:"<<g[0]<<" 平均分:"<<g[0]/n

<<" 及格率:"<<j[0]/n<<endl<<"英语总分:"<<g[1]

<<" 平均分:"<<g[1]/n<<" 及格率:"<<j[1]/n<<endl

<<"计算机总分: "<<g[2]<<" 平均分: "<<g[2]/n

<<" 及格率:"<<j[2]/n<<endl;}

//主选菜单函数

char school::mainmenu()

{char n[6];

cout<<"\n\n       ☆☆☆☆欢迎进入高校学籍管理系统☆☆☆☆"<<endl<<endl

<<"     * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl

<<"     * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl

<<"     * *         1:   录入学生信息           * *"<<endl

<<"     * *         2:   显示学生信息           * *"<<endl

<<"     * *         3:   查找学生信息           * *"<<endl

<<"     * *         4:   删除学生信息           * *"<<endl

<<"     * *         5:   修改学生信息           * *"<<endl

<<"     * *         6:   统计学生成绩           * *"<<endl

<<"     * *         7:   保存学生信息           * *"<<endl

<<"     * *         0:   退出系统               * *"<<endl

<<"     * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl

<<"     * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl

<<"                 请选择:";

cin>>n;

return n[0];}

//主函数

void main()

{int i;

for(i=0;i<1;i++)

{system("color  5A");Sleep(100);}

school p;

int k=1;

char n;

p.begin();

while(k==1)

{n=p.mainmenu();

switch(n)

{ case '1':p.input(); break;

  case '2':p.show(); break;

  case '3':p.found(); break;

  case '4':p.del(); break;

  case '5':p.mend(); break;

  case '6':p.count(); break;

  case '7':p.save(); break;

  case '0':

  if(p.getkey()==1)

  {cout<<"\t\t\t是否保存? 1 : 保存 0:不保存 : ";

  cin>>k;

  if(k==1)

    p.save();}

  p.clear();

  k=0;

  break;}}}

 

  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值