C++ to realize the enterprise staff salary management system

  • 2020-06-03 07:26:15
  • OfStack

Objectives and requirements of course design

Wage management and personnel management, the actual production of every employee of the enterprise salary.

The basic information of enterprise staff and personnel includes employee number, name, gender, date of birth, professional title (assistant, engineer, senior engineer) and length of service.

Enterprise worker salary information includes: worker number, name, duty salary, duty allowance, housing allowance, should pay salary, individual income tax, endowment insurance, housing accumulation fund and pay salary actually.

The main functions of the system include:

(1) Create the basic information file of staff and personnel, input various information of staff according to prompts, sort the staff information according to the number of staff, and store the sorted staff information into one file.

(2) Create the salary information file of the employee (create 1 file every month), in which the employee number and name are copied from the personnel information file. Other salary components shall be calculated according to the following method.

Salary on duty: assistant =1270*(1+ years of service *2%)

Engineer =2360*(1+ years of service *3%)

Senior Engineer =3450*(1+ years of service *5%)

Job subsidy: = job salary *25%

Housing allowance = (duty salary + duty allowance) *15%

Should pay salary = duty salary + duty allowance + housing allowance

Personal income tax = (payroll -3000) *5%

Endowment insurance = (duty salary + duty subsidy) *10%

Housing accumulation fund = salary payable *5%

Pay salary = should pay salary - individual income tax - pension insurance - housing provident fund

(3) Increase the basic information of staff and personnel, and add the new information of staff and personnel on the basis of the original basic information files of staff and personnel.

(4) Delete the basic staff and personnel information, prompt the user to input the employee number to be deleted, if the information exists in the file, output its information to the screen, the user will confirm the deletion of the information, and save the deleted results to the original file. Finally, the user is prompted to continue with the delete operation.

(5) Modify the basic staff and personnel information, prompt the user to input the employee number to be deleted, if the information exists in the file, output its information to the screen, then prompt the user to modify the options (title, tenure), and save the modified results to the original file. Finally, the user is prompted to continue the modification operation.

(6) Conduct inquiry operation according to different conditions, and output the salary information of employees meeting the conditions.

(1) according to the employee number query, input 1 number, output corresponding employee salary information.

(2) query by name, including precise query, fuzzy query.

(3) Query by professional title, input professional title name, output the corresponding professional title salary information.

(7) According to different conditions of the wage information for the statistical work.

(1) Statistics of the number of staff and workers in posts of professional titles is how many, calculate the proportion of senior engineers.

(2) calculate the average real wages of enterprise employees, and output.

(3) statistics of the number of workers whose wages are lower than the average wage, and output their names and real wages.

Code:


#include<stdafx.h> 
#include<stdio.h> 
#include<stdlib.h> 
#include<string.h> 
#include<conio.h> 
#include<time.h> 
 
typedef struct date 
{ 
 short year; 
 short month; 
 short day; 
}st3; 
typedef struct gerenxinxi 
{ 
 char num[30]; 
 char name[30]; 
 char sex[30]; 
 st3 chushengriqi; 
 char zhicheng[20]; 
 int nianxian; 
}st; 
typedef struct gerengongzi 
{ 
  char num[20]; 
  char name[12]; 
  double zhiwugongzi; 
  double zhiwubutie; 
  double zhufangbutie; 
  double yingfagongzi; 
  double gerensuodeshui; 
  double yanglaobaoxian; 
  double zhufanggongjijin; 
  double shifagongzi; 
}st1; 
#define st3_len sizeof(st3) 
#define st_len sizeof(st) 
#define st1_len sizeof(st1) 
#define gerenxinxinum 1000 
#define gerengongzinum 1000 
st gerenxinxi[gerenxinxinum]={0}; 
st1 gerengongzi[gerengongzinum]={0}; 
 
