|
|
@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
|
|
|
#include<string.h>
|
|
|
|
|
|
|
|
struct worker
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char name[30];
|
|
|
|
|
|
|
|
char id[10];
|
|
|
|
|
|
|
|
int salary1,salary2,salary3;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
int read(struct worker wo[]); //读取
|
|
|
|
|
|
|
|
int show(); //菜单
|
|
|
|
|
|
|
|
int baocun(struct worker wo[]); //保存
|
|
|
|
|
|
|
|
int add(); //添加
|
|
|
|
|
|
|
|
int see(); //查看
|
|
|
|
|
|
|
|
int search(); //搜索
|
|
|
|
|
|
|
|
int ghcz(); //按工号搜索
|
|
|
|
|
|
|
|
int xmcz(); //按姓名搜索
|
|
|
|
|
|
|
|
int del(); // 删除
|
|
|
|
|
|
|
|
int xmsc(); //按姓名删除
|
|
|
|
|
|
|
|
int ghsc(); //按工号删除
|
|
|
|
|
|
|
|
int salary(); //薪水统计
|
|
|
|
|
|
|
|
int modify(); //修改
|
|
|
|
|
|
|
|
int ghxg(); //按工号修改
|
|
|
|
|
|
|
|
int xmxg(); //按姓名修改
|
|
|
|
|
|
|
|
int back();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct worker wo[100]; //保存所有职工信息
|
|
|
|
|
|
|
|
int number=0; //记录总的职工人数
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int choose=0;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
|
|
|
printf("\t\t===>请选择");
|
|
|
|
|
|
|
|
scanf("%d",&choose);
|
|
|
|
|
|
|
|
system("cls"); //清屏
|
|
|
|
|
|
|
|
switch(choose)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 0: exit(0);back(); break; //退出
|
|
|
|
|
|
|
|
case 1: add();back(); break; //添加职工信息
|
|
|
|
|
|
|
|
case 2: see();back(); break; //查看职工信息
|
|
|
|
|
|
|
|
case 3: search();back(); break; //搜索职工信息
|
|
|
|
|
|
|
|
case 4: del();back(); break; //删除职工信息
|
|
|
|
|
|
|
|
case 5: salary();back(); break; //职工薪水
|
|
|
|
|
|
|
|
case 6: modify();back(); break; //修改职工信息
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fflush(stdin); //清空输入缓冲区
|
|
|
|
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int read(struct worker wo[])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp=NULL;
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
fp=fopen("C:worker.dat","rb");
|
|
|
|
|
|
|
|
while(fread(&wo[i],sizeof(struct worker),1,fp))
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int show()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("\t****************职工工资管理系统****************\n");
|
|
|
|
|
|
|
|
printf("\t################################################\n");
|
|
|
|
|
|
|
|
printf("\t^^^^^^^^^^^^^^^^[1] 添加职工信息^^^^^^^^^^^^^^^^\n");
|
|
|
|
|
|
|
|
printf("\t^^^^^^^^^^^^^^^^[2] 查看职工信息^^^^^^^^^^^^^^^^\n");
|
|
|
|
|
|
|
|
printf("\t^^^^^^^^^^^^^^^^[3] 查找职工信息^^^^^^^^^^^^^^^^\n");
|
|
|
|
|
|
|
|
printf("\t^^^^^^^^^^^^^^^^[4] 删除职工信息^^^^^^^^^^^^^^^^\n");
|
|
|
|
|
|
|
|
printf("\t^^^^^^^^^^^^^^^^[5] 统计职工工资^^^^^^^^^^^^^^^^\n");
|
|
|
|
|
|
|
|
printf("\t^^^^^^^^^^^^^^^^[6] 修改职工信息^^^^^^^^^^^^^^^^\n");
|
|
|
|
|
|
|
|
printf("\t^^^^^^^^^^^^^^^^[7] 退出 系统^^^^^^^^^^^^^^^^\n");
|
|
|
|
|
|
|
|
printf("\t################################################\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int baocun(struct worker *wo)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp=NULL;
|
|
|
|
|
|
|
|
fp=fopen("C:worker.dat","ab+");
|
|
|
|
|
|
|
|
fwrite(wo,sizeof(struct worker),1,fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int add() //添加职工信息
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int num=0,i=0;
|
|
|
|
|
|
|
|
struct worker temp;
|
|
|
|
|
|
|
|
printf("请输入要添加的职工个数:");
|
|
|
|
|
|
|
|
scanf("%d",&num);
|
|
|
|
|
|
|
|
for(i=0;i<num;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("输入第%d个职工信息\n",i+1);
|
|
|
|
|
|
|
|
printf("姓名:");
|
|
|
|
|
|
|
|
scanf("%s",temp.name);
|
|
|
|
|
|
|
|
printf("工号:");
|
|
|
|
|
|
|
|
scanf("%s",temp.id);
|
|
|
|
|
|
|
|
printf("基本工资:");
|
|
|
|
|
|
|
|
scanf("%d",&temp.salary1);
|
|
|
|
|
|
|
|
printf("职务工资:");
|
|
|
|
|
|
|
|
scanf("%d",&temp.salary2);
|
|
|
|
|
|
|
|
printf("工作补贴:");
|
|
|
|
|
|
|
|
scanf("%d",&temp.salary3);
|
|
|
|
|
|
|
|
wo[number++]=temp; //写入到数组
|
|
|
|
|
|
|
|
baocun(&temp); //写入到文件
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("添加成功\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int see() //查看职工信息
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
printf("以下是全部员工\n");
|
|
|
|
|
|
|
|
printf("\t姓名\t工号\t基本工资\t职务工资\t工作补贴\n");
|
|
|
|
|
|
|
|
while(i<number)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\t%s\t%s\t%d\t%d\t%d\n",wo[i].id,wo[i].name,wo[i].salary1,wo[i].salary2,wo[i].salary3);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int search() //查找职工信息
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
printf("1 按姓名查找\n");
|
|
|
|
|
|
|
|
printf("2 按工号查找\n");
|
|
|
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
|
|
|
switch(n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:xmcz(); break;
|
|
|
|
|
|
|
|
case 2:ghcz(); break;
|
|
|
|
|
|
|
|
default: printf("输入有误!\n"); break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int xmcz() //姓名查找
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char name[30];
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
printf("请输入要查找的职工姓名:");
|
|
|
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf("\t姓名\t工号\t基本工资\t职务工资\t工作补贴\n");
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(name,wo[i].name)==0)
|
|
|
|
|
|
|
|
printf("\t%s\t%s\t%d\t%d\t%d\n",wo[i].id,wo[i].name,wo[i].salary1,wo[i].salary2,wo[i].salary3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ghcz() //工号查找
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char id[10];
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
printf("请输入要查找的职工工号:");
|
|
|
|
|
|
|
|
scanf("%s",id);
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf("\t姓名\t工号\t基本工资\t职务工资\t工作补贴\n");
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(id,wo[i].id)==0)
|
|
|
|
|
|
|
|
printf("\t%s\t%s\t%d\t%d\t%d\n",wo[i].id,wo[i].name,wo[i].salary1,wo[i].salary2,wo[i].salary3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int del() //删除职工信息
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
printf("1 按姓名删除\n");
|
|
|
|
|
|
|
|
printf("2 按工号删除\n");
|
|
|
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
|
|
|
switch(n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:xmsc(); break;
|
|
|
|
|
|
|
|
case 2:ghsc(); break;
|
|
|
|
|
|
|
|
default: printf("输入有误!\n"); break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int xmsc() //按姓名删除
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp=NULL;
|
|
|
|
|
|
|
|
char name[30];
|
|
|
|
|
|
|
|
int i=0,j=0;
|
|
|
|
|
|
|
|
printf("请输入想要删除的职工的姓名:");
|
|
|
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(name,wo[i].name)==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(j=i;j<number-1;j++)
|
|
|
|
|
|
|
|
{wo[j]=wo[j+1];}number--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fp=fopen("C://woker.dat","wb"); //将剩余的数据写入文件 ,删除以前的数据
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fwrite(&wo[i],sizeof(struct worker),1,fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
printf("删除成功:\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ghsc() //按工号删除
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp=NULL;
|
|
|
|
|
|
|
|
char id[10];
|
|
|
|
|
|
|
|
int i=0,j=0;
|
|
|
|
|
|
|
|
printf("请输入想要删除的职工的工号:");
|
|
|
|
|
|
|
|
scanf("%s",id);
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(id,wo[i].id)==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(j=i;j<number-1;j++)
|
|
|
|
|
|
|
|
{wo[j]=wo[j+1];}number--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fp=fopen("C://woker.dat","wb"); //将剩余的数据写入文件 ,删除以前的数据
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fwrite(&wo[i],sizeof(struct worker),1,fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
printf("删除成功:\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int salary() //统计职工工资
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
double s=0.0;
|
|
|
|
|
|
|
|
double sum[100];
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sum[i]=wo[i].salary1+wo[i].salary2+wo[i].salary3;
|
|
|
|
|
|
|
|
printf("%s的总工资为:%f\n",wo[i].name,sum[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
s+=sum[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("平均工资为:%f\n",s/number);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int modify() //修改职工信息
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int m=0;
|
|
|
|
|
|
|
|
printf("请选择修改的方式:\n");
|
|
|
|
|
|
|
|
printf("1 按姓名修改\n");
|
|
|
|
|
|
|
|
printf("2 按工号修改\n");
|
|
|
|
|
|
|
|
scanf("%d",&m);
|
|
|
|
|
|
|
|
switch(m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:xmxg();break;
|
|
|
|
|
|
|
|
case 2:ghxg();break;
|
|
|
|
|
|
|
|
default:printf("输入有误!\n");break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int xmxg() //按照姓名修改
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp=NULL;
|
|
|
|
|
|
|
|
char name[30];
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
printf("请输入要修改的职工的姓名:");
|
|
|
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(name,wo[i].name));
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\t姓名\t工号\t基本工资\t职务工资\t工作补贴\n");
|
|
|
|
|
|
|
|
printf("\t%s\t%s\t%d\t%d\t%d\n",wo[i].id,wo[i].name,wo[i].salary1,wo[i].salary2,wo[i].salary3);
|
|
|
|
|
|
|
|
printf("请重新输入该职员的信息");
|
|
|
|
|
|
|
|
printf("姓名:");
|
|
|
|
|
|
|
|
scanf("%s",wo[i].name);
|
|
|
|
|
|
|
|
printf("工号:");
|
|
|
|
|
|
|
|
scanf("%s",wo[i].id);
|
|
|
|
|
|
|
|
printf("基本工资:");
|
|
|
|
|
|
|
|
scanf("%d",&wo[i].salary1);
|
|
|
|
|
|
|
|
printf("职工工资:");
|
|
|
|
|
|
|
|
scanf("%d",&wo[i].salary2);
|
|
|
|
|
|
|
|
printf("工作补贴:");
|
|
|
|
|
|
|
|
scanf("%d",&wo[i].salary3);
|
|
|
|
|
|
|
|
fp=fopen("C://worker.dat","wb");
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{fwrite(&wo[i],sizeof(struct worker),1,fp);}
|
|
|
|
|
|
|
|
fclose(fp);printf("====>修改成功!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ghxg() //按照工号修改
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp=NULL;
|
|
|
|
|
|
|
|
char id[10];
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
printf("请输入要修改的职工的工号:");
|
|
|
|
|
|
|
|
scanf("%s",id);
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(id,wo[i].id));
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\t姓名\t工号\t基本工资\t职务工资\t工作补贴\n");
|
|
|
|
|
|
|
|
printf("\t%s\t%s\t%d\t%d\t%d\n",wo[i].id,wo[i].name,wo[i].salary1,wo[i].salary2,wo[i].salary3);
|
|
|
|
|
|
|
|
printf("请重新输入该职员的信息");
|
|
|
|
|
|
|
|
printf("姓名:");
|
|
|
|
|
|
|
|
scanf("%s",wo[i].name);
|
|
|
|
|
|
|
|
printf("工号:");
|
|
|
|
|
|
|
|
scanf("%s",wo[i].id);
|
|
|
|
|
|
|
|
printf("基本工资:");
|
|
|
|
|
|
|
|
scanf("%d",&wo[i].salary1);
|
|
|
|
|
|
|
|
printf("职工工资:");
|
|
|
|
|
|
|
|
scanf("%d",&wo[i].salary2);
|
|
|
|
|
|
|
|
printf("工作补贴:");
|
|
|
|
|
|
|
|
scanf("%d",&wo[i].salary3);
|
|
|
|
|
|
|
|
fp=fopen("C://worker.dat","wb");
|
|
|
|
|
|
|
|
for(i=0;i<number;i++)
|
|
|
|
|
|
|
|
{fwrite(&wo[i],sizeof(struct worker),1,fp);}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
printf("====>修改成功!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int back()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\t按Enter键返回主菜单!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|