diff --git a/职工工资管理系统.c b/职工工资管理系统.c index e66cac1..5235b5a 100644 --- a/职工工资管理系统.c +++ b/职工工资管理系统.c @@ -8,7 +8,6 @@ void dele_num(); void modi_num(); void browse(); void count(); -void load(); void add(); void menu(); int n; //Ա @@ -16,12 +15,13 @@ struct emploee //ְ { char no[5]; char name[8]; - float wage1; //ԱĻ - float wage2; //Աְ - float funds; //ԱĹ - float ylbx; //ԱҽƱ - float jt; //ԱĽ - float wage3; //Աʵ + int wage1; //ԱĻ + int wage2; //Աְ + int funds; //ԱĹ + int ylbx; //ԱҽƱ + int jt; //ԱĽ + int wage3; //Աʵ + int wage4; //ǰ3֮ }emp[NUM],newemp; int main() { @@ -31,18 +31,17 @@ void menu()// { int n; do{ - printf("************* ְʹϵͳ **************\n"); + printf("**************** ְʹϵͳ ***********\n"); printf("* 1-----ְϢ------ *\n"); printf("* 2-----ѯְϢ------ *\n"); - printf("* 3-----ְIDɾ-- *\n"); - printf("* 4-----ְID޸-- *\n"); - printf("* 5-----ݹͳƲ-- *\n"); - printf("* 6-----ļϢ---- *\n"); - printf("* 7-----ȫְϢ-- *\n"); - printf("* 8-----ְϢ------ *\n"); - printf("* 9-----˳---------- *\n"); + printf("* 3-----ɾְϢ------ *\n"); + printf("* 4-----޸ְϢ------ *\n"); + printf("* 5-----ͳϢ------ *\n"); + printf("* 6-----ְϢ------ *\n"); + printf("* 7-----ְϢ------ *\n"); + printf("* 8-------˳-------- *\n"); printf("*********************************************\n"); - printf("ѡ1-9:"); + printf("ѡ1-8:"); scanf("%d",&n); switch(n) { @@ -51,25 +50,29 @@ switch(n) case 3:dele_num(); break; case 4:modi_num(); break; case 5:count(); break; - case 6:load(); break;//صϢ - case 7:browse(); break;//Ϣ - case 8:add(); break; - case 9:printf("*******ӭ´ʹã*******"); + case 6:browse(); break;//Ϣ + case 7:add(); break; + case 8:printf("*******ӭ´ʹã*******"); default:exit(0);//˳ϵͳ.exit(0)˳ } }while(n!=0); } -/*************************ʼĵط**********************/ +/***********************************************/ void enter() { FILE *fp; int n,i; + fp=fopen("emp.txt","ab+"); + if(fp==NULL) + { + if ((fp=fopen("emp.txt","wb"))==NULL) { printf("ܽempļ\n"); exit(1); } + } printf("ְ:"); scanf("%d",&n); for(i=0;i=num) { - printf("%dְ:\n",n+1); - printf("ID:"); - scanf("%s",emp[n].no); - printf(":"); - scanf("%s",&emp[n].name); - printf(":"); - scanf("%f",&emp[n].wage1); - printf("ְ:"); - scanf("%f",&emp[n].wage2); - printf(":"); - scanf("%f",&emp[n].jt); - printf("ҽƱ:"); - scanf("%f",&emp[n].ylbx); - printf(":"); - scanf("%f",&emp[n].funds); - printf("ܹ:"); - scanf("%f",&emp[n].wage3); + if(emp[n].wage4>=1000&&emp[i].wage4<2000) + { + a++; + } + if(emp[n].wage4>=2000&&emp[i].wage4<3000) + { + b++; + } + if(emp[n].wage4>=3000) + { + c++; } + } + printf("ǰ֮1000~2000Ԫռİٷ֮%d\n",a*100/n); + printf("ǰ֮2000~3000Ԫռİٷ֮%d\n",b*100/n); + printf("ǰ֮3000Ԫռİٷ֮%d\n",c*100/n); fclose(fp); } /********************ɾϢĵط*******************/ @@ -142,35 +141,33 @@ void dele_num() printf("ܴempļ\n"); exit(1); } - printf("ɾǰ:\n"); - printf("¼ ID ְ ҽƱ ʵ\n"); + printf("ID ְ ҽƱ ʵ\n"); for(n=0;fread(&emp[n],sizeof(struct emploee),1,fp);n++) { - printf("%dְ:\n",n+1); printf("ID:"); - scanf("%s",emp[i].no); + scanf("%-6s",emp[i].no); printf(":"); - scanf("%s",&emp[i].name); + scanf("%-6s",&emp[i].name); printf(":"); - scanf("%f",&emp[i].wage1); + scanf("%-8d",&emp[i].wage1); printf("ְ:"); - scanf("%f",&emp[i].wage2); + scanf("%-8d",&emp[i].wage2); printf(":"); - scanf("%f",&emp[i].jt); + scanf("%-8d",&emp[i].jt); printf("ҽƱ:"); - scanf("%f",&emp[i].ylbx); + scanf("%-8d",&emp[i].ylbx); printf(":"); - scanf("%f",&emp[i].funds); + scanf("%-8d",&emp[i].funds); printf("ܹ:"); - scanf("%f",&emp[i].wage3); + scanf("%-8d",&emp[i].wage3); }/*nΪempļм¼*/ - printf("Ҫɾְ:"); + printf("ҪɾID:"); scanf("%s",num); for(i=0;(strcmp(emp[i].no,num)!=0&&i=n) { printf("\tû%sְŵְ\n",num); - exit(2); + return; } fclose(fp); fp=fopen("emp.dat","w+"); @@ -187,23 +184,22 @@ void dele_num() fseek(fp,0,SEEK_SET); for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp);i++) { - printf("%dְ:\n",i+1); printf("ID:"); - scanf("%s",emp[i].no); + scanf("%-6s",emp[i].no); printf(":"); - scanf("%s",&emp[i].name); + scanf("%-6s",&emp[i].name); printf(":"); - scanf("%f",&emp[i].wage1); + scanf("%-8d",&emp[i].wage1); printf("ְ:"); - scanf("%f",&emp[i].wage2); + scanf("%-8d",&emp[i].wage2); printf(":"); - scanf("%f",&emp[i].jt); + scanf("%-8d",&emp[i].jt); printf("ҽƱ:"); - scanf("%f",&emp[i].ylbx); + scanf("%-8d",&emp[i].ylbx); printf(":"); - scanf("%f",&emp[i].funds); + scanf("%-8d",&emp[i].funds); printf("ܹ:"); - scanf("%f",&emp[i].wage3); + scanf("%-8d",&emp[i].wage3); } fclose(fp); } @@ -218,35 +214,34 @@ void modi_num() printf(" empļ\n"); exit(1); } - printf("Ҫ޸ĵְ:"); + printf("Ҫ޸ĵID:"); scanf("%s",num); for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp);i++) if(!strcmp(emp[i].no,num))break; if(feof(fp)) { printf("\tû%sְŵְ\n",num); - exit(2); + return; } - printf("¼ ְ ְ ҽƱ ʵ\n"); - printf("%6d %6s %9s %.1f %.1f %.1f %.1f %.1f %.1f\n",i+1,emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); - printf("ʽ:ְ ְ ҽƱ \n"); - printf("%d¼:",i+1); - scanf("%s%s%f%f%f%f%f",newemp.no,newemp.name,&newemp.wage1,&newemp.wage2,&newemp.jt,&newemp.ylbx,&newemp.funds);//ȡµְ¼ + printf("ID ְ ҽƱ ʵ\n"); + printf(" %-6s %-6s %-8d %-8d %-8d %-8d %-8d %-8d\n",emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); + printf("ID ְ ҽƱ \n"); + scanf("%s%s%d%d%d%d%d",newemp.no,newemp.name,&newemp.wage1,&newemp.wage2,&newemp.jt,&newemp.ylbx,&newemp.funds);//ȡµְ¼ newemp.wage3=newemp.wage1+newemp.wage2+newemp.jt-newemp.ylbx-newemp.funds; fseek(fp,-(long)sizeof(struct emploee),SEEK_CUR); //ļָָ޸ĵļ¼ͷ fwrite(&newemp,sizeof(struct emploee),1,fp); //newempǵǰ¼ printf(" ޸ĺ:\n"); fseek(fp,0,SEEK_SET); //ʾ޸ĺļ - printf("¼ ְ ְ ҽƱ ʵ\n"); + printf("ID ְ ҽƱ ʵ\n"); for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp)!=0;i++) - printf("%6d %6s %9s %.1f %.1f %.1f %.1f %.1f %.1f\n",i+1,emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); + printf(" %-6s %-6s %-8d %-8d %-8d %-8d %-8d %-8d\n",emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); fclose(fp); } /*************************ѯϢĵط***********************/ void search_num() { FILE *fp; - int i; + int i,n; char num[5]; if((fp=fopen("emp.txt","rb"))==NULL) { @@ -260,10 +255,18 @@ void search_num() if(feof(fp)) { printf("\t޴\n"); - exit(2); + return; } - printf("¼ ְ ְ ҽƱ ʵ\n"); - printf("%6d %6s %9s %.1f %.1f %.1f %.1f %.1f %.1f\n",i+1,emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); + printf("ְ ְ ҽƱ ʵ\n"); + printf(" %-6s %-6s %-8d %-8d %-8d %-8d %-8d %-8d\n",emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); + printf("밴1밴0\n"); + scanf("%d",&n); + switch(n) + { + case 1:search_num();break; + case 0:break; + default:break; + } fclose(fp); } /*******************Ϣĵط********************/ @@ -278,15 +281,15 @@ void browse() printf("¼ ְ ְ ҽƱ ʵ\n"); for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp)!=0;i++) { - printf("%6d %6s %9s %.1f %.1f %.1f %.1f %.1f %.1f\n",i+1,emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); + printf("%-6d %-6s %-6s %-8d %-8d %-8d %-8d %-8d %-8d\n",i+1,emp[i].no,emp[i].name,emp[i].wage1,emp[i].wage2,emp[i].jt,emp[i].ylbx,emp[i].funds,emp[i].wage3); } fclose(fp); } -/******************׷Ϣĵط*******************/ +/******************޸Ϣĵط*******************/ void add() { FILE *fp; - int n,i,j; + int n,i,t; if((fp=fopen("emp.txt","ab+"))==NULL) { printf("ܴempļ\n"); @@ -294,43 +297,34 @@ void add() } printf("Ҫ׷ӵְ:"); scanf("%d",&n); - for(i=0;i