C language staff information management system source code

  • 2020-06-03 07:24:21
  • OfStack

This article shares the specific code of C language staff information management system for your reference, the specific content is as follows


#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <conio.h> 
struct worker 
{ 
 char ID[20];// Work number  
 char name[20];// The name  
 char sex[5];// gender  
 char born[20];// birthday  
 char edu[20];// Record of formal schooling  
 char position[20];// position  
 char wage[10];// wage  
 char address[100];// address  
 char tel[15];// The phone  
}work[1000]; 
int n ; 
 
// File read-Write module  
void read()// Read the data  
{ 
 FILE *fp; 
 int i = 0; 
 if( (fp = fopen("d:\\date.txt","r")) == NULL ) 
 { 
  printf(" please D New in the root directory 1 A text file named date\n\n\n"); 
  system("pause"); 
  system("cls"); 
  return ; 
 } 
 fscanf(fp,"%d\n",&n); 
 while(i < n) 
 { 
  fscanf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",work[i].ID,work[i].name,work[i].sex,work[i].born,work[i].edu,work[i].position,work[i].wage,work[i].address,work[i].tel); 
  i ++; 
 } 
 fclose(fp); 
} 
void write()// Write data  
{ 
 FILE *fp; 
 int i = 0; 
 if( (fp = fopen("d:\\date.txt","w")) == NULL ) 
 { 
  printf(" Unable to open file! \n"); 
  return ; 
 } 
 fprintf(fp,"%d\n",n); 
 while(i < n) 
 { 
  fprintf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",work[i].ID,work[i].name,work[i].sex,work[i].born,work[i].edu,work[i].position,work[i].wage,work[i].address,work[i].tel); 
  i ++; 
 } 
 fclose(fp); 
} 
 
 
// Input module  
void input()//  Input from the keyboard  
{ 
 int i; 
 int flag;// Marks whether the job number already exists  
 char c;// instruction Y?N 
 read();// Read the original data in the file before entering the data  
 do 
 { 
  flag = 0; 
  printf("\t\t Please enter the employee's job number :        \n\t\t"); 
  scanf("%s",work[n].ID); 
  for(i = 0 ; i < n ; i ++) 
  { 
   if(strcmp(work[i].ID,work[n].ID) == 0) 
   { 
    flag = 1; 
    break; 
   } 
  } 
  if(flag) 
  { 
   printf(" The number already exists! \n\n"); 
   printf("\t\t Whether to continue typing ?(Y/N): "); 
   scanf("%*c%c",&c); 
   if(c == 'N' || c == 'n') break; 
   continue; 
  } 
  printf("\t\t Please enter the name of the employee :        \n\t\t"); 
  scanf("%s",work[n].name); 
  printf("\t\t Please enter the gender of the employee :        \n\t\t"); 
  scanf("%s",work[n].sex); 
  printf("\t\t Please enter the date of birth of the employee :       \n\t\t"); 
  scanf("%s",work[n].born); 
  printf("\t\t Please enter the educational background of the employee :        \n\t\t"); 
  scanf("%s",work[n].edu); 
  printf("\t\t Please enter the position of the employee :        \n\t\t"); 
  scanf("%s",work[n].position); 
  printf("\t\t Please enter the salary of the staff :        \n\t\t"); 
  scanf("%s",work[n].wage); 
  printf("\t\t Please enter the address of the employee :        \n\t\t"); 
  scanf("%s",work[n].address); 
  printf("\t\t Please enter the employee's telephone number :        \n\t\t"); 
  scanf("%s",work[n].tel); 
  printf("\t\t Whether to continue typing ?(Y/N): "); 
  scanf("%*c%c",&c); 
  n ++; 
 }while( c != 'N' && c != 'n'); 
 write(); 
 printf("\n\n Data saved! \n\n"); 
} 
 
 
// Display module  
void output_inf(int id) 
{ 
 printf("\t\t  Work number : %s\n",work[id].ID); 
 printf("\t\t  The name : %s\n",work[id].name); 
 printf("\t\t  gender : %s\n",work[id].sex); 
 printf("\t\t Date of birth : %s\n",work[id].born); 
 printf("\t\t  Record of formal schooling : %s\n",work[id].edu); 
 printf("\t\t  position : %s\n",work[id].position); 
 printf("\t\t  wage : %s\n",work[id].wage); 
 printf("\t\t  address : %s\n",work[id].address); 
 printf("\t\t  The phone : %s\n",work[id].tel); 
 printf("\n\n\n"); 
} 
void show()// Displays all employee information  
{ 
 int i; 
 read(); 
 if(n == 0) printf(" No record !\n\n"); 
 else 
  for(i = 0 ; i < n ; i ++) 
  { 
   output_inf(i); 
  } 
} 
 
 
// The query module  
void que()// Query information  
{ 
 char num; 
 int flag,i; 
 char q_id[20] ;// The query work number  
 char q_name[20] ;// The query name  
 char q_edu[20] ; // Query degree  
 char q_position[20] ;// The query position  
 char c;// instruction Y?N 
 read();// After opening the program, to query the previous data, to read in first  
 while(1) 
 { 
  system("cls"); 
  printf("\t\t****************** The query ********************\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    1. Press the number to inquire     *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    2. Search by name     *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    3. Enquiry by Education Background     *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    4. Enquiry by Job     *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*   Enter any other key to exit this module    *\n"); 
  printf("\t\t******************************************\n"); 
  printf("\t\t Please enter the instruction (1-4):"); 
  scanf("%*c%c",&num); 
  if(num < '1' || num > '4') 
  { 
   printf(" Wrong instruction! \n\n"); 
   system("pause"); 
   continue; 
  } 
  system("cls"); 
  flag = 0;// Used to mark the existence of employee information  
  if(num == '1')// Press the number to inquire  
  { 
   printf("\t\t Please enter the number of the employee you want to check: "); 
   scanf("%s",q_id); 
   for(i = 0 ; i < n ;i ++) 
   { 
    if( strcmp(work[i].ID,q_id) == 0) 
    { 
     output_inf(i); 
     flag = 1;// tag  
     break; 
    } 
   } 
  } 
  else if(num == '2')// Search by name  
  { 
   printf("\t\t Please enter the name of the employee you want to check: "); 
   scanf("%s",q_name); 
   for(i = 0 ; i < n ;i ++) 
   { 
    if( strcmp(work[i].name,q_name) == 0) 
    { 
     output_inf(i); 
     flag = 1;// tag  
    } 
   } 
  } 
  else if(num == '3')// Enquiry by Education Background  
  { 
   printf("\t\t Please enter the educational background of the employee you want to check: "); 
 
   scanf("%s",q_edu); 
   for(i = 0 ; i < n ;i ++) 
   { 
    if( strcmp(work[i].edu,q_edu) == 0) 
    { 
     output_inf(i); 
     flag = 1;// tag  
    } 
   } 
  } 
  else if(num == '4')// Enquiry by Job  
  { 
   printf("\t\t Please enter the position of the employee you want to check: "); 
   scanf("%s",q_position); 
   for(i = 0 ; i < n ;i ++) 
   { 
    if( strcmp(work[i].position,q_position) == 0) 
    { 
     output_inf(i); 
     flag = 1;// tag  
    } 
   } 
  } 
  if(!flag)// Determine if there is any information about the employee  
  { 
   printf("\n\n No information about the employee is available !\n\n"); 
  } 
  printf("\n\n Whether to continue the query (Y/N):"); 
 
  scanf("%*c%c",&c); 
  if(c == 'N' || c == 'n') break; 
 } 
} 
 
