#include
#include
#include
#include
using namespace std;
#include
#include
#include
#pragma comment(lib, "Winmm.lib")
class Person{
protected:
string number;
string name;
string sex;
string age;
public:
Person(){}
Person(string num,string na,string se,string ag)
{
number=num;name=na;sex=se;age=ag;
}
void point()
{
cout.setf(ios::left);
cout<<setw(12)<<number;
cout<<setw(8)<<name;
cout<<setw(5)<<sex;
cout<<setw(8)<<age;
}
};
class Teacher:public Person{
private:
string xi_bu;
string zhuan_ye;
string zhi_cheng;
public:
Teacher *next;
Teacher(){}
Teacher(string num,string na,string se,string ag,string xi,string zhuan,string zhi):Person(num,na,se,ag)
{
xi_bu=xi;zhuan_ye=zhuan;zhi_cheng=zhi;
}
void point()
{
Person::point();
cout.setf(ios::left);
cout<<setw(20)<<xi_bu;
cout<<setw(20)<<zhuan_ye;
cout<<setw(8)<<zhi_cheng<<endl;
}
friend void teacheradd();
friend int yn(string);
friend void search();
friend void bain_ji(Teacher&);
friend void teacher_tong_ji();
friend int rencount();
friend void teacherSave();
friend int jdadd(Teacher *p1);
friend void delall();
};
class xingzheng:public Person{
private:
string bumen;
string zhengzhi;
string zhicheng;
public:
xingzheng(){}
xingzheng *next;
xingzheng(string num,string na,string se,string ag,string bu,string zz,string zhi):Person(num,na,se,ag)
{
bumen=bu;zhengzhi=zz;zhicheng=zhi;
}
void point(){
Person::point();
cout.setf(ios::left);
cout<<setw(20)<<bumen;
cout<<setw(20)<<zhengzhi;
cout<<setw(8)<<zhicheng<<endl;
}
friend void xzadd();
friend int xzyn(string);
friend void xzsearch();
friend void xzbain_ji(xingzheng&);
friend void xz_tong_ji();
friend int xzrencount();
friend void xzSave();
friend int xzjdadd(xingzheng *p1);
friend void xzdelall();
};
class shiyan:public Person{
private:
string shiyanshi;
string zhiwu;
public:
shiyan *next;
shiyan(){}
shiyan(string num,string na,string se,string ag,string sy,string zw):Person(num,na,se,ag)
{shiyanshi=sy;zhiwu=zw;}
void point()
{
Person::point();
cout.setf(ios::left);
cout<<setw(30)<<shiyanshi;
cout<<setw(8)<<zhiwu<<endl;
}
friend void shiyanadd();
friend int shiyanjdadd(shiyan *p1);
friend int shiyanyn(string);
friend void shiyansearch();
friend void shiyanbain_ji(shiyan&);
friend void shiyan_tong_ji();
friend void shiyandelall();
friend int shiyanrencount();
friend void shiyanSave();
};
Teacher head;
shiyan head1;
xingzheng head2;
void home();
void tuichu();
void huanying();
int question(const char *pstr);
void music()
{
PlaySound(TEXT("teacher.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
}
void symusic()
{
PlaySound(TEXT("shiyanyuan.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
}
void xzmusic()
{
PlaySound(TEXT("xz.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
}
void offmusic()
{
PlaySound(NULL, NULL, SND_FILENAME | SND_ASYNC);
}
void putout(Teacher *p)
{
p=p->next;
int count=0;
system("cls");
if(!p)
{
cout<<"信息为空,请先添加信息!\n";
return;
}
void teacher_list();
teacher_list();
while(p)
{
p->point();
count++;
p=p->next;
}
void __();
__();
cout<<"共有"<<count<<"条信息。\n";
}
void shiyanputout(shiyan *p)
{
p=p->next;
int count=0;
system("cls");
if(!p)
{
cout<<"信息为空,请先添加信息!\n";
return;
}
void shiyan_list();
shiyan_list();
while(p)
{
p->point();
count++;
p=p->next;
}
void __();
__();
cout<<"共有"<<count<<"条信息。\n";
}
void xzputout(xingzheng *p)
{
p=p->next;
int count=0;
system("cls");
if(!p)
{
cout<<"信息为空,请先添加信息!\n";
return;
}
void xingzheng_list();
xingzheng_list();
while(p)
{
p->point();
count++;
p=p->next;
}
void __();
__();
cout<<"共有"<<count<<"条信息。\n";
}
char menu()
{
system("cls");
cout<<"----------------------------教师信息管理系统--------------------------------\n";
cout<<"\n\t1.清除所有信息 2.显示所有信息 3.添加信息\n";
cout<<"\t4.查找信息 5.统计 6.保存信息至文件\n";
cout<<"\t7.退出系统 8.播放背景音乐 9.关闭背景音乐\n";
cout<<"\n-------------------------------------------------------------------------------\n";
void dqsj();
dqsj();
char choose;
cout<<"请输入数字1—9\n";
cin>>choose;
while(choose<'1'||choose>'9')
{
cout<<"输入错误,请重新输入:";cin>>choose;
}
return choose;
}
char xzmenu()
{
system("cls");
cout<<"----------------------------行政人员信息管理系统--------------------------------\n";
cout<<"\n\t1.清除所有信息 2.显示所有信息 3.添加信息\n";
cout<<"\t4.查找信息 5.统计 6.保存信息至文件\n";
cout<<"\t7.退出系统 8.播放背景音乐 9.关闭背景音乐\n";
cout<<"\n-------------------------------------------------------------------------------\n";
void dqsj();
dqsj();
char choose;
cout<<"请输入数字1—9\n";
cin>>choose;
while(choose<'1'||choose>'9')
{
cout<<"输入错误,请重新输入:";cin>>choose;
}
return choose;
}
char shiyanmenu()
{
system("cls");
cout<<"----------------------------实验员信息管理系统--------------------------------\n";
cout<<"\n\t1.清除所有信息 2.显示所有信息 3.添加信息\n";
cout<<"\t4.查找信息 5.统计 6.保存信息至文件\n";
cout<<"\t7.退出系统 8.播放背景音乐 9.关闭背景音乐\n";
cout<<"\n-------------------------------------------------------------------------------\n";
void dqsj();
dqsj();
char choose;
cout<<"请输入数字1—9\n";
cin>>choose;
while(choose<'1'||choose>'9')
{
cout<<"输入错误,请重新输入:";cin>>choose;
}
return choose;
}
void teacherfun(char n)
{
while(1)
{
switch(n)
{
case '1':delall();system("pause");putout(&head);system("pause");teacherfun(menu());break;
case '2':putout(&head);if(question("是否返回主菜单?")) teacherfun(menu());break;
case '3':teacheradd();if(!question("是否继续添加?"))teacherfun(menu());break;
case '4':search();if(!question("是否继查找?"))teacherfun(menu());break;
case '5':teacher_tong_ji();if(!question("是否继续统计?"))teacherfun(menu());break;
case '6':teacherSave();system("pause");teacherfun(menu());break;
case '7':cout<<"1.返回首页 2.退出程序\n请选择:";char t;while(1){cin>>t;if(t=='1'){if(question("你即将离开系统,是否保存信息?"))teacherSave();home();}else if(t=='2'){if(question("你即将离开系统,是否保存信息?"))teacherSave();tuichu();exit(1);}else cout<<"输入错误,请重新输入:\n";}break;
case '8':if(question("是否播放背景音乐?"))music();teacherfun(menu());break;
case '9':if(question("是否关闭背景音乐?"))offmusic();teacherfun(menu());break;
default:break;
}
}
}
void xzfun(char n)
{
while(1)
{
switch(n)
{
case '1':xzdelall();system("pause");xzputout(&head2);system("pause");xzfun(xzmenu());break;
case '2':xzputout(&head2);if(question("是否返回主菜单?")) xzfun(xzmenu());break;
case '3':xzadd();if(!question("是否继续添加?"))xzfun(xzmenu());break;
case '4':xzsearch();if(!question("是否继查找?"))xzfun(xzmenu());break;
case '5':xz_tong_ji();if(!question("是否继续统计?"))xzfun(xzmenu());break;
case '6':xzSave();system("pause");xzfun(xzmenu());break;
case '7':cout<<"1.返回首页 2.退出程序\n请选择:";char t;while(1){cin>>t;if(t=='1'){if(question("你即将离开系统,是否保存信息?"))xzSave();home();}else if(t=='2'){if(question("你即将离开系统,是否保存信息?"))xzSave();tuichu();exit(1);}else cout<<"输入错误,请重新输入:\n";}break;
case '8':if(question("是否播放背景音乐?"))xzmusic();xzfun(xzmenu());break;
case '9':if(question("是否关闭背景音乐?"))offmusic();xzfun(xzmenu());break;
default:break;
}
}
}
void shiyanfun(char n)
{
while(1)
{
switch(n)
{
case '1':shiyandelall();system("pause");shiyanputout(&head1);system("pause");shiyanfun(shiyanmenu());break;
case '2':shiyanputout(&head1);if(question("是否返回主菜单?")) shiyanfun(shiyanmenu());break;
case '3':shiyanadd();if(!question("是否继续添加?"))shiyanfun(shiyanmenu());break;
case '4':shiyansearch();if(!question("是否继查找?"))shiyanfun(shiyanmenu());break;
case '5':shiyan_tong_ji();if(!question("是否继续统计?"))shiyanfun(shiyanmenu());break;
case '6':shiyanSave();system("pause");shiyanfun(shiyanmenu());break;
case '7':cout<<"1.返回首页 2.退出程序\n请选择:";char t;while(1){cin>>t;if(t=='1'){if(question("你即将离开系统,是否保存信息?"))shiyanSave();home();}else if(t=='2'){if(question("你即将离开系统,是否保存信息?"))shiyanSave();tuichu();exit(1);}else cout<<"输入错误,请重新输入:\n";}break;
case '8':if(question("是否播放背景音乐?"))symusic();shiyanfun(shiyanmenu());break;
case '9':if(question("是否关闭背景音乐?"))offmusic();shiyanfun(shiyanmenu());break;
default:break;
}
}
}
void dqsj()
{
char * wday[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
time_t t;
struct tm *p;
t = time(NULL);
p = gmtime(&t);
printf("现在时间是:");
printf("%d年%2d月%2d日", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday);
printf(" %s ", wday[p->tm_wday]);
printf("%02d:%02d\n", (8+p->tm_hour), p->tm_min);
printf("\n-------------------------------------------------------------------------------\n");
}
int question(const char *pstr)
{
char answer;
printf("%s请选择(y or n):", pstr);
while(1 != scanf(" %c", &answer) || (answer != 'y' && answer != 'n'))
{
printf("输入错误!\n请重新选择(y or n):");
}
if('y' == answer)
return 1;
else
return 0;
}
void teacheradd()
{
string num,na,se,xi,zhuan,zhi;string ag;
cout<<"请输入您要添加的教师信息!"<<endl;
cout<<"编号:";cin>>num;
while(yn(num))
{
cout<<"该编号已存在,请重新输入:\n";
cin>>num;
}
cout<<"姓名:";cin>>na;
cout<<"性别:";cin>>se;
while(se!="男"&&se!="女")
{
cout<<"输入的性别有误!!!\n请重新输入:";
cin>>se;
}
cout<<"年龄:";cin>>ag;
cout<<"系部:";cin>>xi;
cout<<"专业:";cin>>zhuan;
cout<<"职称:";cin>>zhi;
Teacher *T=new Teacher(num,na,se,ag,xi,zhuan,zhi);
jdadd(T);
}
void teacher_list()
{
cout<<"-------------------------------------------------------------------------------------------------\n";
cout<<"编号 姓名 性别 年龄 系部 专业 职称 \n";
cout<<"-------------------------------------------------------------------------------------------------\n";
}
void xingzheng_list()
{
cout<<"-------------------------------------------------------------------------------------------------\n";
cout<<"编号 姓名 性别 年龄 部门 政治面貌 职称 \n";
cout<<"-------------------------------------------------------------------------------------------------\n";
}
void shiyan_list()
{
cout<<"-------------------------------------------------------------------------------------------------\n";
cout<<"编号 姓名 性别 年龄 实验室 职务 \n";
cout<<"-------------------------------------------------------------------------------------------------\n";
}
void __()
{
cout<<"-------------------------------------------------------------------------------------------------\n";
}
int yn(string num)
{
Teacher *p=head.next;
while(p)
if(num==p->number)
return 1;
else
p=p->next;
return 0;
}
void search()
{
Teacher *p=head.next;
cout<<"请输入你要查找信息的编号或姓名:\n";
string nn;
cin>>nn;
int i=0;
Teacher *temp=&head;
while(p)
{
if(nn==p->number||nn==p->name)
{
i++;
teacher_list();
p->point();
__();
bain_ji(*temp);
}
temp=p;
p=p->next;
}
if(!i)
cout<<"您所查找的信息不存在!!!\n";
}
void bain_ji(Teacher &p1)
{
string a;
while(1)
{
cout<<"您可以对以上信息进行以下操作:\n";
cout<<"1.修改 2.删除 3.返回主菜单\n您的选择是:";
cin>>a;
if(a =="1")
{
string se,num;
cout<<"请输入您要修改信息!"<<endl;
cout<<"编号:";cin>>num;
while(yn(num))
{
if(num==p1.next->number)
break;
cout<<"该编号已存在,请重新输入:\n";
cin>>num;
}
p1.next->number=num;
cout<<"姓名:";cin>>p1.next->name;
cout<<"性别:";cin>>se;
while(se!="男"&&se!="女")
{
cout<<"输入的性别有误!!!\n请重新输入:";
cin>>se;
}
p1.next->sex=se;
cout<<"年龄:";cin>>p1.next->age;
cout<<"系部:";cin>>p1.next->xi_bu;
cout<<"专业:";cin>>p1.next->zhuan_ye;
cout<<"职称:";cin>>p1.next->zhi_cheng;
cout<<"信息修改成功!\n";
break;
}
else if(a=="2")
{
if(question("确定要删除该信息吗?"))
{
Teacher *t=p1.next->next;
p1.next=t;
cout<<"删除成功!\n";
break;
}
}
else if(a=="3")
teacherfun(menu());
else
cout<<"输入错误!!!\n请重新输入:";
}
}
void teacher_tong_ji()
{
Teacher *p=head.next;
if(!p)
{
cout<<"信息为空!!\n";
return;
}
cout<<"你可以选择的统计方式:1.按性别统计 2.按系部统计 3.按职称统计 4.返回主菜单\n请输入你的选择:";
string a;
while(1)
{
cin>>a;
if(a=="1")
{
Teacher *cur,*tail;
cur=head.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->sex>cur->next->sex)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->xi_bu;cur->xi_bu=cur->next->xi_bu;cur->next->xi_bu=temp;
temp=cur->zhi_cheng;cur->zhi_cheng=cur->next->zhi_cheng;cur->next->zhi_cheng=temp;
temp=cur->zhuan_ye;cur->zhuan_ye=cur->next->zhuan_ye;cur->next->zhuan_ye=temp;
}
cur=cur->next;
}
tail=cur;
cur=head.next;
}
int count=0;
if(p)
{
system("cls");
teacher_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->sex<<"性教师共有"<<count<<"人。\n";
break;
}
if(p->sex!=p->next->sex)
{
__();;
cout<<p->sex<<"性教师共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
teacher_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="2")
{
Teacher *cur,*tail;
cur=head.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->xi_bu>cur->next->xi_bu)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->xi_bu;cur->xi_bu=cur->next->xi_bu;cur->next->xi_bu=temp;
temp=cur->zhi_cheng;cur->zhi_cheng=cur->next->zhi_cheng;cur->next->zhi_cheng=temp;
temp=cur->zhuan_ye;cur->zhuan_ye=cur->next->zhuan_ye;cur->next->zhuan_ye=temp;
}
cur=cur->next;
}
tail=cur;
cur=head.next;
}
int count=0;
if(p)
{
system("cls");
teacher_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->xi_bu<<"教师共有"<<count<<"人。\n";
break;
}
if(p->xi_bu!=p->next->xi_bu)
{
__();
cout<<p->xi_bu<<"教师共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
teacher_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="3")
{
Teacher *cur,*tail;
cur=head.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->zhi_cheng>cur->next->zhi_cheng)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->xi_bu;cur->xi_bu=cur->next->xi_bu;cur->next->xi_bu=temp;
temp=cur->zhi_cheng;cur->zhi_cheng=cur->next->zhi_cheng;cur->next->zhi_cheng=temp;
temp=cur->zhuan_ye;cur->zhuan_ye=cur->next->zhuan_ye;cur->next->zhuan_ye=temp;
}
cur=cur->next;
}
tail=cur;
cur=head.next;
}
int count=0;
if(p)
{
system("cls");
teacher_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->zhi_cheng<<"教师共有"<<count<<"人。\n";
break;
}
if(p->zhi_cheng!=p->next->zhi_cheng)
{
__();
cout<<p->zhi_cheng<<"教师共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
teacher_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="4")
teacherfun(menu());
else
cout<<"您的输入有误,请重新输入:";
}
}
int jdadd(Teacher *p2)
{
Teacher *pt=&head;
if(!p2)
return 0;
if(yn(p2->number))
{
cout<<"编号为"<<p2->number<<"的信息已经存在!\n";
return 0;
}
while(pt->next)
pt=pt->next;
pt->next=p2;
p2->next=NULL;
return 1;
}
void teacherSave()
{
ofstream out("teacher.dat",ios::binary);
Teacher *pstu = &head;
int i = 0, count = rencount();
if(!out)
{
cout<<"打开待写入的文件失败!\n";
system("pause");teacherfun(menu());
}
if(question("您确定要保存吗?"))
{
out.write((char *) &count,sizeof(count));
while(pstu->next)
{
out.write((char*) pstu->next,sizeof(Teacher));
++i;
pstu = pstu->next;
}
out.close();
if(i == count)
{
printf("成功的写入了%d条教师信息。\n", count);
}
else
{
printf("应写入%d条教师信息,实际写入%d条教师信息。\n", count, i);
}
}
}
void delall()
{
Teacher *p=head.next,*temp;
int count=0;
if(question("确定要删除当前所有信息吗?"))
{
while(p)
{
temp=p;
p=p->next;
free(temp);
++count;
}
head.next=NULL;
printf("共删除了%d条信息!\n",count);
}
}
int rencount()
{
int count=0;
Teacher *p=&head;
while(p->next)
{
count++;
p=p->next;
}
printf("\n当前共有%d条信息。\n",count);
return(count);
}
void shiyanadd()
{
string num,na,se,shi,zhi;string ag;
cout<<"请输入您要添加的信息!"<<endl;
cout<<"编号:";cin>>num;
while(shiyanyn(num))
{
cout<<"该编号已存在,请重新输入:\n";
cin>>num;
}
cout<<"姓名:";cin>>na;
cout<<"性别:";cin>>se;
while(se!="男"&&se!="女")
{
cout<<"输入的性别有误!!!\n请重新输入:";
cin>>se;
}
cout<<"年龄:";cin>>ag;
cout<<"实验室:";cin>>shi;
cout<<"职务:";cin>>zhi;
shiyan *T=new shiyan(num,na,se,ag,shi,zhi);
shiyanjdadd(T);
}
int shiyanjdadd(shiyan *p1)
{
shiyan *pt=&head1;
if(!p1)
return 0;
if(shiyanyn(p1->number))
{
cout<<"编号为"<<p1->number<<"的信息已经存在!\n";
return 0;
}
while(pt->next)
pt=pt->next;
pt->next=p1;
p1->next=NULL;
return 1;
}
int shiyanyn(string num)
{
shiyan *p=head1.next;
while(p)
if(num==p->number)
return 1;
else
p=p->next;
return 0;
}
void shiyansearch()
{
shiyan *p=head1.next;
cout<<"请输入你要查找信息的编号或姓名:\n";
string nn;
cin>>nn;
int i=0;
shiyan *temp=&head1;
while(p)
{
if(nn==p->number||nn==p->name)
{
i++;
shiyan_list();
p->point();
__();
shiyanbain_ji(*temp);
}
temp=p;
p=p->next;
}
if(!i)
cout<<"您所查找的信息不存在!!!\n";
}
void shiyanbain_ji(shiyan &p1)
{
string a;
while(1)
{
cout<<"您可以对以上信息进行以下操作:\n";
cout<<"1.修改 2.删除 3.返回主菜单\n您的选择是:";
cin>>a;
if(a =="1")
{
string se,num;
cout<<"请输入您要修改信息!"<<endl;
cout<<"编号:";cin>>num;
while(shiyanyn(num))
{
if(num==p1.next->number)
break;
cout<<"该编号已存在,请重新输入:\n";
cin>>num;
}
p1.next->number=num;
cout<<"姓名:";cin>>p1.next->name;
cout<<"性别:";cin>>se;
while(se!="男"&&se!="女")
{
cout<<"输入的性别有误!!!\n请重新输入:";
cin>>se;
}
p1.next->sex=se;
cout<<"年龄:";cin>>p1.next->age;
cout<<"实验室:";cin>>p1.next->shiyanshi;
cout<<"职务:";cin>>p1.next->zhiwu;
cout<<"信息修改成功!\n";
break;
}
else if(a=="2")
{
if(question("确定要删除该信息吗?"))
{
shiyan *t=p1.next->next;
p1.next=t;
cout<<"删除成功!\n";
break;
}
}
else if(a=="3")
shiyanfun(shiyanmenu());
else
cout<<"输入错误!!!\n请重新输入:";
}
}
void shiyan_tong_ji()
{
shiyan *p=head1.next;
if(!p)
{
cout<<"信息为空!!\n";
return;
}
cout<<"你可以选择的统计方式:1.按性别统计 2.按实验室统计 3.返回主菜单\n请输入你的选择:";
string a;
while(1)
{
cin>>a;
if(a=="1")
{
shiyan *cur,*tail;
cur=head1.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head1.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->sex>cur->next->sex)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->shiyanshi;cur->shiyanshi=cur->next->shiyanshi;cur->next->shiyanshi=temp;
temp=cur->zhiwu;cur->zhiwu=cur->next->zhiwu;cur->next->zhiwu=temp;
}
cur=cur->next;
}
tail=cur;
cur=head1.next;
}
int count=0;
if(p)
{
system("cls");
shiyan_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->sex<<"性实验员共有"<<count<<"人。\n";
break;
}
if(p->sex!=p->next->sex)
{
__();;
cout<<p->sex<<"性实验员共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
shiyan_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="2")
{
shiyan *cur,*tail;
cur=head1.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head1.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->shiyanshi>cur->next->shiyanshi)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->shiyanshi;cur->shiyanshi=cur->next->shiyanshi;cur->next->shiyanshi=temp;
temp=cur->zhiwu;cur->zhiwu=cur->next->zhiwu;cur->next->zhiwu=temp;
}
cur=cur->next;
}
tail=cur;
cur=head1.next;
}
int count=0;
if(p)
{
system("cls");
teacher_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->shiyanshi<<"实验员共有"<<count<<"人。\n";
break;
}
if(p->shiyanshi!=p->next->shiyanshi)
{
__();
cout<<p->shiyanshi<<"实验员共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
shiyan_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="3")
shiyanfun(shiyanmenu());
else
cout<<"您的输入有误,请重新输入:";
}
}
void shiyandelall()
{
shiyan *p=head1.next,*temp;
int count=0;
if(question("确定要删除当前所有信息吗?"))
{
while(p)
{
temp=p;
p=p->next;
free(temp);
++count;
}
head1.next=NULL;
printf("共删除了%d条信息!\n",count);
}
}
int shiyanrencount()
{
int count=0;
shiyan *p=&head1;
while(p->next)
{
count++;
p=p->next;
}
printf("\n当前共有%d条信息。\n",count);
return(count);
}
void shiyanSave()
{
ofstream out("shiyanyuan.dat",ios::binary);
shiyan *pstu = &head1;
int i = 0, count = shiyanrencount();
if(!out)
{
cout<<"打开待写入的文件失败!\n";
system("pause");shiyanfun(shiyanmenu());
}
if(question("您确定要保存吗?"))
{
out.write((char *) &count,sizeof(count));
while(pstu->next)
{
out.write((char*) pstu->next,sizeof(shiyan));
++i;
pstu = pstu->next;
}
out.close();
if(i == count)
{
printf("成功的写入了%d条信息。\n", count);
}
else
{
printf("应写入%d条信息,实际写入%d条信息。\n", count, i);
}
}
}
void xzadd()
{
string num,na,se,xi,zhuan,zhi;string ag;
cout<<"请输入您要添加的信息!"<<endl;
cout<<"编号:";cin>>num;
while(xzyn(num))
{
cout<<"该编号已存在,请重新输入:\n";
cin>>num;
}
cout<<"姓名:";cin>>na;
cout<<"性别:";cin>>se;
while(se!="男"&&se!="女")
{
cout<<"输入的性别有误!!!\n请重新输入:";
cin>>se;
}
cout<<"年龄:";cin>>ag;
cout<<"部门:";cin>>xi;
cout<<"政治面貌:";cin>>zhuan;
cout<<"职称:";cin>>zhi;
xingzheng *T=new xingzheng(num,na,se,ag,xi,zhuan,zhi);
xzjdadd(T);
}
int xzyn(string num)
{
xingzheng *p=head2.next;
while(p)
if(num==p->number)
return 1;
else
p=p->next;
return 0;
}
void xzsearch()
{
xingzheng *p=head2.next;
cout<<"请输入你要查找信息的编号或姓名:\n";
string nn;
cin>>nn;
int i=0;
xingzheng *temp=&head2;
while(p)
{
if(nn==p->number||nn==p->name)
{
i++;
xingzheng_list();
p->point();
__();
xzbain_ji(*temp);
}
temp=p;
p=p->next;
}
if(!i)
cout<<"您所查找的信息不存在!!!\n";
}
void xzbain_ji(xingzheng &p1)
{
string a;
while(1)
{
cout<<"您可以对以上信息进行以下操作:\n";
cout<<"1.修改 2.删除 3.返回主菜单\n您的选择是:";
cin>>a;
if(a =="1")
{
string se,num;
cout<<"请输入您要修改信息!"<<endl;
cout<<"编号:";cin>>num;
while(yn(num))
{
if(num==p1.next->number)
break;
cout<<"该编号已存在,请重新输入:\n";
cin>>num;
}
p1.next->number=num;
cout<<"姓名:";cin>>p1.next->name;
cout<<"性别:";cin>>se;
while(se!="男"&&se!="女")
{
cout<<"输入的性别有误!!!\n请重新输入:";
cin>>se;
}
p1.next->sex=se;
cout<<"年龄:";cin>>p1.next->age;
cout<<"部门:";cin>>p1.next->bumen;
cout<<"政治面貌:";cin>>p1.next->zhengzhi;
cout<<"职称:";cin>>p1.next->zhicheng;
cout<<"信息修改成功!\n";
break;
}
else if(a=="2")
{
if(question("确定要删除该信息吗?"))
{
xingzheng *t=p1.next->next;
p1.next=t;
cout<<"删除成功!\n";
break;
}
}
else if(a=="3")
xzfun(xzmenu());
else
cout<<"输入错误!!!\n请重新输入:";
}
}
void xz_tong_ji()
{
xingzheng *p=head2.next;
if(!p)
{
cout<<"信息为空!!\n";
return;
}
cout<<"你可以选择的统计方式:1.按性别统计 2.按部门统计 3.按职称统计 4.返回主菜单\n请输入你的选择:";
string a;
while(1)
{
cin>>a;
if(a=="1")
{
xingzheng *cur,*tail;
cur=head2.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head2.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->sex>cur->next->sex)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->bumen;cur->bumen=cur->next->bumen;cur->next->bumen=temp;
temp=cur->zhengzhi;cur->zhengzhi=cur->next->zhengzhi;cur->next->zhengzhi=temp;
temp=cur->zhicheng;cur->zhicheng=cur->next->zhicheng;cur->next->zhicheng=temp;
}
cur=cur->next;
}
tail=cur;
cur=head2.next;
}
int count=0;
if(p)
{
system("cls");
xingzheng_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->sex<<"性共有"<<count<<"人。\n";
break;
}
if(p->sex!=p->next->sex)
{
__();;
cout<<p->sex<<"性共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
xingzheng_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="2")
{
xingzheng *cur,*tail;
cur=head2.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head2.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->bumen>cur->next->bumen)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->bumen;cur->bumen=cur->next->bumen;cur->next->bumen=temp;
temp=cur->zhengzhi;cur->zhengzhi=cur->next->zhengzhi;cur->next->zhengzhi=temp;
temp=cur->zhicheng;cur->zhicheng=cur->next->zhicheng;cur->next->zhicheng=temp;
}
cur=cur->next;
}
tail=cur;
cur=head2.next;
}
int count=0;
if(p)
{
system("cls");
xingzheng_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->bumen<<"共有"<<count<<"人。\n";
break;
}
if(p->bumen!=p->next->bumen)
{
__();;
cout<<p->bumen<<"共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
xingzheng_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="3")
{
xingzheng *cur,*tail;
cur=head2.next;
tail=NULL;
if(cur==NULL||cur->next==NULL)
if(!head2.next)
return;
while(cur!=tail)
{
while(cur->next!=tail)
{
if(cur->zhicheng>cur->next->zhicheng)
{
string temp=cur->age;cur->age=cur->next->age;cur->next->age=temp;
temp=cur->name;cur->name=cur->next->name;cur->next->name=temp;
temp=cur->number;cur->number=cur->next->number;cur->next->number=temp;
temp=cur->sex;cur->sex=cur->next->sex;cur->next->sex=temp;
temp=cur->bumen;cur->bumen=cur->next->bumen;cur->next->bumen=temp;
temp=cur->zhengzhi;cur->zhengzhi=cur->next->zhengzhi;cur->next->zhengzhi=temp;
temp=cur->zhicheng;cur->zhicheng=cur->next->zhicheng;cur->next->zhicheng=temp;
}
cur=cur->next;
}
tail=cur;
cur=head2.next;
}
int count=0;
if(p)
{
system("cls");
xingzheng_list();
while(p)
{
p->point();
count++;
if(!p->next)
{
__();
cout<<p->zhicheng<<"共有"<<count<<"人。\n";
break;
}
if(p->sex!=p->next->sex)
{
__();;
cout<<p->zhicheng<<"共有"<<count<<"人。\n";
count=0;cout<<endl<<endl;
xingzheng_list();
}
p=p->next;
}
}
else
cout<<"信息为空!!!\n";
break;
}
else if(a=="4")
xzfun(xzmenu());
else
cout<<"您的输入有误,请重新输入:";
}
}
void xzSave()
{
ofstream out("xz.dat",ios::binary);
xingzheng *pstu = &head2;
int i = 0, count = xzrencount();
if(!out)
{
cout<<"打开待写入的文件失败!\n";
system("pause");xzfun(xzmenu());
}
if(question("您确定要保存吗?"))
{
out.write((char *) &count,sizeof(count));
while(pstu->next)
{
out.write((char*) pstu->next,sizeof(xingzheng));
++i;
pstu = pstu->next;
}
out.close();
if(i == count)
{
printf("成功的写入了%d条信息。\n", count);
}
else
{
printf("应写入%d条信息,实际写入%d条信息。\n", count, i);
}
}
}
int xzjdadd(xingzheng *p1)
{
xingzheng *pt=&head2;
if(!p1)
return 0;
if(xzyn(p1->number))
{
cout<<"编号为"<<p1->number<<"的信息已经存在!\n";
return 0;
}
while(pt->next)
pt=pt->next;
pt->next=p1;
p1->next=NULL;
return 1;
}
void xzdelall()
{
xingzheng *p=head2.next,*temp;
int count=0;
if(question("确定要删除当前所有信息吗?"))
{
while(p)
{
temp=p;
p=p->next;
free(temp);
++count;
}
head2.next=NULL;
printf("共删除了%d条信息!\n",count);
}
}
int xzrencount()
{
int count=0;
xingzheng *p=&head2;
while(p->next)
{
count++;
p=p->next;
}
printf("\n当前共有%d条信息。\n",count);
return(count);
}
void home()
{
system("cls");
char c;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 1.教师信息管理系统 2.实验员信息管理系统 3.行政人员信息管理系统 4.退出\n";
cout<<endl;
cout<<" 请选择管理系统:";
while(1)
{
cin>>c;
if(c=='1')
{
int i, count = 0;
FILE *pf;
Teacher *pstu;
if((pf = fopen("teacher.dat", "rb")) == NULL)
{
cout<<"当前信息为空,请载入文件或输入信息!!!\n";
system("pause"); teacherfun(menu());
}
fread(&count, 1, sizeof count, pf);
for(i = 0;i<count;i++)
{
Teacher *pstu = new Teacher;
fread(pstu, 1, sizeof(Teacher), pf);
jdadd(pstu);
}
fclose(pf);
teacherfun(menu());
}
else if(c=='2')
{
int i, count = 0;
ifstream in("shiyanyuan.dat",ios::binary);
if(!in)
{
cout<<"当前信息为空,请载入文件或输入信息!!!\n";
system("pause"); shiyanfun(shiyanmenu());
}
in.read((char *) &count,sizeof(count));
for(i = 0;i<count;i++)
{
shiyan *pstu = new shiyan;
in.read((char*) pstu,sizeof(shiyan));
shiyanjdadd(pstu);
}
in.close();
shiyanfun(shiyanmenu());
}
else if(c=='3')
{
int i, count = 0;
ifstream in("xz.dat",ios::binary);
if(!in)
{
cout<<"当前信息为空,请载入文件或输入信息!!!\n";
system("pause"); xzfun(xzmenu());
}
in.read((char *) &count,sizeof(count));
for(i = 0;i<count;i++)
{
xingzheng *pstu = new xingzheng;
in.read((char*) pstu,sizeof(xingzheng));
xzjdadd(pstu);
}
in.close();
xzfun(xzmenu());
}
else if(c=='4')
{
tuichu();
exit(1);
}
else
cout<<"输入错误,请重新输入:\n";
}
}
void huanying()
{
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
PlaySound(TEXT("hello.wav"), NULL, SND_FILENAME | SND_ASYNC);
cout<<" 欢迎使用高校人才信息管理系统\n";
cout<<endl<<endl;
cout<<" Welcome to the use of university talent information management system.\n\n";
}
void tuichu()
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 感谢您使用高校人才信息管理系统,再见!\n";
cout<<endl<<endl;
cout<<" Thank you for using the university talent information management system, goodbye!\n\n";
PlaySound(TEXT("退出音效.wav"), NULL, SND_FILENAME | SND_SYNC);
exit(0);
}
void login()
{
int i=3,j=0;
char password1[20]="201821111134",user[20],password[20];
char user1[20]={"徐世兴"},ch;
huanying();
cout<<" 请输入您的用户名:";
scanf("%s",user);
while(strcmp(user1,user)!=0)
{
printf(" 该用户名不存在,请重新输入! 您还有%d次机会。\n\n",i);
printf(" 请您重新输入:");
scanf("%s",user);
i--;
if(!i)
{
tuichu();
}
}
printf(" 请输入您的密码:");
ch=getch();
while(ch!='\r'||ch=='\b')
{
if(ch!='\b')
{
password[j]=ch;
printf("*");
j++;
}
else
{
j-=1;
printf("\b");
printf(" ");
printf("\b");
}
ch=getch();
}
i=3;password[j]=NULL;
while(strcmp(password1,password)!=0)
{
printf("\n 密码错误,请重新输入! 您还有%d次机会。\n",i);
printf(" 请您重新输入:");
ch=getch();
j=0;
while(ch!='\r'||ch=='\b')
{
if(ch!='\b')
{
password[j]=ch;
printf("*");j++;
}
else
{
j-=1;
printf("\b");
printf(" ");
printf("\b");
}
ch=getch();
}
i--;
if(!i)
{
tuichu();
}
}
}
int main()
{
login();
home();
return 0;
}