⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhigongguanlixit.txt

📁 职工管理系统。希望对有需要的朋友方便。发行这个网站不错。资源很多
💻 TXT
📖 第 1 页 / 共 2 页
字号:


   #include
#include
#include
#include
#define maxworker 100

FILE *fp;  /*定义全局变量fp,指向数据库文件 worker.txt*/

struct date{      /*日期的结构,用于存储工人的生日,工作日期等*/
  int year;
  int month;
  int day;
};
struct address {  /*地址的结构, 用于存储工人的地址*/
  char province[10];
  char city[10];
  char street[20];
};
struct WORKER {       /*工人的资料总结构*/
 char name[20];
 enum {male,female}sex;
 struct date birthday;
 enum {elesch,middle,high,university,other}rofs;
 struct date workday;
 int workeri;
 char position[20];
 struct address addr;
 int workerj;
 char tel[13];
 };
/*程序的初始化函数,用于从数据库中读出现存的资料到内存中*/
data_load(int *i,struct WORKER *p){
 char c;
 long int k;
 fp=fopen("worker.txt","r");
 if(!fp){fopen("worker.txt","w+");*i=0;}
 else{
 for((*i)=0;(*i)  if(feof(fp)) return;
  c=fgetc(fp);
  if(c==EOF) return;
  fflush(stdin);
  k=*i;
  fseek(fp,k*sizeof(struct WORKER),SEEK_SET);
  fread(&p[*i],sizeof(struct WORKER),1,fp);
  }
 }
fclose(fp);
}
/*添加一个工人的资料*/

void add(int *i,struct WORKER *profile){
 char add_name[20],add_position[20],add_addr_province[20],add_addr_city[20],add_addr_street[30],add_tel[13];
 int add_birthday_year,add_birthday_month,add_birthday_day,add_workday_year,add_workday_month,add_workday_day;
 int add_sex,add_rofs;
 enum {false,true}status;
 status=false;
 printf("\n\tNow add NO. %d worker's profile\n",*i+1);

 /*以下是处理输入的循环*/
   while(status==false){
  printf("Enter the name of the worker:");
  scanf("%s",add_name);
     if(strlen(add_name)==0 || strlen(add_name)>20){
         status=false;puts("input error,name cannot over 8 character or less than 0 character!");
         continue;
     }
     else 
        status=true;
  printf("Enter the gender of worker:(1=>female,0=>male)");
  scanf("%d",&add_sex);
     if(add_sex!=0 && add_sex!=1){
         status=false;puts("only 0 or 1 can be accepted!");
         continue;
     }
     else
        status=true;
  printf("Enter the birthday of worker:\n");
  printf("\tYear:");
  scanf("%4d",&add_birthday_year);
     if(add_birthday_year>9999 || add_birthday_year<0){
         status=false;puts("input error,the year of birthday cannot more than 9999 or less than 0!");
         continue;
      }
     else
        status=true;
printf("\tMonth:");
  scanf("%2d",&add_birthday_month);
     if(add_birthday_month>12 || add_birthday_month<1){
         status=false;puts("input error,the month of birthday cannot be more than 12 or less than 1");
         continue;
      }
     else
        status=true;
printf("\tDay:");
  scanf("%2d",&add_birthday_day);
     if(add_birthday_day>31 || add_birthday_day<1){
         status=false;puts("input error,the year of birthday cannot be more than 31 or less than 1!");
         continue;
      }
     else
        status=true;
  printf("Enter the workday of worker:\n");
  printf("\tYear:");
  scanf("%4d",&add_workday_year);
     if(add_workday_year>9999 || add_workday_year<0){
         status=false;puts("input error,the year of workday cannot more than 9999 or less than 0!");
         continue;
      }
     else
        status=true;
printf("\tMonth:");
  scanf("%2d",&add_workday_month);
     if(add_workday_month>12 || add_workday_month<1){
         status=false;puts("input error,the month of workday cannot be more than 12 or less than 1");
         continue;
      }
     else
        status=true;
printf("\tDay:");
  scanf("%2d",&add_workday_day);
     if(add_workday_day>31 || add_workday_day<1){
         status=false;puts("input error,the year of workday cannot be more than 31 or less than 1!");
         continue;
      }
     else
        status=true;

  printf("Enter the record of formal schooling of worker:(0=>element school,1=>middle school,2=>high school,3=>university,4=>other)");
  scanf("%d",&add_rofs);
     if(add_rofs!=0 && add_rofs!=1 &&add_rofs!=2 &&add_rofs!=3 &&add_rofs!=4){
         status=false;puts("only digit can be accepted!you can only enter 0,1,2,3,4");
         continue;
     }
     else 
        status=true;
  printf("Enter the position of worker:");
  scanf("%s",add_position);
     if(strlen(add_position)==0 || strlen(add_position)>20){
         status=false;puts("input error,position cannot over 20 character or less than 0 character!");
         continue;
     }else 
        status=true;
  printf("Enter the address of worker:\n");
  printf("\tProvince:");
  scanf("%s",add_addr_province);
     if(strlen(add_addr_province)==0 || strlen(add_addr_province)>20){
         status=false;puts("input error,province cannot over 20 character or less than 0 character!");
         continue;
     }
     else 
       status=true;
printf("\tCity:");
scanf("%s",add_addr_city);
     if(strlen(add_addr_city)==0 || strlen(add_addr_city)>20){
         status=false;puts("input error,city cannot over 20 character or less than 0 character!");
         continue;
     }
     else 
       status=true;
printf("\tStreet:");
scanf("%s",add_addr_street);
     if(strlen(add_addr_street)==0 || strlen(add_addr_street)>30){
         status=false;puts("input error,street cannot over 30 character or less than 0 character!");
         continue;
     }
     else 
       status=true;
  printf("Enter the telephone number of worker:(area code/telephone code)");
  scanf("%s",add_tel);
     if(strlen(add_tel)==0 || strlen(add_tel)>13){
        status=false;puts("input error,telephone number cannot over 13 character or less than 0 character!");
        continue;
     }
    else
      status=true;
 }

 /*检查完毕,开始将输入的东西保存到结构数组中*/

strcpy(profile[*i].name,add_name);
profile[*i].sex=add_sex;

profile[*i].birthday.year=add_birthday_year;
profile[*i].birthday.day=add_birthday_day;
profile[*i].birthday.month=add_birthday_month;

profile[*i].workday.year=add_workday_year;
profile[*i].workday.day=add_workday_day;
profile[*i].workday.month=add_workday_month;

profile[*i].rofs=add_rofs;

strcpy(profile[*i].position,add_position);
strcpy(profile[*i].addr.province,add_addr_province);
strcpy(profile[*i].addr.city,add_addr_city);
strcpy(profile[*i].addr.street,add_addr_street);

strcpy(profile[*i].tel,add_tel);
++(*i);
printf("\n\nin function add :i=%d\n\n",*i);
}