int loadgerenxinxi(void);// Read the information in the file  
int originalgerenxinxi(void);// Personal information initialization  
void getonegerenxinxi(int i);// Lose, ru1 Personal information of employees  
void allgerenxinxi(int bn);// Save all information  
void xggerenxinxi(int bn);// Modify personal information  
void saveonegerenxinxi(int i);// Keep personal information  
int addgerenxinxi(int bn);// Add personal information  
int delgerenxinxi(int bn); // Delete personal Information  
void putonegerenxinxi(int i);// The output 1 Personal Information  
void sort(int bn);// The sorting  
void shengchenggongzi(int bn);// Generate wage  
void putonegerengongzi(int i);// The output 1 Personal salary information  
void cxgerenxinxi(int bn);// The query  
void cxzhicheng(int bn);// Title query  
void cxname(int bn);// Name query  
void cxnum(int bn);// Number query  
void tongjigongzixinxi(int bn);// Statistical salary information  
float avegongzi(int bn);// The average salary  
void lowgongzi(int bn);// Below average wages  
void gangweirenshu(int bn);// The worker number  
 
void main() 
{ int select,bn; 
  bn=loadgerenxinxi(); 
  if(bn==0) 
  printf(" Employee information is zero :"); 
 
  while(1) 
  { 
   printf("\n  Enterprise employee salary management system   \n"); 
   printf("\n-----------------------------\n"); 
   printf("\n  Please enter the serial number before you want to operate  \n"); 
   printf("\n  1. Input employee information    \n"); 
   printf("\n  2. Modify employee information    \n"); 
   printf("\n  3. Increase employee information    \n"); 
   printf("\n  4. Delete employee information    \n"); 
   printf("\n  5. The worker wages     \n"); 
   printf("\n  6. Statistical salary information    \n"); 
   printf("\n  7. Check salary information    \n"); 
   printf("\n  0. exit      \n"); 
   printf("\n----------------------------\n"); 
    
   scanf("%d",&select); 
   getchar(); 
   switch(select) 
   { case 1: originalgerenxinxi(); break; 
    case 2: xggerenxinxi(bn); break; 
    case 3: addgerenxinxi(bn); break; 
    case 4: delgerenxinxi(bn); break; 
    case 5: shengchenggongzi(bn); break; 
    case 6: tongjigongzixinxi(bn); break; 
    case 7: cxgerenxinxi(bn); break; 
    case 0: return; 
    default:printf("\n Button error, please select again \n"); 
   } 
  } 
  
} 
//===================================================== 
 
int loadgerenxinxi(void)// Read the information in the file  
{ 
 FILE *fb; 
 int bn=0; 
 if((fb=fopen("gerenxinxi.txt","r+"))==NULL) 
 {printf(" Can't open \n"); 
 return(bn); 
 } 
while(!feof(fb)) 
 if(fread(&gerenxinxi[bn],st_len,1,fb)) 
 bn++; 
 fclose(fb); 
 return(bn); 
} 
//====================================================== 
 
 
int originalgerenxinxi(void)// Personal information initialization  
{ 
  int n; 
  char c='y'; 
  for(n=0;c=='y';n++) 
  { printf("\n Input the worker %d The information of :\n",n+1); 
  getonegerenxinxi(n); 
  printf("\n Press to continue typing 'y', Stop please click 'n':"); 
  c=getchar(); getchar(); 
  } 
  sort(n); 
  allgerenxinxi(n); 
  return(n); 
} 
//====================================================== 
void getonegerenxinxi(int i)// Lose, ru1 Personal information of employees  
{ 
 printf(" Employee No. : "); 
 gets(gerenxinxi[i].num); 
 printf(" Name: "); 
 gets(gerenxinxi[i].name); 
 printf(" Gender: "); 
 gets(gerenxinxi[i].sex); 
 printf(" Date of Birth "); 
 scanf("%d.%d.%d",&gerenxinxi[i].chushengriqi.year,&gerenxinxi[i].chushengriqi.month,&gerenxinxi[i].chushengriqi.day); 
 getchar(); 
 printf(" The title ( Assistant, engineer   , Senior Engineer ) : "); 
 gets(gerenxinxi[i].zhicheng); 
 printf(" Years of Service: "); 
 scanf("%d",&gerenxinxi[i].nianxian); 
 getchar(); 
} 
//====================================================== 
 
