C++職工工資管理源代碼.doc
附錄源程序#include <stdio.h>#include <stdlib.h>#include <string.h>struct workerchar name30;char ID10;int salary1,salary2,salary3;int dq(struct worker wo);void show();void bc(struct worker wo);void add(); void see();void search();void ghcz();void xmcz();void del();void xmsc();void ghsc();void statistics();void modify();void ghxg(); void xmxg();void reserve();void back();void author();struct worker wo100; /保存所有的職工信息int Number=0; /記錄總的職工人數(shù)void main()int choose=0;while(true) show();printf("tt=>請(qǐng)選擇:");scanf("%d",&choose);system("cls");switch(choose)case 0: exit(0);/退出break; case 1: add();back();/添加職工信息break; case 2: see();back();/查看職工信息break; case 3: search();back();/ 查找職工信息 break;case 4: del(); back();/刪除職工信息break;case 5: statistics();back();/統(tǒng)計(jì)職工工資break;case 6: modify();back();/修改職工信息break; case 7:reserve();back();/保存數(shù)據(jù) break;case 8:author();back();/作者信息break;default:break;fflush(stdin);getchar();system("cls");int dq(struct worker wo)FILE *fp=NULL;int i=0;fp=fopen("C:/worker.dat","rb");while(fread(&woi,sizeof(struct worker),1,fp)i+;fclose(fp);return i;void show() printf("n");printf("t*職工工資管理系統(tǒng)*nn");printf("t*nn");printf("t1 添加職工信息n");printf("t2 查看職工信息n");printf("t3 查找職工信息n");printf("t4 刪除職工信息n");printf("t5 統(tǒng)計(jì)職工工資n");printf("t6 修改職工信息n");printf("t7 保 存 數(shù) 據(jù)n");printf("t8 作 者 信 息n");printf("t0 退 出 系 統(tǒng)nn");printf("t*n");void bc(struct worker *wo)FILE *fp=NULL;fp=fopen("C:/worker.dat","ab+");fwrite(wo,sizeof(struct worker),1,fp);fclose(fp);/添加職工信息void add() int numberTemp=0;int i=0;struct worker temp; printf("請(qǐng)輸入要添加職工個(gè)數(shù):");scanf("%d",&numberTemp);for(i=0;i<numberTemp;i+)printf("輸入第%d個(gè)職工信息n",i+1);printf("姓名:");scanf("%s",temp.name);printf("工號(hào):");scanf("%s",temp.ID);printf("基本工資:");scanf("%d",&temp.salary1);printf("職務(wù)工資:");scanf("%d",&temp.salary2);printf("津貼:");scanf("%d",&temp.salary3);woNumber+=temp; /寫入到數(shù)組bc(&temp); /寫入到文件printf("添加成功n");/查看職工信息void see() int i=0;printf("以下是全部職工n");printf("t姓名t工號(hào)t基本工資t職務(wù)工資t津貼n");while(i<Number)printf("t%st%st%dtt%dtt%dn",woi.name,woi.ID,woi.salary1,woi.salary2,woi.salary3);i+;/查找職工信息void search() int n=0;printf("1 按姓名查找n");printf("2 按工號(hào)查找n"); scanf("%d",&n);switch(n)case 1: xmcz();break;case 2: ghcz();break;default: printf("輸入錯(cuò)誤!n");break; void xmcz()/按姓名查找 char name30;int i=0;printf("請(qǐng)輸入要查找職工姓名:");scanf("%s",name);system("cls");printf("t姓名t工號(hào)t基本工資t職務(wù)工資t津貼n");for (i=0;i<Number;i+)if (strcmp(name,woi.name)=0)printf("t%st%st%dtt%dtt%dn",woi.name,woi.ID,woi.salary1,woi.salary2,woi.salary3);void ghcz()/按工號(hào)查找 char id10;int i=0;printf("請(qǐng)輸入要查找職工工號(hào):");scanf("%s",id);system("cls");printf("t姓名t工號(hào)t基本工資t職務(wù)工資t津貼n");for (i=0;i<Number;i+)if (strcmp(id,woi.ID)=0)printf("t%st%st%dtt%dtt%dn",woi.name,woi.ID,woi.salary1,woi.salary2,woi.salary3);/刪除職工信息void del() int n=0;printf("1 按姓名刪除n");printf("2 按工號(hào)刪除n");scanf("%d",&n);switch(n)case 1: xmsc();break;case 2: ghsc();break;void xmsc()/按姓名刪除 FILE *fp=NULL;char name30;int i=0;int j=0;printf("請(qǐng)輸入要?jiǎng)h除的職工姓名:");scanf("%s",name);for(i=0;i<Number;i+)if (strcmp(name,woi.name)=0)for (j=i;j<Number-1;j+)woj=woj+1;Number-;/將剩余數(shù)據(jù)寫入文件 擦除以前的數(shù)據(jù)fp=fopen("C:/worker.dat","wb");for (i=0;i<Number;i+)fwrite(&woi,sizeof(struct worker),1,fp);fclose(fp);printf("刪除成功;n");void ghsc()/按工號(hào)刪除 FILE *fp=NULL;char id60;int i=0;int j=0;printf("請(qǐng)輸入要?jiǎng)h除的職工工號(hào):");scanf("%s",id);for(i=0;i<Number;i+)if (strcmp(id,woi.ID)=0) for (j=i;j<Number-1;j+)woj=woj+1;Number-;/將剩余數(shù)據(jù)寫入文件 擦除以前的數(shù)據(jù)fp=fopen("C:/worker.dat","wb");for (i=0;i<Number;i+)fwrite(&woi,sizeof(struct worker),1,fp);fclose(fp);printf("刪除成功;n");/統(tǒng)計(jì)職工工資void statistics() int i=0;double s=0.0;double sum100;for(i=0;i<Number;i+)sumi=woi.salary1+woi.salary2+woi.salary3;printf("%s的總工資為:%fn",woi.name,sumi);for(i=0;i<Number;i+)s+=sumi;printf("平均工資為:%fn",s/Number); /修改職工信息void modify() int mode=0;printf("請(qǐng)選擇修改查找方式n");printf("1 按姓名查找修改n"); printf("2 按工號(hào)查找修改n"); scanf("%d",&mode);switch(mode)case 1: xmxg();break;case 2: ghxg();break;default: printf("輸入錯(cuò)誤!n");break; void xmxg()/按姓名修改 FILE *fp=NULL;char name30;int i=0;printf("請(qǐng)輸入要修改的職工姓名:");scanf("%s",name);for (i=0;i<Number;i+)if (strcmp(name,woi.name);elsebreak;printf("t姓名t工號(hào)t基本工資t職務(wù)工資t津貼n");printf("t%st%st%dtt%dtt%dn",woi.name,woi.ID,woi.salary1,woi.salary2,woi.salary3);printf("請(qǐng)重新輸入該職工信息");printf("姓名:");scanf("%s",woi.name);printf("工號(hào):");scanf("%s",woi.ID);printf("基本工資:");scanf("%d",&woi.salary1);printf("職務(wù)工資:");scanf("%d",&woi.salary2);printf("津貼:");scanf("%d",&woi.salary3);/信息修改后重新更新文件里面的數(shù)據(jù) 以保持?jǐn)?shù)據(jù)一致性fp=fopen("C:/worker.dat","wb");for (i=0;i<Number;i+)fwrite(&woi,sizeof(struct worker),1,fp);fclose(fp);void ghxg()/按工號(hào)修改 FILE *fp=NULL;char id30;int i=0;printf("請(qǐng)輸入要修改的職工工號(hào):");scanf("%s",id);for (i=0;i<Number;i+)if (strcmp(id,woi.ID);elsebreak;printf("t姓名t工號(hào)t基本工資t職務(wù)工資t津貼n");printf("t%st%st%dtt%dtt%dn",woi.name,woi.ID,woi.salary1,woi.salary2,woi.salary3);printf("請(qǐng)重新輸入該職工信息");printf("姓名:");printf("姓名:");scanf("%s",woi.name);printf("工號(hào):");scanf("%s",woi.ID);printf("基本工資:");scanf("%d",&woi.salary1);printf("職務(wù)工資:");scanf("%d",&woi.salary2);printf("津貼:");scanf("%d",&woi.salary3);/信息修改后重新更新文件里面的數(shù)據(jù) 以保持?jǐn)?shù)據(jù)一致性fp=fopen("C:/worker.dat","wb");for (i=0;i<Number;i+)fwrite(&woi,sizeof(struct worker),1,fp);fclose(fp);printf("t=>修改成功n");/保存數(shù)據(jù)void reserve()printf("t=程序在運(yùn)行時(shí)已自動(dòng)保存.n");void back()printf("t=>按Enter鍵返回主菜單n");/作者信息void author()printf("t*nn");printf("t學(xué)校名稱nn");printf("t學(xué)院班級(jí)nn");printf("tXXX制作nn");printf("t*nn");