diff --git a/Untitled1.cpp b/Untitled1.cpp index 62a1643..3037e57 100644 --- a/Untitled1.cpp +++ b/Untitled1.cpp @@ -1,13 +1,18 @@ #include "stdio.h" +#include "stdlib.h" +#define FILENAME "worker.bin" #define N 20 +/******************************************************* +定义 +*******************************************************/ struct worker { int number; /*工号*/ int counts; /*数量*/ -int grade; /*等级*/ +int grade; /*排名*/ }; /******************************************************* -定义 +显示菜单 *******************************************************/ void xinxi() { @@ -24,15 +29,95 @@ printf("+ 4. 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(worker),1,fp)==1) +i++; +} +fclose(fp); +} +return i; +} +/******************************************************* +功能:输入职工基本信息 +*******************************************************/ +int f(struct worker w[],int length) +{ +int i=length; +while(i=length) +printf("工号不存在:\n"); +printf("请输入工号:"); +scanf("%d",&number);printf("工号不存在:\n"); +printf("请输入工号:"); +scanf("%d",&number); +} +} int main (){ -int choice; +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); - } diff --git a/Untitled1.exe b/Untitled1.exe index 0778119..918c460 100644 Binary files a/Untitled1.exe and b/Untitled1.exe differ