void allgerenxinxi(int bn)// Save all information  
{ FILE *fb; 
  if((fb=fopen("gerenxinxi.txt","w"))==NULL) 
  { printf(" Can't open \n"); 
  exit(1); 
  } 
  fwrite(gerenxinxi,st_len,bn,fb); 
  fclose(fb); 
} 
//======================================================= 
 
void xggerenxinxi(int bn)// Modify personal information  
{ 
 int select,k=-1; 
 char number[20],c1='y',c2; 
 if(bn==0) 
 { printf("\n Employee information is empty \n:"); 
 return; 
 } 
 while(c1=='y') 
 {c2='y'; 
 printf("\n Please enter the employee number to be modified \n"); 
 gets(number); 
 for(int i=0;i<bn;i++) 
  if(strcmp(gerenxinxi[i].num,number)==0) 
 { k=i; 
 break;} 
 if(k<0) 
  printf("\n The number is wrong, please re-enter \n"); 
 else 
 { printf("\n The worker information :\n"); 
  putonegerenxinxi(k); 
  while(c2=='y') 
   { 
    printf("\n Please enter the serial number before you want to modify the item :\n"); 
    printf("1. The title \n"); 
    printf("2. Office term \n"); 
    printf("0. Exit the program \n"); 
     
    scanf("%d",&select); 
    getchar(); 
    switch(select) 
    { 
     case 1:printf(" The title :"); 
      gets(gerenxinxi[k].zhicheng); 
      break; 
     case 2:printf(" Fixed number of year of the entry :"); 
      scanf("%d",&gerenxinxi[k].nianxian); 
      getchar(); 
      break; 
     case 0: 
      exit(1); 
     default: 
      printf("\n Key error, please reenter \n"); 
    } 
    printf("\n Do you need to change any other information about the employee (y/n) ? \n"); 
    c2=getchar(); 
    getchar(); 
    } 
  } 
   saveonegerenxinxi(k); 
   printf("\n Do you need to change any other employee information? (y/n)\n"); 
   c1=getchar(); 
   getchar(); 
  } 
 printf("\n Press any key to continue \n"); 
 getchar(); 
} 
//====================================================== 
 
void saveonegerenxinxi(int i)// Keep personal information  
{ 
 FILE *fb; 
 if((fb=fopen("gerenxinxi.txt","r+"))==NULL) 
 {printf(" Can't open  \n"); 
 exit(1); 
 } 
 fseek(fb,st_len*i,0); 
  fwrite(&gerenxinxi[i],st_len,1,fb); 
 fclose(fb); 
} 
 
//====================================================== 
int addgerenxinxi(int bn)// Add personal information  
{ char c='y'; 
 FILE *fb; 
 if((fb=fopen("gerenxinxi.txt","a"))==NULL) 
 {printf(" Can't open \n"); 
 exit(1); 
 } 
 while(c=='y') 
 {printf("\n Please enter the new employee information: \n"); 
  getonegerenxinxi(bn); 
  fwrite(&gerenxinxi[bn],st_len,1,fb); 
  bn++; 
  printf("\n Continue to enter other employee information ?(y/n):"); 
  c=getchar(); 
  getchar(); 
 } 
 
 printf("\n Press any key to continue \n:"); 
 getch(); 
 fclose(fb); 
 return(bn); 
} 
//====================================================== 
 
