第一篇:C++课程设计 教职工信息管理系统源代码
教职工信息管理系统源码
#include
#define maxsize 100 fstream iofile;//文件指针
class Time //时间类 {
public:
int year;
int month;
int day;};
class Telem //个人信息 {
public:
char name[20];
char sex[10];
Time birthtime;//组合Time类
char num[20];
char wage[20];
Time worktime;
int year;
char department[20];
friend istream& 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();//输出数组的内容
virtual 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 data[maxsize];
Time now;
int length;};
class Teacher: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[]);};
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()//系统自动生成的构造函数 {
length=0;
now.year=2010;
now.month=7;
now.day=6;}
void People::Display()//引用 {
int i;
for(i=0;i cout< void People::Displaypart(char p[])//引用数组 { int i,c; for(i=0;i if(strcmp(data[i].wage,p)==0) { cout<<“输出选择姓名1 性别2 编号3 工资4 出生日期5 工作时间6 年龄7 系别8 退出选择9”< while(cin>>c) { switch(c) { case 1: cout<<“姓名:”< case 2: cout<<“性别:”< case 3: cout<<“编号:”< case 4: cout<<“工资:”< case 5: cout<<“出生日期:”< case 6: cout<<“工作时间:”< case 7: cout<<“年龄:”< case 8: cout<<“系别:”< case 9: goto loop; default:cout<<“操作错误......”< } } loop:; } } void People::Findname(char n[])//引用 { int i; for(i=0;i if(strcmp(data[i].name,n)==0)//对象引用 cout< void People::Findyear(int y){ int i; for(i=0;i if(data[i].year==y) cout< void People::Del(int i){ int j; if(i<1||i>length) cout<<“不存在第”< for(j=i;j data[j-1]=data[j]; 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(data[length]),ios::beg); iofile.read((char*)&data[length],sizeof(data[length]));//文件的随机访问 length++; if(length==maxsize) { flag=1; goto loop; } } People::Del(length); cout<<“添加人员信息成功......”< loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void worker::Addall(){ char ans; int flag=0; iofile.open(“worker_information.txt”,ios::out|ios::binary); do { cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++; if(length==maxsize) { flag=1; goto loop; } cout<<“contine(Y|N)?”; cin>>ans; }while('y'==ans||'Y'==ans);loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void worker::Add(){ int flag=0; iofile.open(“worker_information.txt”,ios::app|ios::out|ios::binary); if(length==maxsize) { flag=1; goto loop; } cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++; loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void worker::Display(){ cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆工人信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< if(0==length) cout<<“无......”< int i; for(i=0;i cout< int i,j,k; for(i=0;i if(strcmp(data[i].name,n)==0){ k=i+1;break;} if(k<1) cout<<“不存在姓名”< for(j=k;j data[j-1]=data[j]; length--; cout<<“删除人员信息成功......”< void worker::Del(int i){ int j; if(i<1||i>length) cout<<“不存在第”< for(j=i;j data[j-1]=data[j]; length--; cout<<“删除成功......”< } void Teacher::AddF(){ int flag=0; iofile.open(“Teacher_information.txt”,ios::in|ios::binary); while(iofile.seekg(sizeof(data[length]),ios::cur)) { if(iofile.seekg(length*sizeof(data[length]),ios::beg)) iofile.read((char*)&data[length],sizeof(data[length])); else break; length++; if(length==maxsize) { flag=1; goto loop; } } People::Del(length); cout<<“添加人员信息成功......”< if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void Teacher::Addall(){ char ans; int flag=0; iofile.open(“Teacher_information.txt”,ios::in|ios::out|ios::binary); do { cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++; if(length==maxsize) { flag=1; goto loop; } cout<<“contine(Y|N)?”; cin>>ans; }while('y'==ans||'Y'==ans);loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void Teacher::Add(){ int flag=0; iofile.open(“Teacher_information.txt”,ios::app|ios::out|ios::binary); if(length==maxsize) { flag=1; goto loop; } cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++;loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void Teacher::Display(){ cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆教师信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< if(0==length) cout<<“无......”< int i; for(i=0;i cout< void Teacher::Del(char n[]){ int i,j,k; for(i=0;i if(strcmp(data[i].name,n)==0) { k=i+1;break; } if(k<1)cout<<“不存在姓名”< for(j=k;j data[j-1]=data[j]; length--; cout<<“删除人员信息成功......”< void Teacher::Del(int i){ int j; if(i<1||i>length) cout<<“不存在第”< for(j=i;j data[j-1]=data[j]; length--; cout<<“删除成功......”< istream& operator>>(istream& input,Telem& T){ int y,m,d; cout<<“请输入姓名(以*结尾):”< input.getline(T.name,20,'*'); cout<<“请输入性别(以*结尾 男或女):”< input.getline(T.sex,10,'*'); cout<<“编号(以*结尾):”< input.getline(T.num,20,'*'); cout<<“工资(以*结尾):”< input.getline(T.wage,20,'*'); cout<<“请输入出生日期:”< input>>y>>m>>d; T.birthtime.year=(y>=1900&&y<=2100)?y:1900; T.birthtime.month=(m>=1&&m<=12)?m:1; T.birthtime.day=(d>=1&&d<=31)?d:1; cout<<“请输入系别(以*结尾):”< input.getline(T.department,20,'*'); cout<<“参加工作时间:”< input>>y>>m>>d; T.worktime.year=(y>=1900&&y<=2100)?y:1900; T.worktime.month=(m>=1&&m<=12)?m:1; T.worktime.day=(d>=1&&d<=31)?d:1; return input;} ostream& operator<<(ostream& output,Telem& T){ cout<<“姓名:”; output< cout<<“性别:”; output< cout<<“编号:”; output< cout<<“工资:”; output< cout<<“出生日期:”; output< cout<<“系别:”; output< cout<<“参加工作时间:”; output< cout<<“年龄:”; output< return output;} int operator-(Time & t1,Time & t2){ return t1.year-t2.year;} void Showmenu(){ cout< cout<<“ 欢 迎 进 入 教 职 工 信 息 管 理 系 统”< cout<<“ 2010 年7月7日发布”<<“ 版权所有: swa”< cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★人员信息管理系统★ ☆ ★ ☆ ★ ☆ ★ ☆ ★”< cout<<“ ★ 1-从键盘录入全部人员记录 ☆ ”< cout<<“ ☆ 2-增加一位人员记录 ★”< cout<<“ ★ 3-显示全部人员记录 ☆”< cout<<“ ☆ 4-按系别输出人员信息(可选)★ ”< cout<<“ ★ 5-按姓名或年龄检索所有信息☆ ”< cout<<“ ☆ 6-显示菜单目录 ★ ”< cout<<“ ★ 7-结束程序运行 ☆ ”< cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< int main(){ Teacher tea; worker stu; People *pt=&tea; People *ps=&stu; int c=0,k=0,l=0,i=0; char nam[20],part[20];Showmenu(); for(;;) { cout<<“请根据菜单执行相应操作: ”; cin>>c; switch(c) { case 1: { cout<<“ ★ ☆ ★ ☆ ★ ☆ ★录入全部人员记录 ★ ☆ ★ ☆ ★ ☆ ★”< cout<<“ ★ ☆ ★ ☆ ★从键盘输入教师信息 ☆ ★ ☆ ★ ☆”< pt->Addall(); cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆从键盘输入工人信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< ps->Addall(); break; } case 2: { cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆从键盘增加一位人员记录 ★ ☆ ★ ☆ ★ ☆ ★ ☆”< cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆教师操作请按1 工人操作请按2 ★ ☆ ★ ☆ ★ ☆ ★ ☆”< cin>>k; if(1==k) pt->Add(); else if(2==k) ps->Add(); else cout<<“操作错误...”< break; } case 3: { cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆显示全部人员记录 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< pt->Display(); ps->Display(); break; } case 4: { cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆按部门输出人员信息(可选)★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< cout<<“ ★ ☆ ★ ☆ ★ ☆教师操作请按1 工人操作请按2 ★ ☆ ★ ☆ ★ ☆”< cin>>k; if(1==k) { cout<<“请输入要输出人员的系别(以*结尾):”< pt->Displaypart(part); } else if(2==k) { cout<<“请输入要输出人员的系别(以*结尾):”< ps->Displaypart(part); } else cout<<“操作错误......”< break; } case 5: { cout<<“ ★ ☆ ★ ☆ ★ ☆ ★按姓名或年龄检索所有信息 ★ ☆ ★ ☆ ★ ☆ ★”< cout<<“ ★ ☆ ★ ☆ ★ ☆ ★按姓名查找1 按年龄查找2 ★ ☆ ★ ☆ ★ ☆ ★”< cin>>k; if(1==k) { cout<<“按姓名查找1 按年龄查找2”< if(1==l) { cout<<“请输入要查找人员的姓名(以*结尾):”< pt->Findname(nam); } else if(2==l) { cout<<“请输入要查找人的年龄:”< pt->Findyear(i); } else cout<<“操作错误......”< } else if(2==k) { cout<<“按姓名查找1 按年龄查找2”< if(1==l) { cout<<“请输入要查找人员的姓名(以*结尾):”< ps->Findname(nam); } else if(2==l) { cout<<“请输入要查找人的年龄:”< ps->Findyear(i); } else cout<<“操作错误......”< } else cout<<“操作错误......”< break; } case 6: { cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆显示菜单目录 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< Showmenu(); break; } case 7: { cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆结束程序运行 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< exit(0); } default:cout<<“操作错误......”< } } return 0;} #include const N=5000;// 定义系统可录入的职工最大数值 string Ename[N];long Enum[N];char Esex[N];int Eage[N]; char Emarriage[N];int Edepart[N];int Eposition[N];int Edegree[N];int Eworktime[N];float Epay[N]; class Employee { public: string Employeename; long Employeenum; char Employeesex; int Employeeage; char Employeemarriage; int Employeedepart; int Employeeposition; int Employeedegree; int Employeeworktime; float Employeepay; static long EmployeeMaxNum; static float EmployeeBasePay; void NewInfo(); void ShowInfo(); void showall(); void showdepart(int depart); void showdegree(int degree); void showage(int min,int max); void shownum(long number); void RefreshInfo(); void DeleteInfo(); float Pay(int Employeegrade); static int MaxNum();}; class DBOperate { public: string Employeename; long Employeenum; char Employeesex; int Employeeage; char Employeemarriage; int Employeedepart; int Employeeposition; int Employeedegree; int Employeeworktime; float Employeepay; static long EmployeeMaxNum; static float EmployeeBasePay; void WriteIn(int iflag); void ReadOut(); void RefreshMaxNum(int iflag);//iflg=1 or-1 or 0 }; long Employee::EmployeeMaxNum = 1000;float Employee::EmployeeBasePay = 1500; int Employee::MaxNum()//返回系统已经存储的人数 { int MN = 0; ifstream myf; myf.open(“EmployeeMaxNum.txt”); myf>>MN; cout< myf.close(); return MN;} void Employee::NewInfo()//添加新职工函数 { cout<<“新职工姓名: ”; cin>>Employee::Employeename; Employee::Employeenum = EmployeeMaxNum + Employee::MaxNum()+1; cout<<“新职工性别(F为女性,M为男性): ”; cin>>Employee::Employeesex; cout<<“新职工年龄: ”; cin>>Employee::Employeeage; cout<<“新职工婚姻状况(Y为已婚,N为未婚): ”; cin>>Employee::Employeemarriage; cout<<“新职工学历,请输入相应学历的序号: ”< cout<<“ [1:小学 2:初中 3:高中 4:本科 5:硕士 6:博士] ”; cin>>Employee::Employeedegree; while(Employee::Employeedegree!=1&&Employee::Employeedegree!=2&&Employee::Employeedegree!=3&&Employee::Employeedegree!=4&&Employee::Employeedegree!=5&&Employee::Employeedegree!=6) { cout<<“输入有误,请重新输入:”< cout<<“ [1:小学 2:初中 3:高中 4:本科 5:硕士 6:博士] ”; cin>>Employee::Employeedegree; } cout<<“新职工所在部门,请输入相应部门的序号:”< cout<<“ [1:董事会 2:销售部 3:人事部 4:客服中心 5:财务部 6:技术研发部 7:安全监察部] ”; cin>>Employee::Employeedepart; while(Employee::Employeedepart!=1&&Employee::Employeedepart!=2&&Employee::Employeedepart!=3&&Employee::Employeedepart!=4&&Employee::Employeedepart!=5&&Employee::Employeedepart!=6&&Employee::Employeedepart!=7) { cout<<“输入有误,请重新输入:”< cout<<“ [1:董事会 2:销售部 3:人事部 4:客服中心 5:财务部 6:技术研发部 7:安全监察部] ”; cin>>Employee::Employeedepart; } cout<<“新职工职位, 请输入相应职位的序号: ”< cout<<“ [1:临时职工 2: 正式职工 3:部门经理 4:主任 5:董事长] ”; cin>>Employee::Employeeposition; while(Employee::Employeeposition!=1&&Employee::Employeeposition!=2&&Employee::Employeeposition!=3&&Employee::Employeeposition!=4&&Employee::Employeeposition!=5) { cout<<“输入有误,请重新输入:”< cout<<“ [1:临时职员 2: 正式职员 3:部门经理 4:主任 5:董事长] ”; cin>>Employee::Employeeposition; } cout<<“新职工的工作时长(不需要输入单位): ”; cin>>Employee::Employeeworktime; Employee::Employeepay = Employee::Pay(Employee::Employeeposition); DBOperate dbo; dbo.ReadOut(); int MaxNum = Employee::MaxNum(); Enum[MaxNum] = Employee::Employeenum; Ename[MaxNum] = Employee::Employeename; Esex[MaxNum] = Employee::Employeesex; Eage[MaxNum] = Employee::Employeeage; Emarriage[MaxNum] = Employee::Employeemarriage; Edegree[MaxNum] = Employee::Employeedegree; Edepart[MaxNum] = Employee::Employeedepart; Eposition[MaxNum] = Employee::Employeeposition; Eworktime[MaxNum] = Employee::Employeeworktime; Epay[MaxNum] = Employee::Employeepay; dbo.WriteIn(1); cout<<“ 添加新成员成功!”< void Employee::ShowInfo()//程序主体 数据输出函数 { int choice1,choice2,min,max; long searchnum; Employee e; cout<<“*******************************************”< cout<<“-----------1.输出全体职工信息--------------”< cout<<“-----------2.按职工部门输出----------------”< cout<<“-----------3.按职工学历输出----------------”< cout<<“-----------4.按职工年龄输出----------------”< cout<<“-----------5.按职工编号输出----------------”< cout<<“*******************************************”< cout<<“ 请选择查询方式:”; cin>>choice1; switch(choice1) { case 1: showall();break; case 2: cout<<“请输入要查询职工的部门编号[1:董事会 2:销售部 3:人事部 4:客服中心 5:财务部 6:技术研发部 7:安全监察部] ”; cin>>choice2; e.showdepart(choice2);break; case 3: cout<<“请输入要查询职工的学历编号: [1:小学 2:初中 3:高中 4:本科 5:硕士 6:博士] ”; cin>>choice2; e.showdegree(choice2);break; case 4: cout<<“请输入要查询的年龄范围: ”; cout<<“最小值: ”; cin>>min; cout<<“最大值: ”; cin>>max; e.showage(min,max);break; case 5: cout<<“请输入要查询的职工编号: ”; cin>>searchnum; e.shownum(searchnum);break; default: cout<<“出错啦!”< } } void Employee::showall()//全体职工输出函数 { int i; long number; for(i=0;i { number = Enum[i]; shownum(number); } } void Employee::showdepart(int depart)//按职工所在部门输出函数 { int i; switch(depart) { case 1: cout<<“董事会的成员有: ”< case 2: cout<<“销售部的成员有: ”< case 3: cout<<“人事部的成员有: ”< case 4: cout<<“客服中心的成员有: ”< case 5: cout<<“财务部的成员有: ”< case 6: cout<<“技术研发部的成员有: ”< case 7: cout<<“安全监察部的成员有: ”< default: cout<<“输入错误!>”<第二篇:C++大作业_职工信息管理系统源代码