/*显示所有的工人资料的列表*/

void list(int i,struct WORKER *prof){
int j;
char temp[20];
if(i==0){printf("There is no profile in the list!\nPress any key to return!\n");getch();return;}
printf("========There are %d workers' profiles========\n\n",i);
 for(j=0;j  printf("NO. %d worker's profile=>\n",(j+1));
 printf("\n\tName: %s\n",prof[j].name);
 if(prof[j].sex)
   strcpy(temp,"Female");
 else
   strcpy(temp,"Male"); 
 printf("\tGender:%s\n",temp);
 printf("\tBirthday:");
   printf("%4d %2d %2d\n",prof[j].birthday.year,prof[j].birthday.month,prof[j].birthday.day);
 printf("\tWorkday:");
   printf("%4d %2d %2d\n",prof[j].workday.year,prof[j].workday.month,prof[j].workday.day);
 switch(prof[j].rofs){
  case 0:
   strcpy(temp,"Element school");
   break; 
  case 1:
   strcpy(temp,"Middle school");
   break;
  case 2:
   strcpy(temp,"High school");
   break;
  case 3:
   strcpy(temp,"University");
   break;
  case 4:
   strcpy(temp,"Other");
   break;
  default:
  strcpy(temp,"Error");
 }
 printf("\tThe record of formal schooling:%s\n",temp);
 printf("\tPosition:%s\n",prof[j].position);
 printf("\tAddress:%s %s city %s province\n",prof[j].addr.street,prof[j].addr.city,prof[j].addr.province);
 printf("\tTelephone number:%s\n",prof[j].tel);
 getch();
 }
}

/*显示指定的工人的资料*/

void display(int dk,struct WORKER *prof){
char temp[20];
 if(dk>maxworker)
  return;
printf("\n===============The profile of %s=================\n\n",prof[dk].name);
printf("\n\tName: %s\n",prof[dk].name);
 if(prof[dk].sex)
   strcpy(temp,"Female");
 else
   strcpy(temp,"Male"); 
 printf("\tGender:%s\n",temp);
 printf("\tBirthday:%4d %2d %2d\n",prof[dk].birthday.year,prof[dk].birthday.month,prof[dk].birthday.day);
 printf("\tWorkday:%4d %2d %2d\n",prof[dk].workday.year,prof[dk].workday.month,prof[dk].workday.day);
 switch(prof[dk].rofs){
  case 0:
   strcpy(temp,"Element school");
   break; 
  case 1:
   strcpy(temp,"Middle school");
   break;
  case 2:
   strcpy(temp,"High school");
   break;
  case 3:
   strcpy(temp,"University");
   break;
  case 4:
   strcpy(temp,"Other");
   break;
  default:
  strcpy(temp,"Error");
 }
 printf("\tThe record of formal schooling:%s\n",temp);
 printf("\tPosition:%s\n",prof[dk].position);
 printf("\tAddress:%s %s city %s province\n",prof[dk].addr.street,prof[dk].addr.city,prof[dk].addr.province);
 printf("\tTelephone number:%s\n",prof[dk].tel);
 getch();
}

/*从数据库中搜索一个指定的工人的资料*/

int search(int i,struct WORKER * sp,int mode,char trans[]){
 char search_name[20];
 int j,n;

 /*错误处理*/
if(!strcmp(trans,"")){
  printf("Please enter the name that you want to search:");
  scanf("%s",search_name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -