1、c+学校人员信息管理系统1.C+课程设计题目:学校人员信息管理系统用c+设计一个大学教师和学生管理程序,教师包括编号(a),(c),职称(d)和教研室数据(b)的数据输入输出; 大学生包括编号(m),( s),性别(t),班号(n),英语(e),高等数学(f)和数据结构(g)三门课程成绩输入输出和计算机平均分(ave);研究生包括编号,性别,班号,指导教师和研究方法数据输入输出; 博士后数据的输入输出;博士后既是教师也是研究生.(用派生,继承的方法可以做)2.功能如下图所示: 3.部分代码#include#include#includepersons.h#includestudent.h#in
2、cludeteacher.h#includeempoyee.h#includechainList.h#includevoid fileRead(chainList *list,ifstream &ff);/把文件从硬盘上读入内存void fileWrite(chainList *list,ofstream &ff);/写入硬盘int compareStr(char*str1,char*str2);/名字作为关键字,这个函数就用来比较void addList(chainList *list);/同名的话,覆盖,或者改为新名字加入void deleteNode(chainList *node);/
3、根据名字删除void editList(chainList *list,char *name);/要编辑的人名和新的资料chainList *searchList(chainList *list,char*name);/只提供名字查询(其他以后加入)/返回前一个节点的指针void orderList(chainList *list);/按名字排序void orderListByAge(chainList *list);/按年龄降序排列void orderListBySex(chainList *list);/按照性别排列,女士优先void printStaticInfo(chainList*l
4、ist);void printList(chainList *list);int main()couttYou are welcome to the management system!endl; coutDo you want to load a file or setup a new list?Press l or s.sn; char fileName30; chainList headNode(0,NULL); chainList *head=&headNode; if(sn=l) ifstream file; coutFiles name:fileName; file.open(fi
5、leName); if(! file)/为何输入不存在地文件后,机子变得很慢,而且没有结果出来? coutFile not found!System exit.endl; return 1; / couttestendl;/竟然通过!file的检查?(文件不存在阿) fileRead(head,file);/读入文件到链表 file.close(); printStaticInfo(head); char ctn; do coutmain menu:endl; coutt1.Add a person. 2.Delete a person 3.Edit a personendl; coutt4.
6、Search a person 5.Order the list 6.Print info about the listendl; coutt0.exitctn; switch(ctn) case 0:break; case 1: addList(head); break; case 2: coutPlease input the persons name to be deleted:nm; chainList *pdel; pdel=searchList(head,nm); char sure;/Make sure whether you want to delete the data su
7、re=n; if(!pdel-next) coutThe person you input cannt be foundendl; else coutThe persons infor follows:next-pl-print(); coutAre you sure to delete it?Press y or nsure; if(sure=y) deleteNode(pdel); coutnm have been deleted!endl; break; case 3: coutPlease input the persons name:nm1; chainList *pp; pp=se
8、archList(head,nm1); if(pp-next) coutThe persons infor follows:next-pl-print(); coutNow ,please edit the infors.endl; editList(head,nm1); else coutThe person cant be found !endl; break; case 4: coutPlease input the persons name:name; chainList *p; p=searchList(head,name); if(p-next) p-next-pl-print()
9、; else coutThe person cant be found!endl; break; case 5: coutYou want to order the list by:endl; cout1.name 2.age 3.sex(lady first)ch; switch(ch) case 1: coutYou choose to order the list by name.The result are as follows:endl; orderList(head); printStaticInfo(head); break; case 2: coutYou choose to
10、order the list by age.The result are as follows:endl; orderListByAge(head); printStaticInfo(head); break; case 3: coutYou choose to order the list by sex.The result are as follows:endl; orderListBySex(head); printStaticInfo(head); break; default: coutWrong choice!endl; break; case 6: printStaticInfo
11、(head); break; default: coutWrong choice!endl; while(ctn!=0); coutDo you want to save the file?No,press n.Else,any other key.save; if(save!=n) coutPlease input the files name:fileName; ofstream fin; fin.open(fileName);/如果文件已经存在,询问是否覆盖。如何知道是否存在 if(!fin) coutCant open output file.n; return 1; fileWrit
12、e(head,fin); fin.close(); coutFile has been successfully saved!endl; coutByebye!tp; while(tp) ffag; ffnm; ffsx; switch(tp) case 1: ffgrd; ffschl; psn=new student(ag,nm,sx,grd,schl,e,m,g,average); break; case 2: ffsb; ffteaYear; psn=new teacher(ag,nm,sx,sb,teaYear); break; case 3: ffslr; psn=new empo
13、yee(ag,nm,sx,slr); break; chainList*s=new chainList(tp,psn); p-next=s; p=s; fftp; void fileWrite(chainList *list,ofstream &ff) chainList*p=list-next; while(p) fftypeOfPn pl-age pl-name pl-sextypeOfPn) case 1: ffpl)-grade pl)-schoolendl; break; case 2: ffpl)-subject pl)-yearsOfTendl; break; case 3: f
14、fpl)-salarynext; int aa=0; ffp2i) return 1; else return -1; void addList(chainList *list)/添加节点 char tp; int type; do coutThe person whose info you want to input is:endl; cout1.a student 2.a teacher 3.a common employeeendl; cout0.Return to main menu.tp;/为什么一输入字符就死循环? char nm20; int ag; char sx; int s
15、lr; int grd; char schl20; int e; int m; int g; int average; char sb20; int teaYear; int aa=1; persons*psn;/插入人员指针 switch(tp) case 0:aa=0; type=0; break; case 1: type=1; coutname:nm; coutage:ag; coutmale or female?m or f?sx; coutThe students gradegrd; coutFrom which school:schl; coutthe score of engl
16、ish:e; coutthe score of math:m; coutthe score of sjjg:g; coutaverage:averageendl; psn=new student(ag,nm,sx,grd,schl,e,m,g,average); break; case 2:type=2; coutname:nm; coutage:ag; coutmale or female?m or f?sx; coutsubject field:sb; coutYears as a teacher:teaYear; psn=new teacher(ag,nm,sx,sb,teaYear);
17、 break; case 3:type=3; coutname:nm; coutage:ag; coutmale or female?m or f?sx; coutThe employees salary:slr; psn=new empoyee(ag,nm,sx,slr); break; default:type=6; aa=0; coutWrong choice!next) =compareStr(nm,p-next-pl-name); coutnext&0)/比p节点小或者p为空退出 p=p-next; if(p-next) =compareStr(nm,p-next-pl-name);
18、 chainList *s=new chainList(type,psn); s-next=p-next; p-next=s; while(type); void deleteNode(chainList *node) chainList*ptemp=node-next; node-next=ptemp-next; delete ptemp;void editList(chainList *list,char *name)/删除,添加就是编辑。缺点:不想删除的也被删除了。 chainList *pde; pde=searchList(list,name); char tp; int type;
19、 do coutThe person whose info you want to input is:endl; cout1.a student 2.a teacher 3.a common employeeendl; cout0.Return to main menu.tp;/为什么一输入字符就死循环? char nm20; int ag; char sx; int slr; int grd; char schl20; int e; int m; int g; int average; char sb20; int teaYear; int aa=1; persons*psn;/插入人员指针
20、 if(tp=1|tp=2|tp=3) deleteNode(pde); switch(tp) case 0:aa=0; type=0; break; case 1: type=1; coutname:nm; coutage:ag; coutmale or female?m or f?sx; coutThe students gradegrd; coutFrom which school:schl; coutthe score of english:e; coutthe score of math:m; coutthe score of sjjg:g; psn=new student(ag,n
21、m,sx,grd,schl,e,m,g,average); break; case 2:type=2; coutname:nm; coutage:ag; coutmale or female?m or f?sx; coutsubject field:sb; coutYears as a teacher:teaYear; psn=new teacher(ag,nm,sx,sb,teaYear); break; case 3:type=3; coutname:nm; coutage:ag; coutmale or female?m or f?sx; coutThe employees salary:slr; psn=new empoyee(ag,nm,sx,slr); break; default:type=6; aa=0; coutWrong choice!next) =comp
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1