// Modify information module  
void mod()// Modify employee information  
{ 
 char change_ID[20];// The number of the employee to be modified  
 int number;// The location of employee information in the data  
 char num;// instruction  
 char message[100];// Modified information  
 char c;// instruction Y?N 
 int flag; 
 int i; 
 read(); 
 while(1) 
 { 
  flag = 0; 
  system("cls"); 
  printf(" Please enter the number of the employee to be modified: "); 
  scanf("%s",change_ID); 
  for(i = 0 ; i < n ; i ++) 
  { 
   if( strcmp(work[i].ID,change_ID) == 0 ) 
   { 
    number = i; 
    flag = 1; 
    break; 
   } 
  } 
  if(!flag) 
  { 
   printf("\n\n No such employee information!! \n\n"); 
   printf("\n\n Whether to continue to modify (Y/N):"); 
   scanf("%*c%c",&c); 
   if(c == 'N' || c == 'n') break; 
   continue; 
  } 
  printf("\n\n\t\t****************** Modify the ********************\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    1. Modify the name      *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    2. Modify the record of formal schooling      *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    3. Modify the job      *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    4. Modify the salary      *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    5. Modify the address      *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*    6. Modify the phone      *\n"); 
  printf("\t\t*          *\n"); 
  printf("\t\t*   Enter any other key to exit this module    *\n"); 
  printf("\t\t******************************************\n"); 
  printf("\t\t Please enter the instruction (1-6):"); 
  scanf("%*c%c",&num); 
  if(num < '1' || num > '6') 
  { 
   printf(" Wrong instruction! \n\n"); 
   system("pause"); 
   continue; 
  } 
  system("cls"); 
  printf(" Please enter the modified information: "); 
  scanf("%s",message); 
  switch(num) 
  { 
   case '1' : strcpy(work[number].name,message); break; 
   case '2' : strcpy(work[number].edu,message); break; 
   case '3' : strcpy(work[number].position,message); break; 
   case '4' : strcpy(work[number].wage,message); break; 
   case '5' : strcpy(work[number].address,message); break; 
   case '6' : strcpy(work[number].tel,message); break; 
  } 
  system("cls"); 
  printf("\n\n Whether to continue to modify (Y/N):"); 
  scanf("%*c%c",&c); 
  if(c == 'N' || c == 'n') break; 
 } 
 write(); 
} 
 
 
// Delete information module  
void del()// Delete employee information  
{ 
 char delete_ID[20];// Delete employee number  
 int i,j; 
 int flag;// Mark if there is information about the employee  
 char c; 
 read(); 
 while(1) 
 { 
  system("cls"); 
  flag = 0; 
  printf(" Please enter the number of the employee to be deleted: "); 
  scanf("%s",delete_ID); 
  for(i = 0 ; i < n ; i ++) 
  { 
   if( strcmp(work[i].ID,delete_ID) == 0) 
   { 
    n --; 
    flag = 1; 
    for(j = i ; j < n ; j ++) 
    { 
     work[j] =work[j + 1]; 
    } 
    break; 
   } 
  } 
  if(!flag) printf("\n\n No such employee information! \n\n"); 
  else printf("\n\n Delete successful! \n"); 
  printf("\n\n Whether to continue deletion (Y/N):"); 
  scanf("%*c%c",&c); 
  if(c == 'N' || c == 'n') break; 
 } 
 write(); 
} 
 
