parent
482cb1706c
commit
17e84b640c
@ -0,0 +1,123 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#define FILENAME "worker.bin"
|
||||
#define N 20
|
||||
/*******************************************************
|
||||
定义
|
||||
*******************************************************/
|
||||
struct worker
|
||||
{
|
||||
int number; /*工号*/
|
||||
int counts; /*数量*/
|
||||
int grade; /*排名*/
|
||||
};
|
||||
/*******************************************************
|
||||
显示菜单
|
||||
*******************************************************/
|
||||
void xinxi()
|
||||
{
|
||||
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");
|
||||
}
|
||||
/*******************************************************
|
||||
信息显示到屏幕
|
||||
*******************************************************/
|
||||
readFromFile(struct worker w[])
|
||||
{
|
||||
FILE *fp=NULL;
|
||||
int i=0;
|
||||
fp=fopen(FILENAME,"rb"); /*打开文件*/
|
||||
if(fp!=NULL)
|
||||
{
|
||||
while(!feof(fp)) /*从文件中读入学生*/{
|
||||
if(i>=N)
|
||||
break;
|
||||
if(fread(w+i,sizeof(w),1,fp)==1)
|
||||
i++;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
/*******************************************************
|
||||
功能:输入职工基本信息
|
||||
*******************************************************/
|
||||
int f(struct worker w[],int length)
|
||||
{
|
||||
int i=length;
|
||||
while(i<N){
|
||||
printf("第%d个职工\n",i);
|
||||
printf("\n");
|
||||
printf("请你输入工号(以职工号为0结束):\n");/*输入工号*/
|
||||
scanf("%d",&w[i].number);
|
||||
if(w[i].number==0)
|
||||
break;
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
printf("请你输入数量:\n");/*输入数量*/
|
||||
scanf("%d",&w[i].counts);
|
||||
printf("\n");
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
/*******************************************************
|
||||
功能:工作量输入并累加
|
||||
*******************************************************/
|
||||
void input(struct worker w[],int length)
|
||||
{
|
||||
int i=1;
|
||||
int number,counts;
|
||||
printf("请输入工号:");
|
||||
scanf("%d",&number);
|
||||
while(number!=0)
|
||||
{
|
||||
printf("请输入完成数量:\n");
|
||||
scanf("%d",&counts);
|
||||
for(i=0;i<length;i++)
|
||||
if(w[i].number==number)
|
||||
{
|
||||
w[i].counts+=counts;
|
||||
break;
|
||||
}
|
||||
if(i>=length)
|
||||
printf("工号不存在:\n");
|
||||
printf("请输入工号:");
|
||||
scanf("%d",&number);printf("工号不存在:\n");
|
||||
printf("请输入工号:");
|
||||
scanf("%d",&number);
|
||||
}
|
||||
}
|
||||
int main (){
|
||||
|
||||
int choice;
|
||||
struct worker w[N];
|
||||
int NUM;
|
||||
char stuName[100];
|
||||
int stuNum;
|
||||
int length=0;
|
||||
length=readFromFile(w);//读入
|
||||
do
|
||||
{ xinxi();
|
||||
scanf("%d",&choice);
|
||||
switch(choice)
|
||||
{ case 1:
|
||||
length=f(w,length);
|
||||
break;
|
||||
case 2:
|
||||
input(w,length);
|
||||
break;
|
||||
}
|
||||
}while(1);
|
||||
}
|
Binary file not shown.
Loading…
Reference in new issue