|
|
|
@ -0,0 +1,195 @@
|
|
|
|
|
#include"stdio.h"
|
|
|
|
|
#include"string.h"
|
|
|
|
|
#include"windows.h"
|
|
|
|
|
struct Staff
|
|
|
|
|
{
|
|
|
|
|
char gh[50];
|
|
|
|
|
char name[50];
|
|
|
|
|
int workload;
|
|
|
|
|
bool operator< (const Staff& a)const{
|
|
|
|
|
return workload<a.workload;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; void menu();
|
|
|
|
|
void staff_add();
|
|
|
|
|
void display();
|
|
|
|
|
void order();
|
|
|
|
|
void qh();
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int n,f;
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
do{
|
|
|
|
|
menu();
|
|
|
|
|
printf("请输入你需要操作的序号(1—5):\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
if(n>=1&&n<=5)
|
|
|
|
|
{
|
|
|
|
|
f=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
f=0;
|
|
|
|
|
printf("您输入有误,请重新选择!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while(f==0);
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1:printf(" 职工基本信息\n");
|
|
|
|
|
printf("\n");system("cls");
|
|
|
|
|
staff_add();
|
|
|
|
|
break;
|
|
|
|
|
case 2:printf(" 浏览职工信息\n");
|
|
|
|
|
printf("\n");system("cls");
|
|
|
|
|
display();
|
|
|
|
|
break;
|
|
|
|
|
case 3:printf(" 按工作量排序\n");
|
|
|
|
|
printf("\n");
|
|
|
|
|
system("cls");
|
|
|
|
|
order();
|
|
|
|
|
break;
|
|
|
|
|
case 4:printf(" 工作量求和 \n");
|
|
|
|
|
printf("\n");
|
|
|
|
|
system("cls");
|
|
|
|
|
qh();
|
|
|
|
|
break;
|
|
|
|
|
case 5:goto loop;
|
|
|
|
|
default :break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loop:
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("\n\n\n\n\n\n----------谢谢使用!---------\n\n\n\n\n\n");
|
|
|
|
|
}
|
|
|
|
|
void menu()
|
|
|
|
|
{
|
|
|
|
|
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
|
|
|
|
|
printf("+ 职工工作量统计系统 +\n");
|
|
|
|
|
printf("+ +\n");
|
|
|
|
|
printf("+ 1. 职工基本信息输入 +\n");
|
|
|
|
|
printf("+ +\n");
|
|
|
|
|
printf("+ 2. 浏览所有职工信息 +\n");
|
|
|
|
|
printf("+ +\n");
|
|
|
|
|
printf("+ 3. 按工作量排序 +\n");
|
|
|
|
|
printf("+ +\n");
|
|
|
|
|
printf("+ 4. 工作量求和 +\n");
|
|
|
|
|
printf("+ +\n");
|
|
|
|
|
printf("+ 5. 结束程序 +\n");
|
|
|
|
|
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
|
|
|
|
|
}
|
|
|
|
|
void staff_add()
|
|
|
|
|
{Staff Sta;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int flag=1;
|
|
|
|
|
fp=fopen("staff.txt","a+");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
{printf("打开文件失败");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while(flag==1)
|
|
|
|
|
{
|
|
|
|
|
printf("请输入职工工号:");
|
|
|
|
|
scanf("%s",Sta.gh);
|
|
|
|
|
printf("请输入职工姓名:");
|
|
|
|
|
scanf("%s",Sta.name);
|
|
|
|
|
printf("请输入工作量:");
|
|
|
|
|
scanf("%d",&Sta.workload);
|
|
|
|
|
fprintf(fp,"\n");
|
|
|
|
|
fprintf(fp,"%s %s %d",Sta.gh,Sta.name,Sta.workload);
|
|
|
|
|
printf("添加成功!\n");
|
|
|
|
|
printf(" 按1继续添加信息,按0返回主菜单:");
|
|
|
|
|
scanf("%d",&flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void display()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char ch;
|
|
|
|
|
fp=fopen("staff.txt","r");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
printf("can not open!\n");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%c",&ch);
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
putchar(ch);
|
|
|
|
|
fscanf(fp,"%c",&ch);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
void order()
|
|
|
|
|
{
|
|
|
|
|
FILE*fp;
|
|
|
|
|
int a=0,i,j,q,p;
|
|
|
|
|
Staff workload1[50];
|
|
|
|
|
char t[50];
|
|
|
|
|
char u[50];
|
|
|
|
|
fp=fopen("staff.txt","a+");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
printf("can not open!\n");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s %s %d",workload1[a].gh,workload1[a].name,&workload1[a].workload);
|
|
|
|
|
a++;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<a;i++)
|
|
|
|
|
{
|
|
|
|
|
for(j=i+1;j<a;j++)
|
|
|
|
|
{
|
|
|
|
|
if(workload1[i]<workload1[j])
|
|
|
|
|
{
|
|
|
|
|
p=workload1[i].workload;
|
|
|
|
|
workload1[i].workload=workload1[j].workload;
|
|
|
|
|
workload1[j].workload=p;
|
|
|
|
|
strcpy(t,workload1[i].name);
|
|
|
|
|
strcpy(workload1[i].name,workload1[j].name);
|
|
|
|
|
strcpy(workload1[j].name,t);
|
|
|
|
|
strcpy(u,workload1[i].gh);
|
|
|
|
|
strcpy(workload1[i].gh,workload1[j].gh);
|
|
|
|
|
strcpy(workload1[j].gh,u);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(q=0;q<a;q++)
|
|
|
|
|
{
|
|
|
|
|
printf("%s %s %d\n",workload1[q].gh,workload1[q].name,workload1[q].workload);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void qh()
|
|
|
|
|
{
|
|
|
|
|
FILE*fp;
|
|
|
|
|
Staff workload1[50];
|
|
|
|
|
int a=0,i,sum=0;
|
|
|
|
|
fp=fopen("staff.txt","a+");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
printf("can not open!\n");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s%s%d",workload1[a].gh,workload1[a].name,&workload1[a].workload);
|
|
|
|
|
a++;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<a;i++)
|
|
|
|
|
{
|
|
|
|
|
sum=sum+workload1[i].workload;
|
|
|
|
|
}
|
|
|
|
|
printf("工作总量为:\n%d",sum);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|