这个程序怎么样??
#include<stdio.h>
#include<string.h>
#define N
30
struct employee
{
int
num[4];
int age;
char name[10];
char sex[2];
char native[10];
char positive[10];
char work[10];
char birth[10];
float salary;
}em[N];
static int i=0;
int P;
FILE *fp;
int input();
int show();
int change();
int search();
int statistic();
int bbb();
int agesum();
int sexsum();
int nameway();
int numway();
int addway();
int delway();
int gzsum();
int load();
main()
//主函数
{
int k=1,n;
while(k)
{
printf("\t\t*****************职工档案管****************\n");
printf("\t\t--------------------------------------------\n");
printf("\t\t\t
| [1]----输入信息 |\n");
printf("\t\t\t
| [2]----输出信息 |\n");
printf("\t\t\t
| [3]----修改信息 |\n");
printf("\t\t\t
| [4]----查询信息 |\n");
printf("\t\t\t
| [5]----统计信息 |\n");
printf("\t\t\t
| [6]----退出程序 |\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请选择:");
scanf("%d",&n);
switch(n)
{
case 1:input();break;
case 2:show();break;
case 3:change();break;
case 4:search();break;
case 5:statistic();break;
case 6:break;
default:printf("输入错误!重新选择。\n");
}
if(n==6)break;
}
}
int input()
//录入信息
{
printf("录入的人数: ");
scanf("%d",&P);
if(P>N)
{
printf("您输入的人数过多,大于%d 人!\n",N);
return 1;
}
for(i=0;i<P;i++)
{
printf("第%d个职工编号:\t",i+1);
scanf("%d",&em[i].num);
printf("姓名:");
scanf("%s",em[i].name);
printf("性别:");
scanf("%s",em[i].sex);
printf("年龄:");
scanf("%d",&em[i].age);
printf("籍贯:");
scanf("%s",em[i].native);
printf("职称:");
scanf("%s",em[i].positive);
printf("职务:");
scanf("%s",&em[i].work);
printf("工资:");
scanf("%f",&em[i].salary);
printf("出生日期:");
scanf("%s",em[i].birth);
}
bbb();
system("pause");
return 1;
}
int show()
//显示信息
{
FILE *fp;
char abc;
if((fp=fopen("e:\\MMM.txt","r"))==NULL)
{
printf("\n没有找到数据文件!");
getch();
exit(1);
}
abc=fgetc(fp);
while(abc!=EOF)
//判断读出的字符是不是文件结束标志
{
putchar(abc);
abc=fgetc(fp);
}
fclose(fp);
return 1;
}
int change()
//修改信息
{
int n;
printf("\t1.添加成员\n");
printf("\t2.删除成员\n");
scanf("%d",&n);
if(n>0&&n<3)
{
switch(n)
{
case 1:addway();
break;
case 2:delway();
break;
}
printf("\n\n***操作完毕***");
}
else printf("\t\t\t\t输入有误!!!");
}
int addway()
//添加成员
{
int j=0;
FILE *fp;
printf("追加人数: ");
scanf("%d",&P);
fp=fopen("e:\\MMM.txt","a");
for(j=0;j<P;j++)
{
printf("编号\t姓名\t性别\t年龄\t籍贯\t职称\t职务\t工资\t出生日期\n");
scanf("%d%s%s%d%s%s%s%f%s",&em[j].num,em[j].name,
em[j].sex, &em[j].age,em[j].native,em[j].positive,
em[j].work, &em[j].salary,em[j].birth);
}
for(j=0;j<P;j++)
{
fprintf(fp,"\n%4d\t%-4s\t %-4s
%4d\t%-4s\t%-4s
%-4s
%0.01f \t%-4s\n",
em[j].num,em[j].name,em[j].sex,em[j].age,em[j].native,em[j].positive,em[j].work,em[j].salary,em[j].birth);
}
fclose(fp);
return 1;
}
int delway()
//删除成员
{
int a;
FILE *fp;
fp=fopen("e:\\MMM.txt","w+");
printf("编号\t姓名\t性别\t年龄\t籍贯\t职称\t职务\t工资\t出生日期\n");
for(i=0;i<P;i++)
{
printf("\n%4d\t%-4s\t %-4s
%4d
\t%-4s \t%-4s
%-4s
%0.01f \t%-4s\n",
em[i].num,em[i].name,em[i].sex,em[i].age,
em[i].native,em[i].positive,em[i].work,em[i].salary,
em[i].birth);
}
printf("输入要删除第几行:");
scanf("%d",&a);
for(i=a;i<P;i++)
{
em[a-1]=em[a];a++;
}
for(i=0;i<P-1;i++)
{
fprintf(fp,"\n%4d\t%-4s\t %-4s
%4d
\t%-4s \t%-4s
%-4s
%0.01f \t%-4s\n",
em[i].num,em[i].name,em[i].sex,em[i].age,
em[i].native,em[i].positive,
em[i].work,em[i].salary,em[i].birth);
}
fclose(fp);
}
int search()
//查询信息
{
int n;
printf("\t1.按姓名查询\n");
printf("\t2.按性别查询\n");
scanf("%d",&n);
if(n>0&&n<3)
{
switch(n)
{
case 1:nameway();
break;
case 2:sexway();
break;
}
printf("\n\n***操作完毕***");
}
else printf("\t\t\t\t输入有误!!!");
}
int nameway()
// 按姓名查询
{
char name[10];
int j;
printf("请输入要查询的员工的名字:");
scanf("%s",name);
for(j=0;j<i;j++)
{
if(strcmp(em[j].name,name)==0)
{printf(" 编号\t姓名\t性别\t年龄\t籍贯\t 职称\t职务\t工资\t出生日期\n");
printf("\n%4d\t%-4s\t %-4s
%4d
\t%-4s \t%-4s
%-4s
%0.01f \t%-4s\n",
em[j].num,em[j].name,em[j].sex,em[j].age,
em[j].native,em[j].positive,
em[j].work,em[j].salary,em[j].birth);
}
system ("pause");
return 1;
}
}
int sexway()
//按性别查询
{
char sex[2];
int j;
printf("请输入要查询的员工的性别:");
scanf("%s",sex);
for(j=0;j<i;j++)
{
if(strcmp(em[j].sex,sex)==0)
{
printf(" 编号\t姓名\t性别\t年龄\t籍贯\t职称\t职务\t工资\t出生日期\n");
printf("\n%4d\t%-4s\t %-4s
%4d
\t%-4s \t%-4s
%-4s
%0.01f \t%-4s\n",
em[j].num,em[j].name,em[j].sex,em[j].age,
em[j].native,em[j].positive,
em[j].work,em[j].salary,em[j].birth);
}
system ("pause");
return 1;
}
}
int statistic()
//统计信息
{
int n;
printf("\t\t\t\t*1.工资求和*\n");
printf("\t\t\t\t*2.男女职工人数*\n");
printf("\t\t\t\t*3.统计59岁职工人数*\n");
printf("\t\t\t\t*4.返回*\n");
scanf("%d",&n);
if(n>0&&n<5)
{
switch(n)
{
case 1:salarysum();
break;
case 2:sexsum();
break;
case 3:agesum();
break;
case 4:main();
break;
}
printf("\n\n***操作完毕***");
}
else printf("\t\t\t\t输入有误!!!");
}
int salarysum()
//工资求和
{
int m=0;
printf("\t\t\n");
for(i=0;i<P;i++)
m=m+em[i].salary;
printf("工资和为:%d\n",m);
return 1;
}
int sexsum()
//男女职工人数
{
int m=0,n=0;
char F[4]="女";
char M[4]="男";
printf("\t\t\n");
for(i=0;i<=P;i++)
{
if(strcmp(em[i].sex,F)==0)
m++;
if(strcmp(em[i].sex,M)==0)
n++;
}
printf("\t\t女职工总人数为:%d\n",m);
printf("\t\t男职工总人数为:%d\n",n);
printf("\t\t\n");
return 1;
}
int agesum()
//59岁职工人数
{
int g=0;
printf("\t\t\n");
for(i=0;i<P;i++)
{
if(em[i].age==59)
g++;
}
if(g==0)
printf("\t\t没有59岁\n");
else printf("\t\t59岁的职工有:%d人",g);
}
int bbb()
//保存函数
{
FILE *fp=fopen("e:\\MMM.txt","w");
int j;
fprintf(fp," 编号\t姓名\t性别\t年龄\t籍贯\t职称\t职务\t工资\t出生日期\n");
for(j=0;j<i;j++)
{
fprintf(fp,"\n%4d\t%-4s\t %-4s
%4d
\t%-4s \t%-4s
%-4s
%0.01f \t%-4s\n",
em[j].num,em[j].name,em[j].sex,
em[j].age,em[j].native,em[j].positive,
em[j].work,em[j].salary,em[j].birth);
}
fclose(fp);
return 1;
}