|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 1
struct worker
{
int num;
char name[10];
int jbgz;
int zwgz;
int gwjt;
int ylbx;
int gjj;
float sum,avg;
};
int read(struct worker wor[]);
void write(struct worker wor[],int n);
int main()
{
void menu();
void input(struct worker wor[]);
void cx(struct worker wor[]);
void tongji(struct worker wor[]);
void update(struct worker wor[]);
void del(struct worker wor[]);
struct worker wor[N];
int xz=0;
while(xz!=6)
{
menu();
printf("请输入您的选择:");
scanf("%d",&xz);
switch(xz)
{
case 1:
input(wor);break;
case 2:
cx(wor);break;
case 3:
tongji(wor);break;
case 4:
update(wor);break;
case 5:
del(wor);break;
default:
return;
}
printf("按任意键返回主菜单!");
getchar();
getchar();
}
return 0;
}
void menu()
{
printf("--------职工工资管理系统--------\n");
printf("1.职工工资信息录入\n");
printf("2.职工工资信息查询\n");
printf("3.职工工资信息统计\n");
printf("4.职工工资信息修改\n");
printf("5.职工工资信息删除\n");
printf("6.退出\n");
printf("--------------------------------\n");
}
void input(struct worker wor[])
{
int i;
FILE *fp;
if((fp=fopen("d:\\职工工资信息.dat", "wb"))==NULL)
{
printf("无法打开此文件!\n");
exit(0);
}
for(i=0;i<N;i++)
{
printf("请输入%d个职工的工资:\n",i+1);
printf("工号:");
scanf("%d",&wor[i].num);
printf("姓名:");
scanf("%s",wor[i].name);
printf("基本工资:");
scanf("%d",&wor[i].jbgz);
printf("职务工资:");
scanf("%d",&wor[i].zwgz);
printf("岗位津贴:");
scanf("%d",&wor[i].gwjt);
printf("医疗保险:");
scanf("%d",&wor[i].ylbx);
printf("公积金:");
scanf("%d",&wor[i].gjj);
fwrite(&wor[i],sizeof(struct worker),1,fp);
}
fclose(fp);
}
void cx(struct worker wor[])//查询 分菜单查询
{
void output(struct worker wor[]);
void cxnum(struct worker wor[]);
void cxname(struct worker wor[]);
int cxxz;
printf("1:按工号查询 2:按姓名查询 3:查询全部 \n ");
printf("输入您的选择:");
scanf("%d",&cxxz);
if(cxxz==1)
cxnum(wor);
else if(cxxz==2)
cxname(wor);
else
output(wor);
}
void cxnum(struct worker wor[])
{
int i,num;
int n=read(wor);
printf("请输入你要查询的职工工号:");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(num==wor[i].num)
{
wor[i].sum=wor[i].jbgz+wor[i].gwjt+wor[i].gjj+wor[i].ylbx+wor[i].zwgz;
wor[i].avg=wor[i].sum/5;
printf("工号\t姓名\t基本工资\t职务工资\t岗位津贴\t医疗保险\t公积金\t总工资\t平均工资\t\n");
printf("%d\t%s\t%d\t%d\t%d\t%d\t%d\t%.2f\t%.2f\n",wor[i].num,wor[i].name,wor[i].jbgz,wor[i].zwgz,wor[i].gwjt,wor[i].ylbx,wor[i].gjj,wor[i].sum,wor[i].avg);
return;
}
}
printf("查无此人!\n");
}
void cxname(struct worker wor[])
{
int i;
char name[10];
int n=read(wor);
printf("请输入你要查询的职工姓名:");
scanf("%s",name);
for(i=0;i<n;i++)
{
wor[i].sum=wor[i].jbgz+wor[i].gwjt+wor[i].gjj+wor[i].ylbx+wor[i].zwgz;
wor[i].avg=wor[i].sum/5;
if(strcmp(wor[i].name,name)==0)
{
printf("工号\t姓名\t基本工资\t职务工资\t岗位津贴\t医疗保险\t公积金\t总工资\t平均工资\n");
printf("%d\t%s\t%d\t%d\t%d\t%d\t%d\t%.2f\t%.2f\n",wor[i].num,wor[i].name,wor[i].jbgz,wor[i].zwgz,wor[i].gwjt,wor[i].ylbx,wor[i].gjj,wor[i].sum,wor[i].avg);
return;
}
}
printf("查无此人!\n");
}
void output(struct worker wor[])
{
int i;
int n=read(wor);
printf("\t工号\t姓名\t基本工资\t职务工资\t岗位津贴\t医疗保险\t公积金\t总工资\t平均工资\n");
for(i=0;i<n;i++)
{
wor[i].sum=wor[i].jbgz+wor[i].gwjt+wor[i].gjj+wor[i].ylbx+wor[i].zwgz;
wor[i].avg=wor[i].sum/5;
printf("%d\t%s\t%d\t%d\t%d\t%d\t%d\t%.2f\t%.2f\n",wor[i].num,wor[i].name,wor[i].jbgz,wor[i].zwgz,wor[i].gwjt,wor[i].ylbx,wor[i].gjj,wor[i].sum,wor[i].avg);
}
}
void tongji(struct worker wor[])
{
FILE *fp;
if((fp=fopen("d:\\职工工资信息统计.dat", "wb"))==NULL)
{
printf("无法打开此文件!\n");
exit(0);
}
int i,sum1,t=0,t1=0,t2=0;
for(i=0;i<N;i++);
{
sum1=wor[i].jbgz+wor[i].zwgz+wor[i].gwjt;
if(sum1>3000)
t++;
else if(sum1>=2000&&sum1<=3000)
t1++;
else if(sum1>=1000&&sum1<2000)
t2++;
}
fprintf(fp,"工资前三项之和在3000元以上有%d人\n工资前三项之和在3000-2000元的有%d人\n工资前三项之和在2000-1000元的有%d人\n",t,t1,t2);
printf("工资前三项之和在3000元以上有%d人\n工资前三项之和在3000-2000元的有%d人\n工资前三项之和在2000-1000元的有%d人\n",t,t1,t2);
fclose(fp);
}
int read(struct worker wor[])
{
FILE *fp;
int i,t=0;
if((fp=fopen("d:\\职工工资信息.dat", "rb"))==NULL)
{
printf("无法打开此文件!\n");
exit(0);
}
for(i=0;i<N;i++)
t=t+fread(&wor[i],sizeof(struct worker),1,fp);
fclose(fp);
return t;
}
void write(struct worker wor[],int n)
{
FILE *fp;
int i;
if((fp=fopen("d:\\职工工资信息.txt","w"))==NULL)
{
printf("无法打开此文件!\n");
exit(0);
}
fprintf(fp,"\t工号\t姓名\t基本工资\t职务工资\t岗位津贴\t医疗保险\t公积金\t总工资\t平均工资\n");
for(i=0;i<n;i++)
{
fprintf(fp,"%d\t%s\t%d\t%d\t%d\t%d\t%d\t%.2f\t%.2f\n",wor[i].num,wor[i].name,wor[i].jbgz,wor[i].zwgz,wor[i].gwjt,wor[i].ylbx,wor[i].gjj,wor[i].sum,wor[i].avg);
}
fclose(fp);
}
void update(struct worker wor[])
{
int i,num,t=0;
FILE *fp;
int n=read(wor);
if((fp=fopen("d:\\职工工资信息.dat", "wb"))==NULL)
{
printf("无法打开此文件!\n");
exit(0);
}
printf("请输入你要修改的职工工号:");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(num==wor[i].num)
{
printf("请输入该职工新信息:\n");
scanf("%d%s%d%d%d%d%d",&wor[i].num,&wor[i].name,&wor[i].jbgz,&wor[i].zwgz,&wor[i].gwjt,&wor[i].ylbx,&wor[i].gjj);
wor[i].sum=wor[i].jbgz+wor[i].gwjt+wor[i].gjj+wor[i].ylbx+wor[i].zwgz;
wor[i].avg=wor[i].sum/5;
t=1;
printf("修改成功");
break;
}
}
for(i=0;i<n;i++)
fwrite(&wor[i],sizeof(struct worker),1,fp);
fclose(fp);
if(t==0)
printf("查无此人!\n");
}
void del(struct worker wor[])
{
int i,num,t=0;
FILE *fp;
int n=read(wor);
if((fp=fopen("d:\\职工工资信息.dat", "wb"))==NULL)
{
printf("无法打开此文件!\n");
exit(0);
}
printf("请输入你要删除的职工工号:");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(num!=wor[i].num)
{
wor[i].sum=wor[i].jbgz+wor[i].gwjt+wor[i].gjj+wor[i].ylbx+wor[i].zwgz;
wor[i].avg=wor[i].sum/5;
fwrite(&wor[i],sizeof(struct worker),1,fp);
}
else
{
t=1;
printf("删除成功!");
}
}
fclose(fp);
if(t==0)
printf("查无此人!\n");
}
|
|