diff --git a/emp.txt b/emp.txt new file mode 100644 index 0000000..da6fb6c Binary files /dev/null and b/emp.txt differ diff --git a/职工工资管理系统.c b/职工工资管理系统.c index 5235b5a..7ee9e3d 100644 --- a/职工工资管理系统.c +++ b/职工工资管理系统.c @@ -21,7 +21,7 @@ struct emploee //ְ int ylbx; //ԱҽƱ int jt; //ԱĽ int wage3; //Աʵ - int wage4; //ǰ3֮ + int wage4; //ǰ3ʺ }emp[NUM],newemp; int main() { @@ -43,6 +43,11 @@ do{ printf("*********************************************\n"); printf("ѡ1-8:"); scanf("%d",&n); +if(n<1||n>8) +{ + printf(":\n"); + return menu(); +} switch(n) { case 1:enter(); break; @@ -50,18 +55,52 @@ switch(n) case 3:dele_num(); break; case 4:modi_num(); break; case 5:count(); break; - case 6:browse(); break;//Ϣ + case 6:browse(); break; case 7:add(); break; case 8:printf("*******ӭ´ʹã*******"); default:exit(0);//˳ϵͳ.exit(0)˳ } }while(n!=0); } + int load()/*뺯int*/ + { + FILE *fp; + int i=0; + if((fp=fopen("emp.txt","rb"))==NULL) + { + printf("ܴļ\n"); + exit(0); + } + else + { + do + { + fread(&emp[i],sizeof(struct emploee),1,fp); + i++; + }while(feof(fp)==0);//ϵļ + } + fclose(fp); + return(i-1);// + } + void save(int m)//ļĺ + { + int i; + FILE *fp;//fpָ룬ָFILE͵Ķ + if((fp=fopen("emp.txt","wb"))==NULL)//ְбļΪ + { + printf("\n"); + exit(0); + } + for(i=0;i=1000&&emp[i].wage4<2000) - { - a++; - } - if(emp[n].wage4>=2000&&emp[i].wage4<3000) - { + { + if(emp[n].wage4>=2000&&emp[n].wage4<3000) b++; - } - if(emp[n].wage4>=3000) - { + else if(emp[n].wage4>0&&emp[n].wage4<=2000) c++; } - } - printf("ǰ֮1000~2000Ԫռİٷ֮%d\n",a*100/n); - printf("ǰ֮2000~3000Ԫռİٷ֮%d\n",b*100/n); - printf("ǰ֮3000Ԫռİٷ֮%d\n",c*100/n); + a=n-b-c; + printf("ǰ֮1000~2000Ԫռİٷ֮%.1f\n",c*100/n); + printf("ǰ֮2000~3000Ԫռİٷ֮%.1f\n",b*100/n); + printf("ǰ֮3000Ԫռİٷ֮%.1f\n",a*100/n); fclose(fp); } /********************ɾϢĵط*******************/ void dele_num() { - FILE *fp; - int i,j,n; - char num[5]; - if((fp=fopen("emp.txt","rb"))==NULL) - { - printf("ܴempļ\n"); - exit(1); - } - printf("ID ְ ҽƱ ʵ\n"); - for(n=0;fread(&emp[n],sizeof(struct emploee),1,fp);n++) - { - printf("ID:"); - scanf("%-6s",emp[i].no); - printf(":"); - scanf("%-6s",&emp[i].name); - printf(":"); - scanf("%-8d",&emp[i].wage1); - printf("ְ:"); - scanf("%-8d",&emp[i].wage2); - printf(":"); - scanf("%-8d",&emp[i].jt); - printf("ҽƱ:"); - scanf("%-8d",&emp[i].ylbx); - printf(":"); - scanf("%-8d",&emp[i].funds); - printf("ܹ:"); - scanf("%-8d",&emp[i].wage3); - }/*nΪempļм¼*/ - printf("ҪɾID:"); - scanf("%s",num); - for(i=0;(strcmp(emp[i].no,num)!=0&&i=n) - { - printf("\tû%sְŵְ\n",num); - return; - } - fclose(fp); - fp=fopen("emp.dat","w+"); - if(n==1) /*һ¼Ѿɾ*/ - { - fclose(fp); - exit(3); - } - for(j=0;j