int delgerenxinxi(int bn) // Delete personal Information  
{ 
  int k=-1; 
  char number[20],c1='y',c2; 
  if(bn==0) 
  { printf("\n Information is empty \n"); 
  return(bn); 
  } 
  while(c1=='y') 
  { c2='y'; 
   printf("\n Enter the employee number to delete \n"); 
   gets(number); 
   for(int i=0;i<bn;i++) 
    if(strcmp(gerenxinxi[i].num,number)==0) 
    { k=i; 
     break;} 
   if(k<0) 
    printf("\n Wrong number, re-enter \n"); 
  else 
  { 
   printf("\n The worker information :\n"); 
   putonegerenxinxi(k); 
   printf("\n Are you sure you want to delete all information about the employee ?(y/n):"); 
   c2=getchar(); 
   getchar(); 
   if(c2=='y') 
   { for(i=k;i<bn;i++) 
     gerenxinxi[i]=gerenxinxi[i+1]; 
    bn--; 
    printf("\n Deleted successfully !\n"); 
   } 
   else 
    printf("\n delete !\n"); 
   printf("\n Continue to delete other employee information ?(y/n):"); 
   c1=getchar(); getchar(); 
  }   
  } 
  allgerenxinxi(bn); 
  printf("\n Press any key to continue !\n"); 
  getch(); 
  return(bn); 
} 
//==================================================== 
void putonegerenxinxi(int i)// The output 1 Personal Information  
{ 
 printf("\n"); 
 printf(" Employee Numbers :"); 
 puts(gerenxinxi[i].num); 
 printf(" The name :"); 
 puts(gerenxinxi[i].name); 
 printf(" gender :"); 
 puts(gerenxinxi[i].sex); 
 printf(" Date of birth :"); 
 printf("%d.%d.%d\n",gerenxinxi[i].chushengriqi.year,gerenxinxi[i].chushengriqi.month,gerenxinxi[i].chushengriqi.day); 
 printf(" The title :"); 
 puts(gerenxinxi[i].zhicheng); 
 printf(" Office term :"); 
 printf("%d",gerenxinxi[i].nianxian);   
} 
 
//================================================== 
void sort(int bn)// The sorting  
{ 
 st temp; 
 int i,j; 
 for(i=0;i<bn-1;i++); 
 { 
   for(j=i+1;j<bn;j++) 
   if(gerenxinxi[i].num >gerenxinxi[i+1].num ) 
   { temp=gerenxinxi[i]; 
    gerenxinxi[i]=gerenxinxi[i+1]; 
    gerenxinxi[i+1]=temp; 
   } 
 
 } 
} 
//================================================= 
void shengchenggongzi(int bn)// Generate wage  
{  
  FILE *fp,*fp2; 
  int i,j; 
  if ((fp = fopen("gerenxinxi.txt", "r")) == NULL) 
  { 
   printf(" Can't open \n"); 
   exit(0); 
  } 
  fread(gerenxinxi,st_len,bn, fp); 
  if ((fp2 = fopen("gerengongzi.txt", "w")) == NULL) 
  { 
  printf(" Can't open \n"); 
  exit(0); 
  } 
  for(i=0;i<bn;i++) 
  { strcpy(gerengongzi[i].name, gerenxinxi[i].name); 
   strcpy(gerengongzi[i].num, gerenxinxi[i].num); 
   if (strcmp(gerenxinxi[i].zhicheng," Assistant engineer ") == 0) 
   {gerengongzi[i].zhiwugongzi=1270*(1+gerenxinxi[i].nianxian*0.02);} 
   if (strcmp(gerenxinxi[i].zhicheng," The engineer ") == 0) 
   {gerengongzi[i].zhiwugongzi=2360*(1+gerenxinxi[i].nianxian*0.03);} 
   if (strcmp(gerenxinxi[i].zhicheng," Senior Engineer ") == 0) 
   {gerengongzi[i].zhiwugongzi=3450*(1+gerenxinxi[i].nianxian*0.05);} 
 
   gerengongzi[i].zhiwubutie=gerengongzi[i].zhiwugongzi*0.25; 
 
   gerengongzi[i].zhufangbutie=(gerengongzi[i].zhiwubutie+gerengongzi[i].zhiwugongzi)*0.15; 
 
   gerengongzi[i].yingfagongzi=gerengongzi[i].zhiwugongzi+gerengongzi[i].zhiwubutie+gerengongzi[i].zhufangbutie; 
   
   if(gerengongzi[i].yingfagongzi>3000) 
   
    gerengongzi[i].gerensuodeshui=(gerengongzi[i].yingfagongzi-3000)*0.05; 
   
   else 
    
    gerengongzi[i].gerensuodeshui=0; 
 
   gerengongzi[i].yanglaobaoxian=(gerengongzi[i].zhiwubutie+gerengongzi[i].zhiwugongzi)*0.1; 
 
   gerengongzi[i].zhufanggongjijin=gerengongzi[i].yingfagongzi*0.05; 
 
   gerengongzi[i].shifagongzi=gerengongzi[i].yingfagongzi-gerengongzi[i].gerensuodeshui-gerengongzi[i].yanglaobaoxian-gerengongzi[i].zhufanggongjijin; 
   
 } 
  printf("\n"); 
  fwrite(gerengongzi,st1_len,bn,fp2); 
  fclose(fp); 
  fclose(fp2); 
  if ((fp = fopen("gerengongzi.txt", "r+")) == NULL) 
  { 
   printf(" Can't open \n"); 
   exit(1); 
  } 
  fread(gerengongzi,st1_len,bn,fp2); 
  for(j=0;j<bn;j++) 
  putonegerengongzi(j); 
   fclose(fp); 
} 
//========================================================== 
 
