第一篇:C++大作业_职工信息管理系统源代码
#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<<“输入错误!>”< } for(i=0;i { if(Edepart[i] == depart) { long number = Enum[i]; shownum(number); } else continue; } } void Employee::showdegree(int degree)//按职工学历输出函数 { int i; switch(degree) { case 1:cout<<“初中学历的员工有:”< case 2:cout<<“初中学历的员工有:”< case 3:cout<<“高中学历的员工有:”< case 4:cout<<“本科学历的员工有:”< case 5:cout<<“硕士学位的员工有:”< case 6:cout<<“博士学位的员工有:”< } for(i=0;i { if(Edegree[i] == degree) { long number = Enum[i]; shownum(number); } else continue; } } void Employee::showage(int min,int max)//按职工年龄段输出函数 { int i; for(i=0;i { if(Eage[i]>=min&&Eage[i]<=max) { long number = Enum[i]; shownum(number); } else continue; } } void Employee::shownum(long number)//按职工编号输出函数 { int i; for(i=0;i { if(Enum[i] == number) { cout<<“**********************************”< cout<<“职工编号:”< cout<<“姓 名:”< cout<<“性 别:”; if(Esex[i]=='F')cout<<“女 ”< else if(Esex[i]=='M')cout<<“男 ”< cout<<“年 龄:”< cout<<“婚姻情况:”; if(Emarriage[i]=='Y')cout<<“已婚 ”< else if(Emarriage[i]=='N')cout<<“未婚 ”< cout<<“学 历:”; switch(Edegree[i]) { case 1:cout<<“小 学 ”< case 2:cout<<“初 中 ”< case 3:cout<<“高 中 ”< case 4:cout<<“本 科 ”< case 5:cout<<“硕 士 ”< case 6:cout<<“博 士 ”< } cout<<“所在部门:”; switch(Edepart[i]) { case 1:cout<<“董事会 ”< case 2:cout<<“销售部 ”< case 3:cout<<“人事部 ”< case 4:cout<<“客服中心 ”< case 5:cout<<“财务部 ”< case 6:cout<<“技术研发部 ”< case 7:cout<<“安全监察部 ”< } cout<<“所任职务:”; switch(Eposition[i]) { case 1:cout<<“临时成员 ”< case 2:cout<<“正式员工 ”< case 3:cout<<“部门经理 ”< case 4:cout<<“主任 ”< case 5:cout<<“董事长 ”< } cout<<“工作时长:”< cout<<“工资:”< cout<<“**********************************”< } else continue; } } void Employee::RefreshInfo()//修改职工信息的函数 { int cNum = 1000; DBOperate dbo; dbo.ReadOut(); void Employee::shownum(long number); cout<<“请输入您要修改的职工编号:”; cin>>cNum; int MN; MN = Employee::MaxNum(); for(int i=0;i { if(Enum[i] == cNum) { Employee::shownum(cNum); cout<<“请输入该职工的新信息: ”< cout<<“职工姓名: ”;//录入职工的新的数据,职工编号保持不变 cin>>Employee::Employeename; Ename[i] = Employee::Employeename; cout<<“职工性别(F为女性,M为男性): ”; cin>>Employee::Employeesex; Esex[i] = Employee::Employeesex; cout<<“职工年龄: ”; cin>>Employee::Employeeage; Eage[i] = Employee::Employeeage; cout<<“职工婚姻状况(Y为已婚,N为未婚): ”; cin>>Employee::Employeemarriage; Emarriage[i] = 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; } Edegree[i] = 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; } Edepart[i] = 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; } Eposition[i] = Employee::Employeeposition; cout<<“员工的工作时(不需要输入单位): ”; cin>>Employee::Employeeworktime; Eworktime[i] = Employee::Employeeworktime; Epay[i] = Employee::Pay(Employee::Employeeposition); break; } } dbo.WriteIn(0);} void Employee::DeleteInfo()//删除职工数据的函数 { char tmp; int cNum = 1000; DBOperate dbo; dbo.ReadOut(); void Employee::shownum(long number); cout<<“请输入您要删除的职工编号>: ”; cin>>cNum; int MN; MN = Employee::MaxNum(); for(int i=0;i { if(Enum[i] == cNum) Employee::shownum(cNum); } cout<<“确认要删除该职工信息?(Y为确认,N为放弃): ”; cin>>tmp; if(tmp=='Y') { if(i==MN-1) dbo.WriteIn(-1); else { for(int j=i;j { Enum[j] = Enum[j+1];} dbo.WriteIn(-1); } cout<<“ 删除操作成功!”< } } float Employee::Pay(int Employeeposition)//根据职工职位计算工资的函数 { float tmpPay; tmpPay = Employee::EmployeeBasePay + Employee::Employeeposition Employee::EmployeeBasePay; * return tmpPay;} void DBOperate::WriteIn(int iflag)//数据操作函数—写入 { DBOperate::RefreshMaxNum(iflag); ofstream myf(“Employee.txt”); Employee e; int MN; MN = e.MaxNum(); for(int i=0;i { myf< } myf.close(); return;} void DBOperate::ReadOut()//数据操作函数—读出 { ifstream myf(“Employee.txt”); Employee e; int MN; MN = e.MaxNum(); for(int i=0;i { myf>>DBOperate::Employeenum>>DBOperate::Employeename>>DBOperate::Employeesex>>DBOperate::Employeeage>>DBOperate::Employeemarriage >>DBOperate::Employeedegree>>DBOperate::Employeedepart>>DBOperate::Employeeposition>>DBOperate::Employeeworktime>>DBOperate::Employeepay; Enum[i] = DBOperate::Employeenum; Ename[i] = DBOperate::Employeename; Esex[i] = DBOperate::Employeesex; Eage[i] = DBOperate::Employeeage; Emarriage[i] = DBOperate::Employeemarriage; Edegree[i] = DBOperate::Employeedegree; Edepart[i] = DBOperate::Employeedepart; Eposition[i] = DBOperate::Employeeposition; Eworktime[i] = DBOperate::Employeeworktime; Epay[i] = DBOperate::Employeepay; } myf.close();} void DBOperate::RefreshMaxNum(int iflag)//更新系统中员工计数文件的函数 { int MaxNum = 0; ifstream myif(“EmployeeMaxNum.txt”); myif>>MaxNum; myif.close(); MaxNum = MaxNum+iflag; ofstream myof(“EmployeeMaxNum.txt”); myof< myof.close();} int main()//主函数 { system(“color B0”);//设置当前窗口的背景色和前景色 // 0 = 黑色 = 灰色 // 1 = 蓝色 = 淡蓝色 // 2 = 绿色 A = 淡绿色 // 3 = 浅绿色 B = 淡浅绿色 // 4 = 红色 C = 淡红色 // 5 = 紫色 D = 淡紫色 // 6 = 黄色 E = 淡黄色 // 7 = 白色 F = 亮白色 int select = 0; while(select!=5) { cout<<“ ╭————————————————————————————╮”< cout<<“ ∣ 《主菜单》 ∣”< cout<<“ ├————————————————————————————┤”< cout<<“ ∣ 1.新建并录入职工信息 ∣”< cout<<“ ∣ 2.按条件输出职工信息 ∣”< cout<<“ ∣ 3.修改指定职工的信息 ∣”< cout<<“ ∣ 4.删除职工信息 ∣”< cout<<“ ∣ 5.退出系统 ∣”< cout<<“ ╰————————————————————————————╯”< cout<<“ ——————————————————————————————”< cout<<“ 请选择您需要功能的代号: ”; cin>>select; Employee e; DBOperate dbo; switch(select) { case 1: e.NewInfo();break; case 2: dbo.ReadOut(); e.ShowInfo();break; case 3: e.RefreshInfo();break; case 4: e.DeleteInfo();break; case 5: cout<<“ 退出成功”< default: cout<<“命令错误!”< } if(select == 5) break; } exit(1); return 0;} #include intnum; /*定义一个职工信息的结构体*/ char name[20]; /*定义一个职工信息的结构体*/ char sex[10]; //用字符串存放职工的性别数据 char birth[20];//用字符串存放职工的出生年月数据 char deta[20];//用字符串存放职工的工作年月数据 char education[20];//用字符串存放职工的学历数据 double salary; //用字符串存放职工的性别数据 char work[30];//用字符串存放职工的职务数据 char addr[20];//用字符串存放职工的地址数据 char tel[20];//用字符串存放职工的电话数据 }worker[100];//用结构体数组存放职工的所有信息 void menu(); void input(); void save(); void read(); void display(); void add(); void search(); voidsearch_education(); voidsearch_num(); void del(); void modify(); void main() { char s; system(“color 3f”); printf(“nn”); printf(“ t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓n”); printf(“ t┃**********************************************************┃n”); printf(“ t┃***┏━━━━━━━━━━━━━━━━━━━━━━━━┓***┃n”); printf(“ t┃***┃************************************************┃***┃n”); printf(“ t┃***┃*** ****┃***┃n”); printf(“ t┃***┃*** 欢迎使用职工信息管理系统 ****┃***┃n”); printf(“ t┃***┃*** ****┃***┃n”); printf(“ t┃***┃*** ****┃***┃n”); printf(“ t┃***┃*** 制作人吴青伶 ****┃***┃n”); printf(“ t┃***┃*** ****┃***┃n”); printf(“ t┃***┃*** 2013.12.28 ****┃***┃n”); printf(“ t┃***┃*** ****┃***┃n”); printf(“ t┃***┃************************************************┃***┃n”); printf(“ t┃***┗━━━━━━━━━━━━━━━━━━━━━━━━┛***┃n”); printf(“ t┃**********************************************************┃n”);printf(“ t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛n”);do { menu();printf(“Do you want to continue?(y/n)”); s=getchar();}while(s=='Y'||s=='y');} void menu()/*菜单函数*/ { int b;printf(“t n”);printf(“t n”);printf(“t n”);printf(“t n”);printf(“t n”);printf(“t 请选择 n”);printf(“t ------------------------------n”);printf(“t || || n”);printf(“t || 1.职工信息录入 || n”);printf(“t || 2.职工信息浏览 || n”);printf(“t || 3.职工信息添加 || n”);printf(“t || 4.职工信息查询 || n”);printf(“t || 5.职工信息删除 || n”);printf(“t || 6.职工信息修改 || n”);printf(“t || 0.退出 || n”);printf(“tn”);printf(“n 输入你的选择项(0~6):n”); scanf(“%d”,&b); switch(b) { case 1 : //职工信息录入、保存 input(); save(); getchar(); break; case 2 ://读入职工信息并显示 read(); display(); getchar();break; case 3 : //添加职工信息 add();getchar();break; case 4 : //查询职工信息 search();getchar();break; case 5 : //读入职工信息并实现职工信息删除功能 read(); del(); getchar(); break; case 6 : //读入职工信息并修改职工信息 read();modify();getchar();break; case 0 : exit(0);//退出 default:break;} } void input() //录入职工信息 { inti,flag,j;printf(“输入职工个数(默认个数为2):”);scanf(“%d”,&N);fflush(stdin);//清除缓存 for(i=0;i { loop: printf(“职工号:”);scanf(“%d”,&worker[i].num);fflush(stdin);flag=1;if(worker[N].num<0) printf(“请输入正整数:n”);else for(j=0;j { if(worker[i].num==worker[j].num) { flag=0; printf(“ 工号重复,请重新输入!n”); goto loop; } } printf(“姓名:”);scanf(“%s”,worker[i].name);fflush(stdin);printf(“性别:”);scanf(“ %s”,worker[i].sex);fflush(stdin);printf(“出生年月:”);scanf(“%d”,&worker[i].birth);fflush(stdin);printf(“工作年月:”);scanf(“%lf”,&worker[i].deta);fflush(stdin);printf(“请输入学历(中专=zz,大专=dz,本科=bk,研究生=yjs):n”);scanf(“%s”,worker[i].education);fflush(stdin);printf(“工资:”);scanf(“%lf”,worker[i].salary);fflush(stdin);printf(“职务:”);scanf(“%s”,worker[i].work);fflush(stdin);printf(“住址:”);scanf(“%s”,worker[i].addr);fflush(stdin);printf(“电话:”);scanf(“%s”,worker[i].tel);fflush(stdin); } printf(“n创建完毕!n”);} void save() //保存函数 { FILE *fp;int i; if((fp=fopen(“worker.txt”,“wb”))==NULL)//以只写方式打开一个二进制文件 { printf(“ncannot open filen”); exit(0);} for(i=0;i void read() //读入函数 { FILE *fp;int i=0; if((fp=fopen(“worker.txt”,“rb”))==NULL)//以只读方式为输出打开磁盘文件中的一个二进制文件 { printf(“ncannot open filen”); exit(0);} do{ fread(&worker[i],sizeof(struct worker),1,fp);//从worker.txt文件向内存读入数据(二进制) i++;}while(!feof(fp));fclose(fp); N=i-1;} void display() //信息浏览函数 { int i;for(i=0;i { printf(“职工号:%dn”,worker[i].num);printf(“姓名:%sn”,worker[i].name);printf(“性别:%sn”,worker[i].sex);printf(“出生年月:%dn”,worker[i].birth);printf(“工作年月:%dn”,worker[i].deta);printf(“学历:%sn”,worker[i].education);printf(“工资:%lfn”,worker[i].salary);printf(“职务:%dn”,worker[i].work);printf(“住址:%sn”,worker[i].addr);printf(“电话:%sn”,worker[i].tel); } } void add() //添加函数 { FILE *fp;int i;struct worker p;double t;printf(“n请输入新增加职工的信息:n”); printf(“请输入职工号:n”); scanf(“%d”,&p.num); for(i=0;i { while(worker[i].num==p.num) { printf(“ 工号重复,请重新输入!n”); scanf(“%d”,&p.num); } } printf(“请输入姓名:n”);scanf(“%s”,p.name);printf(“请输入性别:n”);scanf(“%s”,p.sex);printf(“请输入出生年月:n”);scanf(“%d”,&p.birth);printf(“请输入工作年月:n”);scanf(“%d”,&p.deta);printf(“请输入学历(中专=zz,大专=dz,本科=bk,=yjs:):n”);scanf(“%s”,p.education);printf(“请输入工资:n”);scanf(“%lf”,&t);p.salary=t;printf(“请输入职务:n”);scanf(“%s”,p.work);printf(“请输入住址:n”);scanf(“%s”,p.addr);printf(“请输入电话:n”);scanf(“%s”,p.tel);printf(“n添加完毕!n”); if((fp=fopen(“worker.txt”,“ab”))==NULL)//以追加方式打开一个二进制文件尾部 { printf(“ncannot open filen”);exit(0); } fwrite(&p,sizeof(struct worker),1,fp);fclose(fp);} void search() //查询函数 { int c;do { puts(“nsearch by=>n1.学历2.职工号3.取消并返回”);printf(“Which you needed?:n”);scanf(“%d”,&c); 研究生if(c>3||c<1) { puts(“nchoiceerror!please again!”);getchar();//此语句用于接受在执行上一句时最后输出的回车符 } } while(c>3||c<1); { switch(c) { case 1:search_education();break;case 2:search_num();break;case 3:menu();break; } } } void search_education() //按学历查询函数 { inti,flag=0;char s[10];printf(“n请输入你要查询的学历:n”);scanf(“%s”,s);for(i=0;i { if(strcmp(s,worker[i].education)==0) { printf(“职工号:%dn”,worker[i].num); printf(“姓名:%sn”,worker[i].name); printf(“性别:%sn”,worker[i].sex); printf(“出生年月:%dn”,worker[i].birth); printf(“工作年月:%dn”,worker[i].deta); printf(“学历(中专=zz,大专=dz,yjs):%sn”,worker[i].education);printf(“工资:%lfn”,worker[i].salary);printf(“职务:%lfn”,worker[i].work); printf(“住址:%sn”,worker[i].addr); printf(“电话:%sn”,worker[i].tel);flag++; } } if(flag==0) printf(“n对不起没有找到!n”);getchar();} void search_num() //按工号查询函数 { inti,s,flag=0;printf(“n输入要查询的职工号!:n”);scanf(“%d”,&s); 本科=bk,研究生=for(i=0;i { if(s==worker[i].num) { printf(“职工号:%dn”,worker[i].num); printf(“姓名:%sn”,worker[i].name); printf(“性别:%sn”,worker[i].sex); printf(“出生年月:%dn”,worker[i].birth); printf(“工作年月:%dn”,worker[i].deta); printf(“学历(中专=zz,大专=dz,本科=bk,研究生=yjs):%sn”,worker[i].education); printf(“工资:%lfn”,worker[i].salary);printf(“职务:%lfn”,worker[i].work); printf(“住址:%sn”,worker[i].addr); printf(“电话:%sn”,worker[i].tel); flag++; } } if(flag==0)printf(“n对不起没有找到!please”); getchar();} void del() //删除函数 { inti,j;FILE *fp;char name[20];char c;if((fp=fopen(“worker.txt”,“wb”))==NULL)//以只写方式打开一个二进制文件 { printf(“ncannot open filen”);exit(0); } printf(“请输入要删除的职工的姓名:”);scanf(“%s”,name);for(i=0;i if(strcmp(name,worker[i].name)==0)//判断输入的姓名和原来的姓名是否相同 { printf(“找到该职工,是否删除?(y/n)”); fflush(stdin); scanf(“%c”,&c); if(c =='Y'||c=='y') { for(j=i;j worker[j]=worker[j+1]; printf(“删除成功!n”); //break; } } } if(i>=N){ printf(“没有找到该职工!n ”); return;} else { N=N-1; for(i=0;i if(fwrite(&worker[i],sizeof(struct worker),1,fp)!=1) { printf(“ncannot save filen”);getchar(); } fclose(fp);} } void modify() //修改函数 { struct worker p;FILE *fp;inti,n;double t;printf(“n输入要修改的职工号:n”);scanf(“%d”,&n); for(i=0;i if(n==worker[i].num) { printf(“找到该职工的信息(任意键继续)!”); printf(“n请输入职工的信息!n”); printf(“请输入姓名:n”);scanf(“%s”,p.name); printf(“请输入性别:n”);scanf(“%s”,p.sex); printf(“请输入出身年月:n”);scanf(“%d”,&p.birth);printf(“请输入工作年月:n”);scanf(“%lf”,&p.deta); printf(“请输入学历(中专=zz,大专=dz,yjs):n”);scanf(“%s”,p.education);printf(“请输入工资:n”);scanf(“%lf”,&t); p.salary=t;printf(“请输入职务:n”);scanf(“%s”,p.work); printf(“请输入住址:n”);scanf(“%s”,p.addr); 本科=bk,研究生= } printf(“请输入电话:n”);scanf(“%s”,p.tel);p.num=n; if((fp=fopen(“worker.txt”,“r+”))==NULL)//以读写的方式将修改的信息写入磁盘文件 { printf(“ncannot open filen”); exit(0); } fseek(fp,i*sizeof(struct worker),0);//将位置指针移到i*sizeof(struct worker)个字节处 fwrite(&p,sizeof(struct worker),1,fp); fclose(fp); printf(“修改成功!n”); break;} } if(i>=N)printf(“n未找到该职工!n”); 教职工信息管理系统源码 #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<<“添加人员信息成功......”<第二篇:职工信息管理系统源代码
第三篇:C++课程设计 教职工信息管理系统源代码