|
|
|
@ -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<m;i++)//将内存中职工的信息输出到磁盘文件中去
|
|
|
|
|
if(fwrite(&emp[i],sizeof(struct emploee),1,fp)!=1)//写入数据库
|
|
|
|
|
printf("文件读写错误!\n");
|
|
|
|
|
fclose(fp); //缓冲区内最后剩余 的数据输出到磁盘文件中,并释放文件指针和有关的缓冲区
|
|
|
|
|
}
|
|
|
|
|
/*************************输入**********************/
|
|
|
|
|
void enter()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int n,i;
|
|
|
|
|
int n,i,j;
|
|
|
|
|
fp=fopen("emp.txt","ab+");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
{
|
|
|
|
@ -75,7 +114,7 @@ void enter()
|
|
|
|
|
}
|
|
|
|
|
printf("输入职工人数:");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
for(i=0;i<n;i++) /* 循环获取n个职工记录 */
|
|
|
|
|
for(i=0;i<n;i++) /*循环获取n个职工记录*/
|
|
|
|
|
{
|
|
|
|
|
printf("第%d个职工:\n",i+1);
|
|
|
|
|
printf("ID:");
|
|
|
|
@ -103,8 +142,8 @@ void enter()
|
|
|
|
|
void count()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int n,i;
|
|
|
|
|
int a=0,b=0,c=0;
|
|
|
|
|
int n;
|
|
|
|
|
float a=0,b=0,c=0;
|
|
|
|
|
if((fp=fopen("emp.txt","rb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("不能打开emp文件\n");
|
|
|
|
@ -112,97 +151,69 @@ void count()
|
|
|
|
|
}
|
|
|
|
|
for(n=0;fread(&emp[n],sizeof(struct emploee),1,fp)!=0;n++)
|
|
|
|
|
{
|
|
|
|
|
if(emp[n].wage4>=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)
|
|
|
|
|
int m=load();
|
|
|
|
|
int i,j,n,t,button;
|
|
|
|
|
char name[20];
|
|
|
|
|
printf("原来的职工信息:\n");
|
|
|
|
|
browse();//显示删除前的职工信息
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("按姓名删除:\n");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
for(button=1,i=0;button&&i<m;i++)//主函数确定button==1时各函数 才可以被调用
|
|
|
|
|
{
|
|
|
|
|
printf("不能打开emp文件\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
printf("ID 姓名 基本工资 职务工资 津贴 医疗保险 公积金 实发工资\n");
|
|
|
|
|
for(n=0;fread(&emp[n],sizeof(struct emploee),1,fp);n++)
|
|
|
|
|
if(strcmp(emp[i].name,name)==0)//将文件中的员工姓名和输入的进行比较
|
|
|
|
|
{
|
|
|
|
|
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);i++)
|
|
|
|
|
if(i>=n)
|
|
|
|
|
printf("他的原始记录:\n");//显示他的信息
|
|
|
|
|
printf("ID 姓名 基本工资 职务工资 津贴 医疗保险 公积金 总工资\n");
|
|
|
|
|
printf("\n %-6s%-6s %-8d %-8d %-8d %-8d %-8d %-8d",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确定删除?确定按1,不删除按0\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
if(n==1)
|
|
|
|
|
{
|
|
|
|
|
printf("\t没有%s职工号的职工\n",num);
|
|
|
|
|
return;
|
|
|
|
|
for(j=i;j<m;j++)//从第i项起后面的每一项都替换前一项的值
|
|
|
|
|
{
|
|
|
|
|
emp[j]=emp[j+1];
|
|
|
|
|
}
|
|
|
|
|
button=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fp=fopen("emp.txt","wb+");
|
|
|
|
|
for(i<0;i<m-1;i++)
|
|
|
|
|
fwrite( &emp[i],sizeof(struct emploee),1,fp);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
fp=fopen("emp.dat","w+");
|
|
|
|
|
if(n==1) /*一个记录已经删除了*/
|
|
|
|
|
if(!button)//button=0表示删除成功
|
|
|
|
|
m=m-1;//总人数减少一个
|
|
|
|
|
else
|
|
|
|
|
printf("\n查无此人!\n");
|
|
|
|
|
printf("\n删除后的所有职工信息:\n");
|
|
|
|
|
save(m);//调用保存函数
|
|
|
|
|
browse();//调用浏览函数
|
|
|
|
|
printf("\n继续删除按1,不再删除按0\n");
|
|
|
|
|
scanf("%d",&t);
|
|
|
|
|
switch(t)
|
|
|
|
|
{
|
|
|
|
|
fclose(fp);
|
|
|
|
|
exit(3);
|
|
|
|
|
case 1:dele_num();break;
|
|
|
|
|
case 0:break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
for(j=0;j<i;j++)
|
|
|
|
|
fwrite(&emp[j],sizeof(struct emploee),1,fp);
|
|
|
|
|
for(j=i+1;j<n;j++)
|
|
|
|
|
fwrite(&emp[j],sizeof(struct emploee),1,fp);
|
|
|
|
|
printf("删除后:\n");
|
|
|
|
|
fseek(fp,0,SEEK_SET);
|
|
|
|
|
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp);i++)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
/********************修改信息的地方*******************/
|
|
|
|
|
void modi_num()
|
|
|
|
|
{
|
|
|
|
@ -223,7 +234,7 @@ void modi_num()
|
|
|
|
|
printf("\t没有%s职工号的职工\n",num);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
printf("ID 姓名 基本工资 职务工资 津贴 医疗保险 公积金 实发工资\n");
|
|
|
|
|
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);//获取新的职工记录
|
|
|
|
@ -232,7 +243,7 @@ void modi_num()
|
|
|
|
|
fwrite(&newemp,sizeof(struct emploee),1,fp); //用newemp覆盖当前记录
|
|
|
|
|
printf(" 修改后:\n");
|
|
|
|
|
fseek(fp,0,SEEK_SET); //显示修改后的文件数据
|
|
|
|
|
printf("ID 姓名 基本工资 职务工资 津贴 医疗保险 公积金 实发工资\n");
|
|
|
|
|
printf("ID 姓名 基本工资 职务工资 津贴 医疗保险 公积金 总工资\n");
|
|
|
|
|
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp)!=0;i++)
|
|
|
|
|
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);
|
|
|
|
@ -257,7 +268,7 @@ void search_num()
|
|
|
|
|
printf("\t查无此人\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
printf("职工号 姓名 基本工资 职务工资 津贴 医疗保险 公积金 实发工资\n");
|
|
|
|
|
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("继续请按1,不继续请按0\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
@ -271,21 +282,22 @@ void search_num()
|
|
|
|
|
}
|
|
|
|
|
/*******************浏览信息的地方********************/
|
|
|
|
|
void browse()
|
|
|
|
|
{ int i;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("emp.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("不能打开emp文件\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
printf("记录号 职工号 姓名 基本工资 职务工资 津贴 医疗保险 公积金 实发工资\n");
|
|
|
|
|
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp)!=0;i++)
|
|
|
|
|
{ int i,sum=0;
|
|
|
|
|
int m=load();
|
|
|
|
|
float pjwage1=0,pjwage2=0,pjylbx=0;
|
|
|
|
|
int pjjt=0,pjfunds=0;
|
|
|
|
|
printf("ID 姓名 基本工资 职务工资 津贴 医疗保险 公积金 总工资\n");
|
|
|
|
|
for(i=0;i<m;i++)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
sum=emp[i].wage1+emp[i].wage2+emp[i].jt;//计算员工工资总和
|
|
|
|
|
printf("前3项工资之和 %d\n",sum);
|
|
|
|
|
pjwage1+=emp[i].wage1;pjwage2+=emp[i].wage2;pjjt+=emp[i].jt;pjylbx+=emp[i].ylbx;pjfunds+=emp[i].funds;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("各项的平均工资: %.1f %.1f %d %.1f %d\n",pjwage1/m,pjwage2/m,pjjt/m,pjylbx/m,pjfunds/m);
|
|
|
|
|
}
|
|
|
|
|
/******************修改信息的地方*******************/
|
|
|
|
|
/******************增加信息*******************/
|
|
|
|
|
void add()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|