void putonegerengongzi(int i)// The output 1 Personal salary information  
{ 
  printf("\n"); 
  printf(" Employee Numbers :"); 
  puts(gerengongzi[i].num); 
  printf(" The worker's name :"); 
  puts(gerengongzi[i].name); 
  printf(" Labor wages :"); 
  printf("%f\n",gerengongzi[i].zhiwugongzi); 
  printf(" Labor benefits :"); 
  printf("%f\n",gerengongzi[i].zhiwubutie); 
  printf(" Housing subsidies :"); 
  printf("%f\n",gerengongzi[i].zhufangbutie); 
  printf(" Should pay :"); 
  printf("%f\n",gerengongzi[i].yingfagongzi); 
  printf(" Individual income tax :"); 
  printf("%f\n",gerengongzi[i].gerensuodeshui); 
  printf(" Endowment insurance :"); 
  printf("%f\n",gerengongzi[i].yanglaobaoxian); 
  printf(" Housing accumulation fund :"); 
  printf("%f\n",gerengongzi[i].zhufanggongjijin); 
  printf(" Real wages :"); 
  printf("%f\n",gerengongzi[i].shifagongzi); 
} 
//=============================================== 
void cxgerenxinxi(int bn)// The query  
{ 
  int select; 
  while(1) 
  { printf("\n Please enter the number before the operation \n"); 
  printf("1. Number query \n"); 
  printf("2. Search by name \n"); 
  printf("3. Query by Title \n"); 
  printf("0. Exit the query \n"); 
  scanf("%d",&select); 
  getchar(); 
  switch(select) 
  { 
   case 1: 
    cxnum(bn); 
    break; 
   case 2: 
    cxname(bn); 
    break; 
   case 3: 
    cxzhicheng(bn); 
    break; 
   case 0: 
   return; 
   default:printf("\n Button error, please select again \n"); 
   } 
  } 
} 
 
 
//============================================== 
void cxnum(int bn) 
{ 
  int i; 
  char number[20],c='y'; 
  while(c=='y') 
  { 
  printf("\n Please enter the employee number :"); 
  gets(number); 
  for(i=0;i<bn;i++) 
   if(strcmp(gerenxinxi[i].num,number)==0) 
   { 
    printf("\n The worker %d The information of :\n"); 
    putonegerenxinxi(i); 
    printf("\n Press any key to continue !\n"); 
    getch(); 
   } 
   if(i==bn) 
   printf("\n No employee information was found \n"); 
   return; 
   
  } 
  
  printf("\n Press any key to continue the query! \n"); 
  getchar(); 
} 
//================================================ 
void cxzhicheng(int bn) 
{ 
  int i; 
  char zhicheng[20],c='y'; 
  while(c=='y') 
  { 
  printf("\n Please enter employee title :"); 
  gets(zhicheng); 
  for(i=0;i<bn;i++) 
   if(strcmp(gerenxinxi[i].zhicheng,zhicheng)==0) 
   { 
    printf("\n Employee information :\n"); 
    putonegerenxinxi(i); 
    printf("\n Press any key to continue !\n"); 
    getch(); 
   } 
   if(i==bn) 
   { printf("\n No employee information was found \n"); 
    return ; 
   } 
  } 
  
  printf("\n Press any key to continue the query! \n"); 
  getchar(); 
 
} 
//============================================== 
 
