#define N 200
#define PRINT1 printf("工号 姓名 性别 年龄 学历 工资 地址 电话 \n")
#define PRINT2 printf("%6d/t%8s/t%8s/t%4d/t%8s/t%4d/t%10s/t%6s/t",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].cult,em[i].salary,em[i].address,em[i].tel);
#include"string.h"
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
int sum;
void clearscreen()
{
getchar();
system("cls");
}
struct employee
{
int num; /*工号*/
char name[50]; /*姓名*/
char sex[3]; /*性别*/
int age; /*年龄*/
char cult[15]; /*学历*/
int salary; /*工资*/
char address[20]; /*地址*/
char tel[12]; /*电话*/
}em[N];
void manage();
void quary();
void paixu();
void input();
void output();
void change();
void add();
void del();
void insalary();
int incult();
int p_salary();
int p_age();
int p_name();
/*输入模块*/
void input()
{int i=0;
int n;
FILE *fp1;
char choice;
printf(" 警告:输入新的信息将删除已有所有信息!");
printf(" 确定输入新的信息? (y/n)");
choice=getch();
if(choice=='Y'||choice=='y')
{printf(" 确定输入新的信息!");
if ((fp1=fopen("e:\\employ.txt","wt"))==NULL)
{printf("can not open the file!\n");
getch();
return;
}
printf("\n\n请输入职工信息人数: n");
scanf("%d",&n);
do
{
clearscreen();
printf("第%d个职工\n",i+1);
printf("职工号\n");
scanf("%d",&em[i].num);
if(em[i].num ==0)
break;
printf("名字\n");
scanf("%s",em[i].name);
printf("性别\n");
scanf("%s",em[i].sex);
printf("年龄\n");
scanf("%d",&em[i].age);
printf("学历\n");
scanf("%s",em[i].cult);
printf("工资\n");
scanf("%d",&em[i].salary);
printf("地址\n");
scanf("%s",em[i].address);
printf("电话\n");
scanf("%s",em[i].tel);
i++;
}while(i<n+1);
printf("%d个职工信息输入完毕!\n",i);
sum=i;
for(i=0;i<sum;i++)
fprintf(fp1,"%d %s %s %d %s %d %s %s\n\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].cult,em[i].salary,em[i].address,em[i].tel);
fclose(fp1);
}else
printf(" 放弃输入新的信息!");
printf("按任意键返回!");
getch();
clearscreen();
}
/*修改模块*/
void change()
{int i,flag;
char changename[50];
int choicechange;
char choice;
FILE *fp1;
FILE *fp2;
if((fp1=fopen("e:\\employ.txt","rt"))==NULL)
{printf("can not open this file!");
getch();
return;
}
for(i=0;i<N;i++)
{fscanf(fp1,"%d%s%s%d%s%d%s%s\n",&em[i].num,em[i].name,em[i].sex,&em[i].age,em[i].cult,&em[i].salary,em[i].address,em[i].tel);
if(em[i].num==0)
break;
}
sum=i;
fclose(fp1);
do
{
printf("请输入要修改的人的姓名\n");
scanf("%s",changename);
clearscreen();
for(i=0;i<sum;i++)
{if(strcmp(em[i].name,changename)==0)
{PRINT1;
PRINT2;
printf("\n你要修改哪一项?");
printf("\n 1 职工名\n 2 学历\n 3 工资\n 4 地址\n 5 电话\n 6 年龄\n 7 性别\n 0 返回\n ");
scanf("%d",&choicechange);
switch(choicechange)
{
case 1:printf("新职工名");scanf("%s",em[i].name);break;
case 2:printf("新学历");scanf("%s",em[i].cult);break;
case 3:printf("新工资");scanf("%d",&em[i].salary);break;
case 4:printf("新地址");scanf("%s",em[i].address);break;
case 5:printf("新电话");scanf("%s",em[i].tel);break;
case 6:printf("新年龄");scanf("%d",&em[i].age);break;
case 7:printf("新性别");scanf("%s",em[i].sex);break;
case 0:printf("返回!");break;
}
PRINT1;
PRINT2;
break;
}
}
if(i==sum)
{
printf("该职工信息不存在");
}
printf("继续修改吗?");
choice=getch();
if(choice=='Y'||choice=='y')
{flag=1;
printf("\n继续!\n");
}
else flag=0;
}while(flag==1);
printf("按任意键返回");
getch();
clearscreen();
if((fp2=fopen("e:\\employ.txt","wt"))==NULL)
{printf("can not open this file!");
getch();
return;
}
for(i=0;i<sum;i++)
fprintf(fp2,"%d %s %s %d %s %d %s %s\n\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].cult,em[i].salary,em[i].address,em[i].tel);
fclose(fp2);
}
/*添加模块*/
void add()
{int i;
int n;
printf("\n\n添加一个新职工\n\n");
FILE *fp1;
FILE *fp2;
if((fp1=fopen("e:\\employ.txt","rt"))==NULL)
{printf("can not open this file!");
getch();
return;
}
for(i=0;i<N;i++)
{fscanf(fp1,"%d%s%s%d%s%d%s%s\n",&em[i].num,em[i].name,em[i].sex,&em[i].age,em[i].cult,&em[i].salary,em[i].address,em[i].tel);
if(em[i].num==0)
break;
}fclose (fp1);
sum=i;
printf("请输入要添加的人数: \n");
scanf("%d",&n);
for(i=sum;i<sum+n;i++)
{printf("\n输入第%d个职工的信息\n",i+1);
printf("\n新职工号\n");
scanf("%d",&em[i].num);
if(em[i].num==0)
break;
printf("\n新职工名字:\n");
scanf("%s",em[i].name);
printf("\n新职工性别:\n");
scanf("%s",em[i].sex);
printf("\n新职工年龄:\n");
scanf("%d",&em[i].age);
printf("\n新职工学历:\n");
scanf("%s",em[i].cult);
printf("\n新职工工资:\n");
scanf("%d",&em[i].salary);
printf("\n新职工地址:\n");
scanf("%s",em[i].address);
printf("\n新职工电话:\n");
scanf("%s",em[i].tel);
printf("第%d个职工信息输入完毕",i+1);
clearscreen();
}
sum=i;
if((fp2=fopen("e:\\employ.txt","wt"))==NULL)
{printf("can not open this file!");
getch();
return;
}
for(i=0;i<sum;i++)
fprintf(fp1,"%d %s %s %d %s %d %s %s\n\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].cult,em[i].salary,em[i].address,em[i].tel);
fclose(fp2);
}
/*查询模块*/
void insalary()
{
int i,k=0;
int inquire_salary;
FILE *fp;
if((fp=fopen("e:\\employ.txt","rt"))==NULL)
{printf("can not open this file!");
getch();
}
for(i=0;i<N;i++)
{fscanf(fp,"%d%s%s%d%s%d%s%s\n",&em[i].num,em[i].name,em[i].sex,&em[i].age,em[i].cult,&em[i].salary,em[i].address,em[i].tel);
if(em[i].num==0)
break;
}
fclose(fp);
sum=i;
clearscreen();
printf("\n输入要查询的工资\n");
scanf("%d",&inquire_salary);
for(i=0;i<sum;i++)
{
if(em[i].salary==inquire_salary)
{printf("\n职工信息\n");
PRINT1;
PRINT2;
k++;
}
}
if(k==0)
printf("无此人!");
getch();
return ;
}
int incult()
{int i,k=0;
char incult[15];
FILE *fp;
if((fp=fopen("e:\\employ.txt","r"))==NULL)
{printf("can not open this file!");
getch();
}
for(i=0;i<N;i++)
{fscanf(fp,"%d%s%s%d%s%d%s%s\n",&em[i].num,em[i].name,em[i].sex,&em[i].age,em[i].cult,&em[i].salary,em[i].address,em[i].tel);
if(em[i].num==0)
break;
}
fclose (fp);
sum=i;
clearscreen();
printf("\n输入要查询的学历\n");
scanf("%s",incult);
for(i=0;i<sum;i++)
{if(strcmp(em[i].cult,incult)==0)
{printf("\n职工信息\n");
PRINT1;
PRINT2;
k++;
}
}
if(k==0) printf("无此人!");
getch();
return 0;
}
int p_salary()
{struct employee *p, *q[N];
int i,j,k;
FILE *fp;
if((fp=fopen("e:\\employ.txt","rt+"))==NULL)
{printf("can not open this file!");
getch();
}
printf("num name sex age cult salary address tel\n");
for(i=0;i<N;i++)
{fscanf(fp,"%d%s%s%d%s%d%s%s\n",&em[i].num,em[i].name,em[i].sex,&em[i].age,em[i].cult,&em[i].salary,em[i].address,em[i].tel);
if(em[i].num==0)
break;
}fclose (fp);
sum=i;
clearscreen();
printf("\n工资排行\n");
printf("\n 排名 职工名 工资\n");
p=em;
for(i=0;i<sum;i++)
q[i]=p++;
for(i=0;i<sum;i++)
{k=i;
for(j=i+1;j<sum;j++)
if(q[k]->salary<q[j]->salary)
k=j;
if(k!=j)
{p=q[i];
q[i]=q[k];
q[k]=p;
}
}
for(i=0;i<sum;i++)
{printf("\n%8d %s %8d\n",i+1,q[i]->name,q[i]->salary);
}
fclose(fp);
return 0;
}
/*排序模块*/
int p_age()
{struct employee *p, *q[N];
int i,j,k;
FILE *fp;
if((fp=fopen("e:\\employ.txt","rt"))==NULL)
{printf("can not open this file!");
getch();
return 0;
}
printf("num name sex age cult salary address tel\n");
for(i=0;i<N;i++)
{fscanf(fp,"%d%s%s%d%s%d%s%s\n",&em[i].