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

📄 zg.c

📁 八、简单的职工管理系统 1.问题描述   对单位的职工进行管理
💻 C
字号:
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "conio.h"
#define N 100
#define M 1

typedef struct employee /*职工信息记录定义*/
 {int num; /*职工号*/
  char name[6]; /*姓名*/
  char sex[2];  /*性别*/
  char birithday[10]; /*生日*/
  char  cult[8]; /*学历*/
  char position[8]; /*职务*/
  int salary; /*工资*/
  char address[15]; /*住址*/
  char tel[11]; /*电话*/
 }ro;
ro em[N];

void input();
void display();
void find();
void find_num();
void find_name();
void find_cult();
void del();
void change();
void add();
void change_field();
char *change_field_cult();
char *change_field_position();
int  change_field_salary();
char *change_field_address();


int total;
int p;



void main()
{
     int choice;
     char s[10];
     char password[10]="ruanjian";
     int flag=0;
     int n=3;
     int m;
     do
     {
        printf("Please input password:");
        scanf("%s",s);
        if(!strcmp(s,password))
         {
            printf("\t\tWelcome enter the employee information manger!\n\n\n");
            flag=1;
            break;
          }
        else 
         {
            n--;
            printf("You also have the %d inferior opportunity\n",n);
          }
     }while(n>0);
       if(!flag)
       {printf("Input number of times already!\n");
        printf("Please land");
        getch();
        exit(0);
       }

   do
   {
    printf(" \n\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
    printf("  \t*\t    *                                       *           *\n");
    printf("  \t*\t    *     Employee information manger       *           *\n");
    printf("  \t*\t    *                                       *           *\n");
    printf("  \t*\t    * * * * * * * * * * * * * * * * * * * * *           *\n");
    printf("  \t*\t         *                             *                *\n");
    printf("  \t*\t        *     1.Input information       *               *\n");
    printf("  \t*\t       *                                 *              *\n");
    printf("  \t*\t      *       2.Display information       *             *\n");
    printf("  \t*\t     *                                     *            *\n");
    printf("  \t*\t    *         3.Find information            *           *\n");
    printf("  \t*\t   *                                         *          *\n");
    printf("  \t*\t    *         4.Delete information          *           *\n");
    printf("  \t*\t     *                                     *            *\n");
    printf("  \t*\t      *       5.Change information        *             *\n");
    printf("  \t*\t       *                                 *              *\n");
    printf("  \t*\t        *     6.Exit System             *               *\n");
    printf("  \t*\t         *                             *                *\n");
    printf("  \t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");
    printf("  \t                                              *Alexis Workgroup*\n");
    printf("\t\t\t\tPlease input(1-6):");
    scanf("%d",&m);
         switch(m)
   {
             case 1: input();
             clrscr();
             break;
             case 2:display();
             clrscr();
             break;
             case 3:find();
             clrscr();
             break;
             case 4:del();
             clrscr();
             break;
             case 5:change();
             clrscr();
             break;
             case 6:
             printf("^_^Bye_bye^_^\n");
             clrscr();
             return;
            default:printf("Your input has the mistake please to input\n");
   }
    }while(1);
}


void input(FILE *fp)
{
    int i=0;
    char choiceinput='y';
    if((fp=fopen("employee.txt","w"))==NULL)
    return;
    while(choiceinput=='y'||choiceinput=='Y')
 {
      i++;
      printf("The%demployee\n",i);
      printf("\n");
      printf("Please Input employee number(001-100):");
      scanf("%d",&em[i].num);
      printf("\n");
      printf("Please Input employee name:");
      scanf("%s",em[i].name);
      printf("\n");
      printf("Please Input employee sex(M/F):");
      scanf("%s",em[i].sex);
      printf("\n");
      printf("Please Input employee birithdayYY-MM-DD:");
      scanf("%s",em[i].birithday);
      printf("\n");
      printf("Please Input employee cult:");
      scanf("%s",&em[i].cult);
      printf("\n");
      printf("Please Input employee position:");
      scanf("%s",&em[i].position);
      printf("\n");
      printf("Please Input employee salary:");
      scanf("%d",&em[i].salary);
      printf("\n");
      printf("Please Input employee address:");
      scanf("%s",&em[i].address);
      printf("\n");
      printf("Please Input employee tel:");
      scanf("%s",&em[i].tel);
      printf("\n");
      printf("Whether continues(y/n):");
      scanf("%s",&choiceinput);
      fwrite(&em[i],sizeof(struct employee),M,fp);
    if(choiceinput=='n'||choiceinput=='N')
       {
          printf("The End!\n");
          fclose(fp);
          printf("press anykey back");
          getch();
          return;
       }
}
}


void display()
{FILE *fp;
   int i;
   if((fp=fopen("employee.txt","r"))==NULL)
     return;
   printf("Employee List:\n");
   printf("num name  sex birithday cult    position  salary  address        tel\n");
   printf("\n");
   for(i=0;fread(&em[i],sizeof(struct employee),M,fp)!=0;i++)
   {  
      printf("\n");
      printf("%-4d",em[i].num);
      printf("%-6s",em[i].name);
      printf("%-4s",em[i].sex);
      printf("%-10s",em[i].birithday);
      printf("%-8s",em[i].cult);
      printf("%-10s",em[i].position);
      printf("%-8.2d",em[i].salary);
      printf("%-15s",em[i].address);
      printf("%-11s",em[i].tel);
   }
   printf("\n");
   printf("List the end!\n press anykey continue");
   getch();
   fclose(fp);
    return;
}




void find()
{int n;
 clrscr();
 printf("\n\t\t* * * * * * * * * * * * * * * * * * * * * *\n");
 printf("  \t\t*   *                                 *   *\n");
 printf("  \t\t*   *              find_menu          *   *\n");
 printf("  \t\t*   *                                 *   *\n");
 printf("  \t\t*   * * * * * * * * * * * * * * * * * *   *\n");
 printf("  \t\t*        *                       *        *\n");
 printf("  \t\t*       *    1.Apoint find num    *       *\n");
 printf("  \t\t*      *                           *      *\n");
 printf("  \t\t*     *      2.Apoint find name     *     *\n");
 printf("  \t\t*    *                               *    *\n");
 printf("  \t\t*     *      3.Apoint find cult     *     *\n");
 printf("  \t\t*      *                           *      *\n");
 printf("  \t\t*       *    0.Exit               *       *\n");
 printf("  \t\t*        *                       *        *\n");
 printf("  \t\t* * * * * * * * * * * * * * * * * * * * * *\n");
 printf("  \t\t\t                       *Alexis workgroup*\n");
 printf("Please choose (1-3)Enter:");
 scanf("%d",&n);
 switch(n)
 {case 1: find_num();
         break;
  case 2: find_name();
         break;
  case 3: find_cult();
         break;
  case 0:break;
  default:printf("Error!!!");
 }
}




void find_num()
{FILE *fp;
 int find_num;
 int i;
 ro em[N];
  if((fp=fopen("employee.txt","r"))==NULL)
      {printf("No File! Press anykey continue……");
       getch();
       return;
      }
printf("please input find number:");
scanf("%d",&find_num);
for(i=0;fread(&em[i],sizeof(struct employee),M,fp)!=0;i++)
{if(em[i].num==find_num)
 {printf("This is you find information\n");
  printf("num name  sex birithday cult    position  salary  address        tel\n");
  printf("\n");
  printf("%-4d",em[i].num);
  printf("%-6s",em[i].name);
  printf("%-4s",em[i].sex);
  printf("%-10s",em[i].birithday);
  printf("%-8s",em[i].cult);
  printf("%-10s",em[i].position);
  printf("%-8.2d",em[i].salary);
  printf("%-15s",em[i].address);
  printf("%-11s",em[i].tel);
 }
 else
 {printf("No Number!press anykey back");
 getch();
 fclose(fp);
 return;
 }
}
}

void find_name()
{FILE *fp;
 int i;
 char find_name[8];
 if((fp=fopen("employee.txt","r"))==NULL)
   {printf("No File! Press anykey continue……");
    getch();
    return;
   }
 printf("please input find name:");
 scanf("%s",&find_name);
 for(i=0;fread(&em[i],sizeof(struct employee),M,fp)!=0;i++)
  {if(!strcmp(em[i].name,find_name))
   {printf("This is you find information\n");
    printf("num name  sex birithday cult    position  salary  address        tel\n");
    printf("\n");
    printf("%-4d",em[i].num);
    printf("%-6s",em[i].name);
    printf("%-4s",em[i].sex);
    printf("%-10s",em[i].birithday);
    printf("%-8s",em[i].cult);
    printf("%-10s",em[i].position);
    printf("%-8.2d",em[i].salary);
    printf("%-15s",em[i].address);
    printf("%-11s",em[i].tel);
   }
  else
   printf("No Name!press anykey back");
   getch();
   fclose(fp);
   return;
  }
 }

void find_cult()
{FILE *fp;
 int i;
 char find_cult[8];
 if((fp=fopen("employee.txt","r"))==NULL)
   {printf("No File! Press anykey continue");
    getch();
    return;
   }
 printf("please input find name:");
 scanf("%s",&find_cult);
 for(i=0;fread(&em[i],sizeof(struct employee),M,fp)!=0;i++)
  {if(strcmp(em[i].cult,find_cult)==0)
   {printf("This is you find information\n");
    printf("num name  sex birithday cult    position  salary  address        tel\n");
    printf("\n");
    printf("%-4d",em[i].num);
    printf("%-6s",em[i].name);
    printf("%-4s",em[i].sex);
    printf("%-10s",em[i].birithday);
    printf("%-8s",em[i].cult);
    printf("%-10s",em[i].position);
    printf("%-8.2d",em[i].salary);
    printf("%-15s",em[i].address);
    printf("%-11s",em[i].tel);
   }
  else
   printf("No Cult!press anykey back");
   getch();
   fclose(fp);
   return;
 }

}


void del()
{
 int i=0;
 char del_name[6];
 FILE *fp;
 if((fp=fopen("employee.txt","w"))==NULL)
 {
  printf("No File!\n press anykey continue\n");
  getch();
  return;
 }
 printf("Input delete name:\n");
 scanf("%s",del_name);
 for(i=0;i<N;i++)
 {
  if(strcmp(em[i].name,del_name)==0)
  {
   total--;
   for(;i<N;i++)
    em[i]=em[i+1];
  } 
 }
  i=0;
  fwrite(&em[i],sizeof(struct employee),total,fp);
  fclose(fp);
}



void change()
{int n;
 clrscr();
 printf("\n\t\t\t* * * * * * * * * * * * * * * * * * * * * *\n");
 printf("  \t\t\t*   *                                 *   *\n");
 printf("  \t\t\t*   *            change menu          *   *\n");
 printf("  \t\t\t*   *                                 *   *\n");
 printf("  \t\t\t*   * * * * * * * * * * * * * * * * * *   *\n");
 printf("  \t\t\t*       *                         *       *\n");
 printf("  \t\t\t*      *   1.Change information    *      *\n");
 printf("  \t\t\t*     *                             *     *\n");
 printf("  \t\t\t*    *  2.Add employee information   *    *\n");
 printf("  \t\t\t*     *                             *     *\n");
 printf("  \t\t\t*      *   3.Exit                  *      *\n");
 printf("  \t\t\t*       *                         *       *\n");
 printf("  \t\t\t* * * * * * * * * * * * * * * * * * * * * *\n");
 printf("  \t\t\t                           *Alexis workgroup*\n");
 printf("Please choose (1-3)Enter:");
 scanf("%d",&n);
 switch(n)
 {case 1:change_field();
         break;
  case 2: add();
         break;
  case 3:break;
  default:printf("Error!!!");
 }
}




 
void add()
{
 struct employee emp;
 FILE *fp;
 if((fp=fopen("employee.txt","ab+"))==NULL)
 {
  printf("No File! press anykey continue\n");
  getch();
  return;
 }
 printf("Asks you to input new person's content:\n");
 printf("Asks you to input the labor number:\n");
 scanf("%d",&emp.num);
 printf("Asks you to input the labor name:\n");
 scanf("%s",emp.name);
 printf("Asks you to input the labor sex:\n");
 scanf("%s",emp.sex);
 printf("Asks you to input the labor birithday:\n");
 scanf("%s",emp.birithday);
 printf("Asks you to input the labor cult:\n");
 scanf("%s",&emp.cult);
 printf("Asks you to input the labor position:\n");
 scanf("%s",&emp.position);
 printf("Asks you to input the labor salary:\n");
 scanf("%d",&emp.salary);
 printf("Asks you to input the labor address:\n");
 scanf("%s",&emp.address);
 printf("Asks you to input the labor tel:\n");
 scanf("%s",&emp.tel);
 fwrite(&emp,sizeof(struct employee),M,fp);
 rewind(fp);
 printf("The insertion finished, presses the random key to return\n");
 getch();
 total=total+1;
 fclose(fp);
 return;
}




void change_field()
{
 FILE *fp;
 int i;
 char chname[8];
 ro a[N];
 int n;
 printf("please input change name:\n");
 scanf("%s",&chname);
 if((fp=fopen("employee.txt","w+"))==NULL)
 {
  printf("No File\n");
  return;
 }
 for(i=0;i<N;i++)
 {
  if(strcmp(chname,em[i].name)==0)
  {clrscr();
   printf("This is you change information\n");
   printf("num:%d name:%s sex:%s birithday:%s cult:%s position:%s salary:%d address:%s tel:%c\n",em[i].num,em[i].name,em[i].sex,em[i].birithday,em[i].cult,em[i].position,em[i].salary,em[i].address,em[i].tel);
   printf("--------------------------------------------------------\n");
   printf("Please input :\n");
   printf("========================================================\n");
   printf("1.Change position\n");
   printf("2.Change cult\n");
   printf("3.Change salary\n");
   printf("4.Change address\n");
   printf("0.Exit\n");
   printf("========================================================\n");
   printf("choose(0—4\n");
   scanf("%d",&n);
   switch(n)
   {
   case 1:
    strcpy(em[i].position,change_field_position());
    break;
   case 2:
    strcpy(em[i].cult,change_field_cult());
    break;
   case 3:
    em[i].salary=change_field_salary();
    break;
   case 4:
    strcpy(em[i].address,change_field_address());
    break;
   case 0:
    return;
   default :
    printf("Error!!!");
   }
   a[i]=em[i];
  }
  else
  {
   a[i]=em[i];
  }
 }
 for(i=0;i<total;i++)
 {em[i]=a[i];
  i=0;
  fwrite(&em[i],sizeof(struct employee),total,fp);
  fclose(fp);
  printf("Succeed!\n");
  getch();
  return;
 }
 }


char *change_field_position()
{
 char newposition[8];
 printf("input new position:\n");
 scanf("%s",newposition);
 return (newposition);
 }

char *change_field_cult()
{
 char newcult[8];
 printf("input new cult:\n");
 scanf("%s",&newcult);
 return (newcult);
}


int change_field_salary()
{
 int newsalary;
 printf("input new salary:\n");
 scanf("%d",&newsalary);
 return(newsalary);
}


char *change_field_address()
{
 char newaddress[15];
 printf("input new address:\n");
 scanf("%s",&newaddress);
 return (newaddress);
}

⌨️ 快捷键说明

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