void cxname(int bn)// Name query  
{ 
  int i,j,k; 
  char name[12],c='y'; 
  while(c=='y') 
  { 
   k=-1; 
  printf("\n Please enter the employee's name :"); 
  gets(name); 
  for(i=0,j=1;i<bn;i++) 
   if(strcmp(gerenxinxi[i].name,name)==0) 
   { printf("\n It is currently an accurate query \n"); 
    k=i; 
    printf("\n The worker %d The information of :\n",j++); 
    putonegerenxinxi(k); 
    printf("\n Press any key to continue !\n"); 
    getch(); 
   } 
  if(k==-1) 
  { 
   printf("\n It is currently a fuzzy query \n"); 
   for(i=0,j=1;i<bn;i++) 
    if(strstr(gerenxinxi[i].name,name)!=NULL) 
    { 
     k=i; 
     printf("\n The worker %d The information of :\n",j++); 
     putonegerenxinxi(k); 
     printf("\n Press any key to continue !\n"); 
     getch(); 
    } 
   if(j==1) 
    printf("\n No employee information was found !\n"); 
   return; 
  } 
   
  } 
  printf("\n Press any key to continue !\n"); 
  getchar(); 
} 
 
//================================================= 
void tongjigongzixinxi(int bn)// Statistical salary information  
{ 
 int select; 
 while(1) 
 { 
  printf(" Please enter the number before the operation \n"); 
  printf(" 1. The number of employees in various positions \n"); 
  printf(" 2. The average take-home pay of employees \n"); 
  printf(" 3. The number of people earning less than the average wage \n"); 
  printf(" 0. Exit statistics \n"); 
  
  scanf("%d",&select); getchar(); 
  switch(select) 
  { case 1:gangweirenshu(bn); break; 
   case 2:avegongzi(bn); break; 
   case 3:lowgongzi(bn); break; 
   case 0:return; 
   default: printf("\n Button error, please select again !\n"); 
  } 
  return; 
 
 
 } 
}  
//================================================= 
void gangweirenshu(int bn)// The worker number  
{ int i,j=0, k=0, m=0; 
 float ave; 
 for(i=0;i<bn;i++) 
 { if(strcmp(gerenxinxi[i].zhicheng ," Assistant engineer ")==0) 
  j++; 
  if(strcmp(gerenxinxi[i].zhicheng ," The engineer ")==0) 
  k++; 
  if(strcmp(gerenxinxi[i].zhicheng ," Senior Engineer ")==0) 
  m++; 
 } 
  ave=(m*1.0/bn); 
  printf(" The number of assistants is %d people \n",j); 
  printf(" Number of engineers: %d people \n",k); 
  printf(" The number of senior engineers is %d people \n",m); 
  printf(" The ratio of senior engineers is %f\n",ave); 
} 
//================================================== 
float avegongzi(int bn)// The average salary  
{ 
 int i; 
 float sum=0; 
 float ave; 
 for(i=0;i<bn;i++) 
 sum=sum+gerengongzi[i].shifagongzi; 
 ave=(sum/bn); 
 printf(" The average take-home pay of the staff is :%f\n",ave); 
 return(ave); 
 return(0); 
} 
//================================ 
void lowgongzi(int bn)// Below average wages  
{ int i,k=0; 
 float b; 
 b=avegongzi(bn); 
 for(i=0;i<bn;i++) 
 { 
  if(gerengongzi[i].shifagongzi<b) 
  { 
   k++; 
   printf(" Name: %s\n",gerengongzi[i].name); 
   printf(" Salary: %f\n",gerengongzi[i].shifagongzi); 
  } 
  
 } 
 printf(" The number of people earning less than the average wage is :%d\n",k); 
} 


Worked hard for more than a week, their first time to do so large procedures, encourage 1


Related articles: