C++如何实现学生信息管理系统(C++,开发技术)

时间:2024-05-03 08:33:25 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

实现功能

C++如何实现学生信息管理系统

上面的功能基本完全实现

目前的程序其实还存在两个问题:

1、无法从文件中读取信息,我感觉是格式问题,输出的格式需要改,但是这样的话,保存在文件的信息看起来就不是很方便了
2、保存新同学的学号与当前记录的学号相同时不会提醒,这个实现起来比较容易,在保存的时候,再加一个链表查询就可以了,是我太懒了。

源码附上

#include<cstdlib>#include<iostream>#include<string>#include<windows.h>#include<conio.h>#include<fstream>usingnamespacestd;#definenullNULLclassstudent{private:intflag;friendclassstudentMessage;student*next;//节点指针stringname;//学生姓名stringaddress;//家庭住址intage;//年龄intid;//学号stringsex;chargrade;班级//A代表大学生//B代表中学生//C代表小学生doublechinese,math,english;//语文,数学,英语doublehistory,geography;//历史,地理stringmajor;longlongintTL;//专业,电话public:staticintnum_total;//总数staticintnum_sex;staticintnum_age;//小学生初始化student(int_id,string_name,string_sex,int_age,char_grade,double_chinese,double_math,double_english){name=_name;grade=_grade;age=_age;sex=_sex;id=_id;chinese=_chinese;math=_math;english=_english;next=NULL;}//初中生初始化student(int_id,string_name,string_sex,int_age,char_grade,double_geography,double_history,string_address){name=_name;grade=_grade;age=_age;sex=_sex;id=_id;geography=_geography;history=_history;address=_address;next=NULL;}//大学生初始化student(int_id,string_name,string_sex,int_age,char_grade,string_major,string_address,longlongint_TL){name=_name;grade=_grade;age=_age;sex=_sex;id=_id;major=_major;address=_address;TL=_TL;next=NULL;}//构造函数student()//为studentMessage初始化头结点用{name="null";sex="null";address="null";age=0;id=0;chinese=0;math=0;english=0;grade='0';geography=0;history=0;major="null";TL=0;next=NULL;}~student(){}voidswap(student*);};intstudent::num_total=0;初始化intstudent::num_sex=0;intstudent::num_age=0;voidstudent::swap(student*q){string_name,_sex,_address;int_age,_id;chargrade;班级//A代表大学生//B代表中学生//C代表小学生double_chinese,_math,_english;//语文,数学,英语double_history,_geography;//历史,地理string_major;longlongint_TL;//专业,电话_chinese=chinese;chinese=q->chinese;q->chinese=_chinese;_math=math;math=q->math;q->math=_math;_english=english;english=q->english;q->english=_english;_history=history;history=q->history;q->history=_history;_geography=geography;geography=q->geography;q->geography=_geography;_major=major;major=q->major;q->major=_major;_TL=TL;TL=q->TL;q->TL=_TL;_name=name;name=q->name;q->name=_name;_sex=sex;sex=q->sex;q->sex=_sex;_address=address;address=q->address;q->address=_address;_age=age;age=q->age;q->age=_age;_id=id;id=q->id;q->id=_id;}classstudentMessage{private:student*first;//头指针intnum;//信息中的学生人数public:studentMessage(){num=0;//初始化学生人数为0first=newstudent;//初始化头结点}~studentMessage(){deletefirst;}/*管理系统常规操作*/voidInsret(void);//插入voidDisplay(void);//显示voidDelete(void);//删除voidSearch(void);//搜索voidChange(void);//改动voidSearchByid(void);//按照学号查找voidSearchByname(void);//按照姓名查找intmenu(void);//初始的菜单voidclear(void);//清空列表voidtongji(void);//统计学生人数voidsave(void);voidread(void);};intstudentMessage::menu(void){system("cls");intch;cout<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<"**********************************************************************"<<endl;cout<<"======================================================================"<<endl;cout<<"***************************学生信息管理系统***************************"<<endl;cout<<endl;cout<<endl;cout<<"1.添加功能"<<endl;cout<<"2.查询功能"<<endl;cout<<"3.显示功能"<<endl;cout<<"4.编辑功能"<<endl;cout<<"5.删除功能"<<endl;cout<<"6.统计功能"<<endl;cout<<"7.保存功能"<<endl;cout<<"8.全部删除"<<endl;cout<<"0.退出系统"<<endl;cout<<endl;cout<<endl;cout<<"***********************************************************************"<<endl;cout<<"======================================================================="<<endl;cout<<"***********************************************************************"<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<endl;cin>>ch;cout<<"\n\n\n"<<endl;returnch;}voidstudentMessage::save(void){system("cls");fstreamf("student.txt",ios::out);inti;if(!f){cout<<endl;cout<<endl;cout<<endl;cout<<"文件保存失败!!!!按任意键返回..."<<endl;if(i=getch())return;}if(student::num_total==0){f<<"当前记录中无学生..."<<endl;}else{student*p=first->next;while(p!=null){f<<"学号:"<<p->id<<""<<endl;f<<"姓名:"<<p->name<<endl;f<<"性别(boy/girl):"<<p->sex<<endl;f<<"年龄:"<<p->age<<endl;f<<"班级:"<<p->grade<<endl;if(p->grade=='A'){f<<"专业:"<<p->major<<endl;f<<"家庭住址:"<<p->address<<endl;f<<"联系方式:"<<p->TL<<endl;}elseif(p->grade=='B'){f<<"地理成绩:"<<p->geography<<endl;f<<"历史成绩:"<<p->history<<endl;f<<"家庭住址:"<<p->address<<endl;}else{f<<"语文成绩:"<<p->chinese<<endl;f<<"数学成绩:"<<p->math<<endl;f<<"英语成绩:"<<p->english<<endl;}f<<"------------------------------------------------"<<endl;p=p->next;}}f.close();cout<<endl;cout<<endl;cout<<endl;cout<<"学生信息文件已创建,按任意键继续"<<endl;i=getch();}voidstudentMessage::read(void){system("cls");stringname;intage;intid;chargrade;stringsex,address;doublechinese,math,english;//语文,数学,英语doublehistory,geography;//历史,地理stringmajor;longlongintTL;//专业,电话inti;charch;ifstreamf("student.txt");while(1){f>>ch;if(f.eof()){cout<<"文件为空!按任意键返回"<<endl;if(i=getch())return;}f>>name;f>>sex;f>>age;f>>id;f>>grade;if(grade=='A'){f>>major;f>>address;f>>TL;}elseif(grade=='B'){f>>geography;f>>history;f>>address;}else{f>>chinese;f>>math;f>>english;}student::num_total++;if(sex=="boy")student::num_sex++;if(age>=18)student::num_age++;student*newstu=newstudent();if(grade=='A')newstu=newstudent(id,name,sex,age,grade,major,address,TL);elseif(grade=='B')newstu=newstudent(id,name,sex,age,grade,geography,history,address);elseif(grade=='C')newstu=newstudent(id,name,sex,age,grade,chinese,math,english);student*p=first;while(p->next!=NULL){p=p->next;}p->next=newstu;newstu->next=null;}}/统计voidstudentMessage::tongji(void){system("cls");//cout<<"学生人数一共为:"<<student::num_total<<endl;cout<<"男生一共有:"<<student::num_sex<<endl;cout<<"女生一共有:"<<student::num_total-student::num_sex<<endl;cout<<"成年人有:"<<student::num_age<<endl;inti;cout<<endl;cout<<endl;cout<<endl;cout<<"按任意键继续"<<endl;i=getch();}//插入voidstudentMessage::Insret(void){system("cls");//stringname;intage;intid;chargrade;stringsex,address;doublechinese,math,english;//语文,数学,英语doublehistory,geography;//历史,地理stringmajor;longlongintTL;//专业,电话cout<<"请输入学生姓名:";cin>>name;cout<<"请输入学生性别(boy/girl):";cin>>sex;cout<<"请输入学生年龄:";cin>>age;cout<<"请输入学生学号:";cin>>id;cout<<"下面请输入学生班级(大学生输入'A',初中生输入'B',小学生输入'C'):";cout<<endl;cin>>grade;cout<<endl;if(grade=='A'){cout<<"请输入专业:"<<endl;cin>>major;cout<<"请输入家庭住址:"<<endl;cin>>address;cout<<"请输入联系电话:"<<endl;cin>>TL;}elseif(grade=='B'){cout<<"请输入地理成绩:"<<endl;cin>>geography;cout<<"请输入历史成绩:"<<endl;cin>>history;cout<<"请输入家庭住址:"<<endl;cin>>address;}else{cout<<"请输入语文成绩:"<<endl;cin>>chinese;cout<<"请输入数学成成绩:"<<endl;cin>>math;cout<<"请输入英语成绩:"<<endl;cin>>english;}student::num_total++;if(sex=="boy")student::num_sex++;if(age>=18)student::num_age++;student*newstu=newstudent();if(grade=='A')newstu=newstudent(id,name,sex,age,grade,major,address,TL);elseif(grade=='B')newstu=newstudent(id,name,sex,age,grade,geography,history,address);elseif(grade=='C')newstu=newstudent(id,name,sex,age,grade,chinese,math,english);student*p=first;while(p->next!=NULL){p=p->next;}p->next=newstu;newstu->next=null;}//00000000000000000000000/voidstudentMessage::Display(void){system("cls");if(student::num_total==0){cout<<"当前记录中无学生..."<<endl;}else{student*p=first->next;while(p!=null){cout<<"学号:"<<p->id<<""<<endl;cout<<"姓名:"<<p->name<<endl;cout<<"性别(boy/girl):"<<p->sex<<endl;cout<<"年龄:"<<p->age<<endl;cout<<"班级:"<<p->grade<<endl;if(p->grade=='A'){cout<<"专业:"<<p->major<<endl;cout<<"家庭住址:"<<p->address<<endl;cout<<"联系方式:"<<p->TL<<endl;}elseif(p->grade=='B'){cout<<"地理成绩:"<<p->geography<<endl;cout<<"历史成绩:"<<p->history<<endl;cout<<"家庭住址:"<<p->address<<endl;}else{cout<<"语文成绩:"<<p->chinese<<endl;cout<<"数学成绩:"<<p->math<<endl;cout<<"英语成绩:"<<p->english<<endl;}cout<<"------------------------------------------------"<<endl;p=p->next;}}inti;cout<<endl;cout<<endl;cout<<endl;cout<<"按任意键继续"<<endl;i=getch();}//删除功能~~~~~~~~~~~~~~~~voidstudentMessage::Delete(void){string_name;system("cls");cout<<"请输入需要删除的同学姓名:"<<endl;cin>>_name;intk=0;student*p=first;student*pre=first;while(p->next){pre=p->next;if(pre->name==_name){p->next=pre->next;k=1;deletepre;}p=p->next;}if(k==0&&p->name!=_name)cout<<"记录为空!"<<endl;else{student::num_total--;if(p->sex=="boy")student::num_sex--;if(p->age>=18)student::num_age--;}inti;cout<<endl;cout<<endl;cout<<endl;cout<<"按任意键继续"<<endl;i=getch();}voidstudentMessage::Search(void){system("cls");/inttemp=0;cout<<"请输入查找的条件,有如下选项..."<<endl;cout<<"按照学号查找(请输入【1】)按照姓名查找(请输入【2】)"<<endl;cout<<"退出(请输入【666】)"<<endl;cin>>temp;switch(temp){case1:SearchByid();break;case2:SearchByname();break;case666:return;default:cout<<"输入有误..."<<endl;}}voidstudentMessage::SearchByid(void){system("cls");//int_id;intflag=0;cout<<"请输入待查找学生的学号:";cin>>_id;student*p=first->next;while(p!=null){if(p->id==_id){flag=1;cout<<"下面是查找匹配结果:"<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<"学号:"<<p->id<<""<<endl;cout<<"姓名:"<<p->name<<endl;cout<<"性别(boy/girl):"<<p->sex<<endl;cout<<"年龄:"<<p->age<<endl;cout<<"班级:"<<p->grade<<endl;if(p->grade=='A'){cout<<"专业:"<<p->major<<endl;cout<<"家庭住址:"<<p->address<<endl;cout<<"联系方式:"<<p->TL<<endl;}elseif(p->grade=='B'){cout<<"地理成绩:"<<p->geography<<endl;cout<<"历史成绩:"<<p->history<<endl;cout<<"家庭住址:"<<p->address<<endl;}else{cout<<"语文成绩:"<<p->chinese<<endl;cout<<"数学成绩:"<<p->math<<endl;cout<<"英语成绩:"<<p->english<<endl;}}p=p->next;}if(flag==0){cout<<"未找到匹配项..."<<endl;}inti;cout<<endl;cout<<endl;cout<<endl;cout<<"按任意键继续"<<endl;i=getch();}voidstudentMessage::SearchByname(void){system("cls");/string_name;intflag=0;cout<<"请输入待查找的学生姓名:";cin>>_name;student*p=first->next;while(p!=null){if(p->name==_name){cout<<"下面是查找匹配结果:"<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<"学号:"<<p->id<<""<<endl;cout<<"姓名:"<<p->name<<endl;cout<<"性别(boy/girl):"<<p->sex<<endl;cout<<"年龄:"<<p->age<<endl;cout<<"班级:"<<p->grade<<endl;if(p->grade=='A'){cout<<"专业:"<<p->major<<endl;cout<<"家庭住址:"<<p->address<<endl;cout<<"联系方式:"<<p->TL<<endl;}elseif(p->grade=='B'){cout<<"地理成绩:"<<p->geography<<endl;cout<<"历史成绩:"<<p->history<<endl;cout<<"家庭住址:"<<p->address<<endl;}else{cout<<"语文成绩:"<<p->chinese<<endl;cout<<"数学成绩:"<<p->math<<endl;cout<<"英语成绩:"<<p->english<<endl;}}p=p->next;}if(flag==0){cout<<"未找到匹配项..."<<endl;}inti;cout<<endl;cout<<endl;cout<<endl;cout<<"按任意键继续"<<endl;i=getch();}voidstudentMessage::Change(void){system("cls");//string_name,_sex,_address,_major;char_grade;longlongint_TL;double_chinese,_math,_english;//语文,数学,英语double_history,_geography;//历史,地理intflag=0,temp;int_id,_age;intcourse=0;cout<<"请输入需要改动信息的学生的姓名:";cin>>_name;student*p=first->next;while(p!=null){if(p->name==_name){flag=1;cout<<"该学生当前信息如下:"<<endl;cout<<"学号:"<<p->id<<""<<endl;cout<<"姓名:"<<p->name<<endl;cout<<"性别(boy/girl):"<<p->sex<<endl;cout<<"年龄:"<<p->age<<endl;cout<<"班级:"<<p->grade<<endl;if(p->grade=='A'){cout<<"专业:"<<p->major<<endl;cout<<"家庭住址:"<<p->address<<endl;cout<<"联系方式:"<<p->TL<<endl;}elseif(p->grade=='B'){cout<<"地理成绩:"<<p->geography<<endl;cout<<"历史成绩:"<<p->history<<endl;cout<<"家庭住址:"<<p->address<<endl;}else{cout<<"语文成绩:"<<p->chinese<<endl;cout<<"数学成绩:"<<p->math<<endl;cout<<"英语成绩:"<<p->english<<endl;}cout<<"请指明哪一项需要修改..."<<endl;cout<<"修改学号(输入【1】)修改年龄(输入【2】)修改班级信息(输入【3】)"<<endl;cout<<"退出(输入【666】)"<<endl;cin>>temp;switch(temp){case1:{cout<<"请输入新的学号:"<<endl;cin>>_id;p->id=_id;}break;case2:{cout<<"请输入新的年龄:"<<endl;;cin>>_age;p->age=_age;}break;case3:{cout<<"请输入新的班级信息(大学生输入'A',初中生输入'B',小学生输入'C'):"<<endl;;cin>>_grade;p->grade=_grade;if(_grade=='A'){cout<<"请输入专业:"<<endl;cin>>_major;p->major=_major;cout<<"请输入家庭住址:"<<endl;cin>>_address;p->address=_address;cout<<"请输入联系电话:"<<endl;cin>>_TL;p->TL=_TL;}elseif(_grade=='B'){cout<<"请输入地理成绩:"<<endl;cin>>_geography;p->geography=_geography;cout<<"请输入历史成绩:"<<endl;cin>>_history;p->history=_history;cout<<"请输入家庭住址:"<<endl;cin>>_address;p->address=_address;}else{cout<<"请输入语文成绩:"<<endl;cin>>_chinese;p->chinese=_chinese;cout<<"请输入数学成成绩:"<<endl;cin>>_math;p->major=_math;cout<<"请输入英语成绩:"<<endl;cin>>_english;p->english=_english;}}break;case666:return;cout<<"修改后的信息如下:"<<endl;cout<<"姓名:"<<p->name<<""<<endl;cout<<"性别:"<<p->sex<<""<<endl;cout<<"年龄:"<<p->age<<""<<endl;cout<<"学号:"<<p->id<<""<<endl;cout<<"地址:"<<p->address<<""<<endl;default:cout<<"输入有误..."<<endl;}}p=p->next;}if(flag==0)cout<<"当前记录中没有此学生..."<<endl;}voidstudentMessage::clear(void){student*p=first->next;while(p!=null){first->next=p->next;p->next=null;deletep;p=first->next;}}intmain(){studentMessagestulist;intch;while(ch=stulist.menu()){switch(ch){case1:stulist.Insret();break;case2:stulist.Search();break;case3:stulist.Display();break;case4:stulist.Change();break;case5:stulist.Delete();break;case6:stulist.tongji();break;case7:stulist.save();break;case8:stulist.clear();break;case0:return0;default:cout<<"请按要求输入..."<<endl;}}return0;}
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:C++如何实现学生信息管理系统的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:python面向对象怎么实现学生信息管理系统下一篇:

6 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18