#define AMOUNT 100
#include
#include
void putdata(int data); /*职工信息写入文件函数*/
void add_account(); /*对职工工作量累加*/
void watch(); /*浏览*/
void more_to_less(); /*排序*/
struct worker
{ int id;
char name[20];
int num;
char sex[5];
};
struct worker person[AMOUNT];
void more_to_less()
{
FILE *workload,*number;
int account=1,order=1,j,i,k,t,z;
char change[20];
workload=fopen("workload.txt","r");
number=fopen("number.txt","r");
fscanf(number,"%d",&i); /*确定人数*/
fclose(number);
for(j=1;j<=i;j++) /*读取职工信息*/
{
fscanf(workload,"%d%s%d%s",&person[j].id,person[j].name,&person[j].num,person[j].sex);
}
fclose(workload);
for(k=1;k<=i;k++)
{
z=k+1;
for(z;z<=i;z++)
{
if(person[k].num
t=person[k].num;
person[k].num=person[z].num;
person[z].num=t;
t=person[k].id;
person[k].id=person[z].id;
person[z].id=t;
strcpy(change,person[k].name);
strcpy(person[k].name,person[z].name);
strcpy(person[z].name,change);
strcpy(change,person[k].sex);
strcpy(person[k].sex,person[z].sex);
strcpy(person[z].sex,change);
}
}
printf("%d ",order);
printf("%d %s %d %s ",person[k].id,person[k].name,person[k].num,person[k].sex);
order++;
printf("\n");
} /*完成排序输出*/
workload=fopen("workload.txt","r");
for(j=1;j<=i;j++) /*读取职工信息*/
{
fscanf(workload,"%d%s%d%s",&person[j].id,person[j].name,&person[j].num,person[j].sex);
}
fclose(workload);
printf("同一名次的职工有:"); /*处理同一名次的职工*/
printf("\n");
for(k=1;k<=i;k++)
{
z=k+1;
for(z;z<=i;z++)
{
if(person[k].num==person[z].num)
{ t=1;
if(t==1)
printf("%d ",person[k].id);
account++;
printf("%d ",person[z].id);
printf("\n");
t++;
j=6;
}
}
if(j==6)
{
printf("这一名次的职工有%d人。",account);
printf("\n");
printf("\n");
printf("\n");
}
j=0;
account=1;
}
}
void watch() /*浏览*/
{
FILE *number;
FILE *workload;
int i,k;
number=fopen("number.txt","r");
fscanf(number,"%d",&i);
fclose(number);
workload=fopen("workload.txt","r+");
for(k=1;k<=i;k++) /*读取职工基本信息*/
{
fscanf(workload,"%d%s%d%s",&person[k].id,person[k].name,&person[k].num,person[k].sex);
}
fclose(workload);
for(k=1;k<=i;k++)
{
printf("%d ",person[k].id);
printf("%s ",person[k].name);
printf("%d ",person[k].num);
printf("%s \n",person[k].sex);
}
}
void putdata(int data) /*职工信息写入文件函数*/
{
FILE *workload;
workload=fopen("workload.txt","a");
fprintf(workload,"%d ",person[data].id);
fprintf(workload,"%s ",person[data].name);
fprintf(workload,"%d ",person[data].num);
fprintf(workload,"%s ",person[data].sex);
fputs("\n",workload);
fclose(workload);
}
void add_account() /*对职工工作量累加*/
{
int id,account,f,j;
char judge;
FILE *workload;
FILE *number2;
int k;
int p;
judge='y';
workload=fopen("workload.txt","r+");
number2=fopen("number.txt","r");
fscanf(number2,"%d",&p); /*确定人数*/
for(k=1;k<=p;k++) /*读取职工基本信息*/
{
fscanf(workload,"%d%s%d%s",&person[k].id,person[k].name,&person[k].num,person[k].sex);
}
fclose(workload);
while(judge=='y')
{
printf("请输入要操作的职工工号:");
scanf("%d",&id);
for(f=1;f<=p;f++)
{
if(id!=person[f].id)
;
else
{printf("请输入职工今日工作量:");
scanf("%d",&account);
person[f].num=person[f].num+account;
}
}
printf("是(y)否(n)继续输入职工工作量?");
scanf("%c",&judge);
scanf("%c",&judge);
workload=fopen("workload.txt","w");
for(j=1;j<=(p);j++)
{
fprintf(workload,"%d ",person[j].id);
fprintf(workload,"%s ",person[j].name);
fprintf(workload,"%d ",person[j].num);
fprintf(workload,"%s ",person[j].sex);
fputs("\n",workload);
}
fclose(workload); /*将累加后的职工工作量写入文件*/
}
fclose(number2);
}
void main()
{
FILE *number;
char judge,go;
int i,k=0;
printf("\n"); /*列表*/
printf(" **************************\n");
printf(" * 职工工作量管理系统 *\n");
printf(" **************************\n");
printf("\n");
printf("\n");
printf("是(y)否(n)输入新的职工");
scanf("%c",&judge);
if(judge=='n')
printf("读取原有职工……");
else
{
while(judge=='y')
{
number=fopen("number.txt","r+"); /*number.txt以存在,且以事先存有数据*/
fscanf(number,"%d",&i);
fclose(number);
printf("输入工号:");
scanf("%d",&person[i+1].id);
printf("输入姓名:");
scanf("%s",person[i+1].name);
printf("输入工作量:");
scanf("%d",&person[i+1].num);
printf("输入性别:");
scanf("%s",person[i+1].sex);
i++;
printf("是(y)否(n)继续输入新的职工?");
scanf("%c",&judge);
scanf("%c",&judge);
number=fopen("number.txt","r+");
fprintf(number,"%d",i); /*记录职工人数*/
fclose(number);
putdata(i);
}
}
number=fopen("number.txt","r");
fscanf(number,"%d",&i); /*读取职工人数*/
fclose(number);
/*职工信息写入文件函数*/
printf("\n"); /*列表*/
printf(" **************************\n");
printf(" *请输入选项编号(0~3) *\n");
printf(" **************************\n");
printf(" *1-浏览职工工作量 *\n");
printf(" *2-累加职工工作量 *\n");
printf(" *3-对工作量排序输出 *\n");
printf(" **************************\n");
scanf("%d",&k);
go='y';
while(go=='y')
{
switch(k)
{
case 1: watch();break;
case 2: add_account();break;
case 3: more_to_less();break;
default: printf("输入错误");
}
printf("是(y)否(n)继续操作?");
scanf("%c",&go);scanf("%c",&go);
if(go=='y')
{
printf("输入要执行的操作:");
scanf("%d",&k);
}
}
printf("按任意键退出程序!");
getch();
}
把分给楼上的吧,别个写了这么多,手都酸了。
这就要打包了,这里也不支持图片怎么给你效果图??
GOOGLE吧!