c++学校人员信息管理系统.docx
《c++学校人员信息管理系统.docx》由会员分享,可在线阅读,更多相关《c++学校人员信息管理系统.docx(24页珍藏版)》请在冰豆网上搜索。
c++学校人员信息管理系统
1.C++课程设计题目:
《学校人员信息管理系统》
用c++设计一个大学教师和学生管理程序,教师包括编号(a),(c),职称(d)和教研室数据(b)的数据输入输出;大学生包括编号(m),(s),性别(t),班号(n),英语(e),高等数学(f)和数据结构(g)三门课程成绩输入输出和计算机平均分(ave);研究生包括编号,,性别,班号,指导教师和研究方法数据输入输出;博士后数据的输入输出;博士后既是教师也是研究生.(用派生,继承的方法可以做)
2.功能如下图所示:
3.部分代码
#include
#include
#include"persons.h"
#include"student.h"
#include"teacher.h"
#include"empoyee.h"
#include"chainList.h"
#include
voidfileRead(chainList*list,ifstream&ff);//把文件从硬盘上读入内存
voidfileWrite(chainList*list,ofstream&ff);//写入硬盘
intcompareStr(char*str1,char*str2);//名字作为关键字,这个函数就用来比较
voidaddList(chainList*list);//同名的话,覆盖,或者改为新名字加入
voiddeleteNode(chainList*node);//根据名字删除
voideditList(chainList*list,char*name);//要编辑的人名和新的资料
chainList*searchList(chainList*list,char*name);//只提供名字查询(其他以后加入)
//返回前一个节点的指针
voidorderList(chainList*list);//按名字排序
voidorderListByAge(chainList*list);//按年龄降序排列
voidorderListBySex(chainList*list);//按照性别排列,女士优先
voidprintStaticInfo(chainList*list);
voidprintList(chainList*list);
intmain()
{cout<<"\tYouarewelcometothemanagementsystem!
"<cout<<"Doyouwanttoloadafileorsetupanewlist?
Presslors."<charsn;
cin>>sn;
charfileName[30];
chainListheadNode(0,NULL);
chainList*head=&headNode;
if(sn=='l')
{ifstreamfile;
cout<<"File'sname:
"<cin>>fileName;
file.open(fileName);
if(!
file)//为何输入不存在地文件后,机子变得很慢,而且没有结果出来?
{cout<<"Filenotfound!
Systemexit."<return1;
}
//cout<<"test"<file的检查?
(文件不存在阿)
fileRead(head,file);//读入文件到链表
file.close();
}
printStaticInfo(head);
charctn;
do
{cout<<"mainmenu:
"<cout<<"\t1.Addaperson.2.Deleteaperson3.Editaperson"<cout<<"\t4.Searchaperson5.Orderthelist6.Printinfoaboutthelist"<cout<<"\t0.exit"<cin>>ctn;
switch(ctn)
{
case'0':
break;
case'1':
addList(head);
break;
case'2':
cout<<"Pleaseinputtheperson'snametobedeleted:
"<charnm[20];
cin>>nm;
chainList*pdel;
pdel=searchList(head,nm);
charsure;//Makesurewhetheryouwanttodeletethedata
sure='n';
if(!
pdel->next)
{
cout<<"Thepersonyouinputcann'tbefound"<}
else{
cout<<"Thepersonsinforfollows:
"<pdel->next->pl->print();
cout<<"Areyousuretodeleteit?
Pressyorn"<cin>>sure;
if(sure=='y')
{
deleteNode(pdel);
cout<"<}
}
break;
case'3':
cout<<"Pleaseinputtheperson'sname:
"<charnm1[20];
cin>>nm1;
chainList*pp;
pp=searchList(head,nm1);
if(pp->next)
{
cout<<"Theperson'sinforfollows:
"<pp->next->pl->print();
cout<<"Now,pleaseedittheinfors."<editList(head,nm1);
}
else
cout<<"Thepersoncan'tbefound!
!
"<break;
case'4':
cout<<"Pleaseinputtheperson'sname:
"<charname[30];
cin>>name;
chainList*p;
p=searchList(head,name);
if(p->next)
{
p->next->pl->print();
}
else
cout<<"Thepersoncan'tbefound!
"<break;
case'5':
cout<<"Youwanttoorderthelistby:
"<cout<<"1.name2.age3.sex(ladyfirst)"<charch;
cin>>ch;
switch(ch)
{
case'1':
cout<<"Youchoosetoorderthelistbyname.Theresultareasfollows:
"<orderList(head);
printStaticInfo(head);
break;
case'2':
cout<<"Youchoosetoorderthelistbyage.Theresultareasfollows:
"<orderListByAge(head);
printStaticInfo(head);
break;
case'3':
cout<<"Youchoosetoorderthelistbysex.Theresultareasfollows:
"<orderListBySex(head);
printStaticInfo(head);
break;
default:
cout<<"Wrongchoice!
"<}
break;
case'6':
printStaticInfo(head);
break;
default:
cout<<"Wrongchoice!
"<}
}while(ctn!
='0');
cout<<"Doyouwanttosavethefile?
No,pressn.Else,anyotherkey."<charsave;
cin>>save;
if(save!
='n')
{
cout<<"Pleaseinputthefile'sname:
"<cin>>fileName;
ofstreamfin;
fin.open(fileName);//如果文件已经存在,询问是否覆盖。
如何知道是否存在
if(!
fin)
{
cout<<"Can'topenoutputfile.\n";
return1;
}
fileWrite(head,fin);
fin.close();
cout<<"Filehasbeensuccessfullysaved!
"<}
cout<<"Byebye!
"<return0;
}
voidfileRead(chainList*list,ifstream&ff)
{
chainList*p=list;
inttp;
charnm[20];
intag;
charsx;
intslr;
intgrd;
inte;
intm;
intg;
intaverage;
charschl[20];
charsb[20];
intteaYear;
intaa=1;
persons*psn;//插入人员指针
ff>>tp;
while(tp)
{ff>>ag;
ff>>nm;
ff>>sx;
switch(tp)
{
case1:
ff>>grd;
ff>>schl;
psn=newstudent(ag,nm,sx,grd,schl,e,m,g,average);
break;
case2:
ff>>sb;
ff>>teaYear;
psn=newteacher(ag,nm,sx,sb,teaYear);
break;
case3:
ff>>slr;
psn=newempoyee(ag,nm,sx,slr);
break;
}
chainList*s=newchainList(tp,psn);
p->next=s;
p=s;
ff>>tp;
}
}
voidfileWrite(chainList*list,ofstream&ff)
{
chainList*p=list->next;
while(p)
{
ff<typeOfPn<<""<pl->age<<""<pl->name<<""<pl->sex<<"";
switch(p->typeOfPn)
{
case1:
ff<<((student*)p->pl)->grade<<""<<((student*)p->pl)->school<break;
case2:
ff<<((teacher*)p->pl)->subject<<""<<((teacher*)p->pl)->yearsOfT<break;
case3:
ff<<((empoyee*)p->pl)->salary<break;
}
p=p->next;
}
intaa=0;
ff<}
intcompareStr(char*str1,char*str2)//比较字符串
{
char*p1=str1,*p2=str2;
inti=0;
while((p1[i]==p2[i])&&p1[i]&&p2[i])
i++;
if(p1[i]==p2[i])
{
return0;
}
else
{if(p1[i]>p2[i])
return1;
else
return-1;
}
}
voidaddList(chainList*list)//添加节点
{
chartp;
inttype;
do{
cout<<"Thepersonwhoseinfoyouwanttoinputis:
"<cout<<"1.astudent2.ateacher3.acommonemployee"<cout<<"0.Returntomainmenu."<cin>>tp;//为什么一输入字符就死循环?
?
charnm[20];
intag;
charsx;
intslr;
intgrd;
charschl[20];
inte;
intm;
intg;
intaverage;
charsb[20];
intteaYear;
intaa=1;
persons*psn;//插入人员指针
switch(tp)
{
case'0':
aa=0;
type=0;
break;
case'1':
type=1;
cout<<"name:
"<cin>>nm;
cout<<"age:
"<cin>>ag;
cout<<"maleorfemale?
morf?
"<cin>>sx;
cout<<"Thestudent'sgrade"<cin>>grd;
cout<<"Fromwhichschool:
"<cin>>schl;
cout<<"thescoreofenglish:
"<cin>>e;
cout<<"thescoreofmath:
"<cin>>m;
cout<<"thescoreofsjjg:
"<cin>>g;
cout<<"average:
"<psn=newstudent(ag,nm,sx,grd,schl,e,m,g,average);
break;
case'2':
type=2;
cout<<"name:
"<cin>>nm;
cout<<"age:
"<cin>>ag;
cout<<"maleorfemale?
morf?
"<cin>>sx;
cout<<"subjectfield:
"<cin>>sb;
cout<<"Yearsasateacher:
"<cin>>teaYear;
psn=newteacher(ag,nm,sx,sb,teaYear);
break;
case'3':
type=3;
cout<<"name:
"<cin>>nm;
cout<<"age:
"<cin>>ag;
cout<<"maleorfemale?
morf?
"<cin>>sx;
cout<<"Theemployee'ssalary:
"<cin>>slr;
psn=newempoyee(ag,nm,sx,slr);
break;
default:
type=6;
aa=0;
cout<<"Wrongchoice!
"<}
chainList*p=list;//新节点在p所指的节点之前插入,
if(aa)
{
int;
if(p->next)
{
=compareStr(nm,p->next->pl->name);
cout<<<}
while(p->next&&>0)//比p节点小或者p为空退出
{
p=p->next;
if(p->next)
=compareStr(nm,p->next->pl->name);
}
chainList*s=newchainList(type,psn);
s->next=p->next;
p->next=s;
}
}while(type);
}
voiddeleteNode(chainList*node)
{
chainList*ptemp=node->next;
node->next=ptemp->next;
deleteptemp;
}
voideditList(chainList*list,char*name)//删除,添加就是编辑。
缺点:
不想删除的也被删除了。
{
chainList*pde;
pde=searchList(list,name);
chartp;
inttype;
do{
cout<<"Thepersonwhoseinfoyouwanttoinputis:
"<cout<<"1.astudent2.ateacher3.acommonemployee"<cout<<"0.Returntomainmenu."<cin>>tp;//为什么一输入字符就死循环?
?
charnm[20];
intag;
charsx;
intslr;
intgrd;
charschl[20];
inte;
intm;
intg;
intaverage;
charsb[20];
intteaYear;
intaa=1;
persons*psn;//插入人员指针
if(tp==1||tp==2||tp==3)
deleteNode(pde);
switch(tp)
{
case'0':
aa=0;
type=0;
break;
case'1':
type=1;
cout<<"name:
"<cin>>nm;
cout<<"age:
"<cin>>ag;
cout<<"maleorfemale?
morf?
"<cin>>sx;
cout<<"Thestudent'sgrade"<cin>>grd;
cout<<"Fromwhichschool:
"<cin>>schl;
cout<<"thescoreofenglish:
"<cin>>e;
cout<<"thescoreofmath:
"<cin>>m;
cout<<"thescoreofsjjg:
"<cin>>g;
psn=newstudent(ag,nm,sx,grd,schl,e,m,g,average);
break;
case'2':
type=2;
cout<<"name:
"<cin>>nm;
cout<<"age:
"<cin>>ag;
cout<<"maleorfemale?
morf?
"<cin>>sx;
cout<<"subjectfield:
"<cin>>sb;
cout<<"Yearsasateacher:
"<cin>>teaYear;
psn=newteacher(ag,nm,sx,sb,teaYear);
break;
case'3':
type=3;
cout<<"name:
"<cin>>nm;
cout<<"age:
"<cin>>ag;
cout<<"maleorfemale?
morf?
"<cin>>sx;
cout<<"Theemployee'ssalary:
"<cin>>slr;
psn=newempoyee(ag,nm,sx,slr);
break;
default:
type=6;
aa=0;
cout<<"Wrongchoice!
"<}
chainList*p=list;//新节点在p所指的节点之前插入,
if(aa)
{
int;
if(p->next)
{
=comp