// Menu module  
void menu()// The menu  
{ 
 printf("\t\t************ Staff information management system menu **********\n"); 
 printf("\t\t*          *\n"); 
 printf("\t\t*    1. Input of employee information    *\n"); 
 printf("\t\t*          *\n"); 
 printf("\t\t*    2. Display employee information    *\n"); 
 printf("\t\t*          *\n"); 
 printf("\t\t*    3. Query employee information    *\n"); 
 printf("\t\t*          *\n"); 
 printf("\t\t*    4. Modify employee information    *\n"); 
 printf("\t\t*          *\n"); 
 printf("\t\t*    5. Delete employee information    *\n"); 
 printf("\t\t*          *\n"); 
 printf("\t\t*    0. exit      *\n"); 
 printf("\t\t*          *\n"); 
 printf("\t\t******************************************\n"); 
 printf("\t\t Please enter the instruction (0-5): "); 
} 
 
 
int main() 
{ 
 int num; 
 n = 0; 
 system("color 0B"); 
 while(1) 
 { 
  menu(); 
  scanf("%d",&num); 
  system("cls"); 
  switch(num) 
  { 
   case 1: input(); break; 
   case 2: show(); break; 
   case 3: que(); break; 
   case 4: mod(); break; 
   case 5: del(); break; 
   case 0: printf(" Thanks for using! \n\n"); return 0; 
   default :printf("\n---> Invalid instruction !\n\n\n"); 
  } 
  system("pause"); 
  system("cls"); 
 } 
} 

For more information, please pay attention to the topic management System Development.


Related articles: