1、教职员信息管理系统源码#include #include #include #include#define maxsize 100 fstream iofile; /文件指针class Time /时间类 public: int year; int month; int day; class Telem /个人信息 public: char name20; char sex10; Time birthtime; /组合Time类 char num20; char wage20; Time worktime; int year; char department20; friend istream
2、& operator(istream& input,Telem& T); friend ostream& operator(ostream& output,Telem& T); friend int operator-(Time & t1,Time & t2); ; class People:virtual public Telem /雇员类 public: People(); virtual void AddF()=0; /添加 virtual void Addall()=0; virtual void Add()=0; virtual void Display(); /输出数组内容 vir
3、tual void Displaypart(char p); virtual void Findname(char n); virtual void Findyear(int ); virtual void Del(char n)=0; virtual void Del(int ); protected: Telem datamaxsize; Time now; int length; ; class Teacher:virtual public People /派生虚基类 public: virtual void AddF(); virtual void Addall(); virtual
4、void Add(); virtual void Display(); virtual void Del(int i); virtual void Del(char n); ; class worker:virtual public People /派生虚基类 public: virtual void AddF(); virtual void Addall(); virtual void Add(); virtual void Display(); virtual void Del(int i); virtual void Del(char n); ; People:People() /系统自
5、动生成结构函数 length=0; now.year=; now.month=7; now.day=6; void People:Display() /引用 int i; for(i=0;ilength;i+) coutdatai; void People:Displaypart(char p)/引用数组 int i,c; for(i=0;ilength;i+) if(strcmp(datai.wage,p)=0) cout输出选择姓名1 性别2 编号3 工资4 出生日期5 工作时间6 年纪7 系别8 退出选择9c) switch(c) case 1: cout姓名:datai.nameend
6、l;break; case 2: cout性别:datai.sexendl;break; case 3: cout编号:datai.numendl;break; case 4: cout工资:datai.wageendl;break; case 5: cout出生日期:datai.birthtime.year datai.birthtime.month datai.birthtime.day endl;break; case 6: cout工作时间:datai.worktime.year datai.worktime.month datai.worktime.day endl;break; c
7、ase 7: cout年纪:datai.yearendl;break; case 8: cout系别:datai.departmentendl;break; case 9: goto loop; default:cout操作错误.endl; loop:; void People:Findname(char n) /引用 int i; for(i=0;ilength;i+) if(strcmp(datai.name,n)=0) /对象引用 coutdatai; void People:Findyear(int y) int i; for(i=0;ilength;i+) if(datai.year
8、=y) coutdatai; void People:Del(int i) int j; if(ilength) cout不存在第i个元素; for(j=i;jlength;j+) dataj-1=dataj; length-; void worker:AddF() int flag=0; iofile.open(worker_information.txt,ios:in|ios:binary); /文件打开和关闭 while(iofile.seekg(ios:cur) iofile.seekg(length*sizeof(datalength),ios:beg); iofile.read(c
9、har*)&datalength,sizeof(datalength); /文件随机访问 length+; if(length=maxsize) flag=1; goto loop; People:Del(length); cout添加人员信息成功.endl; loop: if(1=flag) cout人员信息储存空间已满.datalength; datalength.year=now-datalength.birthtime; iofile.write(char*)&datalength,sizeof(datalength); cout添加人员信息成功.endl; length+; if(l
10、ength=maxsize) flag=1; goto loop; coutans; while(y=ans|Y=ans); loop: if(1=flag) cout人员信息储存空间已满.datalength; datalength.year=now-datalength.birthtime; iofile.write(char*)&datalength,sizeof(datalength); cout添加人员信息成功.endl; length+; loop: if(1=flag) cout人员信息储存空间已满.endl; iofile.close(); void worker:Displa
11、y() cout 工人信息 endl; if(0=length) cout无.endl; int i; for(i=0;ilength;i+) coutdatai; void worker:Del(char n) int i,j,k; for(i=0;ilength;i+) if(strcmp(datai.name,n)=0) k=i+1;break; if(k1) cout不存在姓名n人员信息; for(j=k;jlength;j+) dataj-1=dataj; length-; cout删除人员信息成功.endl; void worker:Del(int i) int j; if(ile
12、ngth) cout不存在第i个元素; for(j=i;jlength;j+) dataj-1=dataj; length-; cout删除成功.endl; void Teacher:AddF() int flag=0; iofile.open(Teacher_information.txt,ios:in|ios:binary); while(iofile.seekg(sizeof(datalength),ios:cur) if(iofile.seekg(length*sizeof(datalength),ios:beg) iofile.read(char*)&datalength,sizeo
13、f(datalength); else break; length+; if(length=maxsize) flag=1; goto loop; People:Del(length); cout添加人员信息成功.endl; loop: if(1=flag) cout人员信息储存空间已满.datalength; datalength.year=now-datalength.birthtime; iofile.write(char*)&datalength,sizeof(datalength); cout添加人员信息成功.endl; length+; if(length=maxsize) fla
14、g=1; goto loop; coutans; while(y=ans|Y=ans); loop: if(1=flag) cout人员信息储存空间已满.datalength; datalength.year=now-datalength.birthtime; iofile.write(char*)&datalength,sizeof(datalength); cout添加人员信息成功.endl; length+; loop: if(1=flag) cout人员信息储存空间已满.endl; iofile.close(); void Teacher:Display() cout 老师信息 end
15、l; if(0=length) cout无.endl; int i; for(i=0;ilength;i+) coutdatai; void Teacher:Del(char n) int i,j,k; for(i=0;ilength;i+) if(strcmp(datai.name,n)=0) k=i+1;break; if(k1) cout不存在姓名n人员信息; for(j=k;jlength;j+) dataj-1=dataj; length-; cout删除人员信息成功.endl; void Teacher:Del(int i) int j; if(ilength) cout不存在第i
16、个元素; for(j=i;jlength;j+) dataj-1=dataj; length-; cout删除成功.(istream& input,Telem& T) int y,m,d; cout请输入姓名(以*结尾):endl; input.getline(T.name,20,*); cout请输入性别(以*结尾 男或女):endl; input.getline(T.sex,10,*); cout编号(以*结尾):endl; input.getline(T.num,20,*); cout工资(以*结尾):endl; input.getline(T.wage,20,*); cout请输入出生
17、日期:ymd; T.birthtime.year=(y=1900&y=1&m=1&d=31)?d:1; cout请输入系别(以*结尾):endl; input.getline(T.department,20,*); cout参与工作时间:ymd; T.worktime.year=(y=1900&y=1&m=1&d=31)?d:1; return input; ostream& operator(ostream& output,Telem& T) cout姓名:; outputT.nameendl; cout性别:; outputT.sexendl; cout编号:; outputT.numen
18、dl; cout工资:; outputT.wageendl; cout出生日期:; outputT.birthtime.year T.birthtime.month T.birthtime.dayendl; cout系别:; outputT. departmentendl; cout参与工作时间:; outputT.worktime.year T.worktime.month T.worktime.dayendl; cout年纪:; outputT.yearendl; return output; int operator-(Time & t1,Time & t2) return t1.yea
19、r-t2.year; void Showmenu() coutendl; cout 欢 迎 进 入 教 职 工 信 息 管 理 系 统endlendl; cout 年7月7日公布 版权全部: swaendlendlendl; cout 人员信息管理系统 endlendl; cout 1-从键盘录入全部人员统计 endlendl; cout 2-增加一位人员统计 endlendl; cout 3-显示全部人员统计 endlendl; cout 4-按系别输出人员信息(可选) endlendl; cout 5-按姓名或年纪检索全部信息 endlendl; cout 6-显示菜单目录 endlend
20、l; cout 7-结束程序运行 endlendl; cout endl; int main() Teacher tea; worker stu; People *pt=&tea; People *ps=&stu; int c=0,k=0,l=0,i=0; char nam20,part20; Showmenu(); for(;) coutc; switch(c) case 1: cout 录入全部人员统计 endl; cout 从键盘输入老师信息 Addall(); cout 从键盘输入工人信息 Addall(); break; case 2: cout 从键盘增加一位人员统计 endl;
21、cout 老师操作请按1 工人操作请按2 k; if(1=k) pt-Add(); else if(2=k) ps-Add(); else cout操作错误.endl; break; case 3: cout 显示全部人员统计 Display(); ps-Display(); break; case 4: cout 按部门输出人员信息(可选) endl; cout 老师操作请按1 工人操作请按2 k; if(1=k) cout请输入要输出人员系别(以*结尾):Displaypart(part); else if(2=k) cout请输入要输出人员系别(以*结尾):Displaypart(par
22、t); else cout操作错误.endl; break; case 5: cout 按姓名或年纪检索全部信息 endl; cout 按姓名查找1 按年纪查找2 k; if(1=k) cout按姓名查找1 按年纪查找2l; if (1=l) cout请输入要查找人员姓名(以*结尾):Findname(nam); else if(2=l) cout请输入要查找人年纪:i; pt-Findyear(i); else cout操作错误.endl; else if(2=k) cout按姓名查找1 按年纪查找2l; if (1=l) cout请输入要查找人员姓名(以*结尾):Findname(nam); else if(2=l) cout请输入要查找人年纪:i; ps-Findyear(i); else cout操作错误.endl; else cout操作错误.endl; break; case 6: cout 显示菜单目录 endl; Showmenu(); break; case 7: