C language staff performance sales source code

  • 2020-06-19 11:29:48
  • OfStack

This article shares the specific code of C language staff performance sales for your reference, the specific content is as follows


#include<stdio.h>
#include<string.h>
#include<conio.h>
#define N 100
struct sales
{  int num;
 char name[20];
 char sex[10];
 long int mon[4];
 long int total;
 long int aver;
}sa[N];
void showmenu();
void append();
void modify();
void display();
void search();
void del();
void line();
void save();
void add();
void read();
void main()
{ 
 int ch;
 showmenu();
  printf("\n The left digit corresponds to function selection, please select 0-9:");
  scanf("%d",&ch);
  while(ch>=0&&ch<=9)
  {
  switch(ch)
  { 
  case 0: append();break;
  case 1: modify();break;
    case 2: display();break;
  case 3: search();break;
    case 4: del();break;
  case 5: line();break;
  case 6: save();break;
  case 7: read();break;
  case 8: add();break;
  case 9: exit(0);break;
      default :break;
  }
 showmenu();
  printf("\n The left digit corresponds to function selection, please select 0-9:");
   scanf("%d",&ch); 
}
}
  void append() /* The new file */
  { 
    int n;
  int i,j; 
    printf(" There was no record before and now a new table is created ");
  printf("\n Please be sure to add a few pieces of information :");
  scanf("%d",&n);
   for(i=0;i<n;i++)
   { printf(" The first %d employee \n",i+1);
   printf("\n Please enter your name :");
    scanf("%s",&sa[i].name);
   printf("\n Please enter gender < male :man female :woman>:");
   scanf("%s",&sa[i].sex);
   for(j=0;j<4;j++)
   { printf("\n Please enter the %d Quarterly results :",j+1);
   scanf("%d",&sa[i].mon[j]);
         }
        sa[i].total=sa[i].mon[0]+sa[i].mon[1]+sa[i].mon[2]+sa[i].mon[3];
  sa[i].aver=sa[i].total/4;
   }
   for(i=0;i<n-1;i++)
   {if(sa[i].total>sa[i+1].total)
   sa[i].num=i+1;}
  } 
   
void modify()/* Modification of employee performance */
{ int d,i,num;
  char name[20];
 printf(" Please enter how to find the way to modify the record: ");
 printf("\n1. According to the name ");
  printf("\n2. According to the ranking \n");
  scanf("%d",&d);
  if(d==1)
  { printf(" Please enter the employee's name :");
    scanf("%s",&name);
    for(i=0;i<N;i++)
   { if(strcmp(sa[i].name,name)==0)
   { printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
      printf("%s  %s  %d  %d  %d  %d  %d  %d   %d",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
   printf("\n Please re-enter the employee information below :");
   printf("\n Please enter your name :");
    scanf("%s",&sa[i].name);
   printf("\n Please enter gender < male :man, female :woman>:");
   scanf("%s",&sa[i].sex);
          printf("\n Please enter the 1 Quarterly results :");
   scanf("%d",&sa[i].mon[0]);
           printf("\n Please enter the 2 Quarterly results :");
   scanf("%d",&sa[i].mon[1]);
           printf("\n Please enter the 3 Quarterly results :");
   scanf("%d",&sa[i].mon[2]);
           printf("\n Please enter the 4 Quarterly results :");
   scanf("%d",&sa[i].mon[3]);
   }
   }
  }
  if(d==2)
  { printf(" Please enter employee ranking :");
   scanf("%d",num);
   for(i=0;i<N;i++)
   { if(sa[i].num==num)
   { printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
      printf("%s  %s  %d  %d  %d  %d  %d  %d   %d",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
    printf("\n Please re-enter the employee information below :");
   printf("\n Please enter your name :");
    scanf("%s",&sa[i].name);
   printf("\n Please enter gender < male :man, female :woman>:");
   scanf("%s",&sa[i].sex);
          printf("\n Please enter the 1 Quarterly results :");
   scanf("%d",&sa[i].mon[0]);
           printf("\n Please enter the 2 Quarterly results :");
   scanf("%d",&sa[i].mon[1]);
           printf("\n Please enter the 3 Quarterly results :");
   scanf("%d",&sa[i].mon[2]);
           printf("\n Please enter the 4 Quarterly results :");
   scanf("%d",&sa[i].mon[3]);
   }
   } 
  }
}
void display()/* Display employee performance */
{ int i;
 int n=load();
 for(i=0;i<n;i++)
 { printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
      printf("%s  %s  %d  %d  %d  %d  %d  %d   %d",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
 }
}
void search()/* Query employee performance */
{ int n,i,num;
  char name[20];
 printf(" Please enter the search method: ");
 printf("\n1. According to the name ");
  printf("\n2. According to the ranking \n");
  scanf("%d",&n);
  if(n==1)
  { printf(" Please enter the employee's name :");
    scanf("%s",&name);
    for(i=0;i<N;i++)
   { if(strcmp(sa[i].name,name)==0)
   { printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
      printf("%s  %s  %d  %d  %d  %d  %d  %d   %d\n",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num); 
   }
   }
 }
  if(n==2)
  { printf(" Please enter employee ranking :");
   scanf("%d",num);
   for(i=0;i<N;i++)
   { if(sa[i].num==num)
   { printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
      printf("%s  %s  %d  %d  %d  %d  %d  %d   %d\n",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
   }
   }
 }
}
void del()/* Delete employee performance */
{ int m=load();
 int i,j,n,t,flag,num;
 char name[20],q;
 printf(" Please enter how to delete :\n");
   printf("\n1. According to the name ");
  printf("\n2. According to the ranking \n");
  scanf("%d",&n);
  if(n==1)
  { printf(" Please enter the name of the employee :");
   scanf("%s",&name);
    for(flag=1,i=0;flag&&i<m;i++) 
 { 
     if(strcmp(sa[i].name,name)==0) 
  {  printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
      printf("%s  %s  %d  %d  %d  %d  %d  %d   %d\n",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
      printf(" Be sure to delete the employee's information ?<y or n>");
  scanf("%c",&q);
  if(q=='y')
  {
   for(j=i;j<m-1;j++)
   {
   strcpy(sa[j].name,sa[j+1].name);
    strcpy(sa[j].sex,sa[j+1].sex);
    sa[j].mon[0]=sa[j+1].mon[0];
    sa[j].mon[1]=sa[j+1].mon[1];
     sa[j].mon[2]=sa[j+1].mon[2];
    sa[j].mon[3]=sa[j+1].mon[3];
    sa[j].total=sa[j+1].total;
    sa[j].aver=sa[j+1].aver;
   }
   flag=0;
  }
  }
 }
    if(!flag)
   m=m-1;
  else
   printf("\n No such person !\n");
  printf("\n Press to continue deletion 1 , please click in delete 0\n");
  scanf("%d",&t);
  switch(t)
  {
  case 1:del();break;
  case 0:break;
  default :break;
  }
  if(n==2)
    { printf(" Please enter the ranking of the employee :");
   scanf("%d",&num);
    for(flag=1,i=0;flag&&i<m;i++) 
 { 
     if(sa[i].num==num) 
  {  printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
      printf("%s  %s  %d  %d  %d  %d  %d  %d   %d\n",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
      printf(" Be sure to delete the employee's information ?<y or n>");
  scanf("%c",&q);
  if(q=='y')
  {
   for(j=i;j<m-1;j++)
   {
   strcpy(sa[j].name,sa[j+1].name);
    strcpy(sa[j].sex,sa[j+1].sex);
    sa[j].mon[0]=sa[j+1].mon[0];
    sa[j].mon[1]=sa[j+1].mon[1];
     sa[j].mon[2]=sa[j+1].mon[2];
    sa[j].mon[3]=sa[j+1].mon[3];
    sa[j].total=sa[j+1].total;
    sa[j].aver=sa[j+1].aver;
   }
   flag=0;
  }
  }
 }
    if(!flag)
   m=m-1;
  else
   printf("\n No such person !\n");
  printf("\n Press to continue deletion 1 , please click in delete 0\n");
  scanf("%d",&t);
  switch(t)
  {
  case 1:del();break;
  case 0:break;
  default :break;
  }
  }
  }
}
void save()/* Save the file */
{ int i;
 FILE *fp;
 if((fp=open("sales_list","wb"))==NULL)
 {
  printf("file write error\n");
  fclose(fp);
 }
}
 int load()
 {
  FILE *fp;
  int i=0;
  if((fp=fopen("sales_list","rb"))==NULL)
  {
  printf("cannot open file\n");
  exit(0);
  }
  else
  {
  do
  {
   fread(&sa[i],sizeof(struct sales),1,fp);
   i++;
  }
  while(feof(fp)==0);
  }
  fclose(fp);
  return(i-1);
 }
 void read()/* Read the information */
 {  FILE *fp;
  char ch;
   char filename[20];
  printf(" Enter file name \n");
  scanf("%s",&filename);
  if((fp=fopen("filename","r"))==NULL)
  {
  printf(" No information, press any key to return to main menu \n");
  exit(0);
  getch();
  }
  ch=fgetc(fp);
  while(ch!=EOF)
  {
  putchar(ch);
  ch=fgetc(fp);
  }
  fclose(fp);
 }
void add()/* Add records */
{
 FILE *fp;
 int n;
 int count=0;
 int i;
 int m=load();
 fp=fopen("sales_list","a");
 printf(" Adds information to the end of the current table \n");
 printf(" Please enter the number of employees added :\n");
   scanf("%d",&n);
 for(i=m;i<(m+n);i++)
 {
  printf(" Please enter the new employee information \n");
  printf(" The first %d employee \n",i);
  printf(" Please enter your name :");
    scanf("%s",&sa[i].name);
   printf("\n Please enter gender < male :man, female :woman>:");
   scanf("%s",&sa[i].sex);
          printf("\n Please enter the 1 Quarterly results :");
   scanf("%d",&sa[i].mon[0]);
           printf("\n Please enter the 2 Quarterly results :");
   scanf("%d",&sa[i].mon[1]);
           printf("\n Please enter the 3 Quarterly results :");
   scanf("%d",&sa[i].mon[2]);
           printf("\n Please enter the 4 Quarterly results :");
   scanf("%d",&sa[i].mon[3]);
   printf("\n");
   count=count+1;
   printf(" Has increased %d people \n",count);
 }
}
 void line()/* Sort the information */
 {
  int b,j,i,k,flag;
  int n=load();
  flag=0;
  printf(" Please enter how you would like to sort :\n");
  printf("1- In ascending order \n");
    printf("2- In descending order \n");
  scanf("%d",&k);
  if(k==1)
  { for(i=0;i<n;i++)
   for(j=i+1;j<n;j++)
    if(sa[i].num>sa[j].num)
    { b=sa[i].num;
     sa[i].num=sa[j].num;
   sa[j].num=b;
    }
          printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
    for(i=0;i<n;i++)
          printf("%s  %s  %d  %d  %d  %d  %d  %d   %d\n",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
  }
     if(k==2)
  { for(i=0;i<n;i++)
   for(j=i+1;j<n;j++)
    if(sa[i].num<sa[j].num)
    { b=sa[i].num;
     sa[i].num=sa[j].num;
   sa[j].num=b;
    }
          printf(" The name   gender  1 quarter  2 quarter  3 quarter  4 quarter   Total performance   On average,   ranking \n");
    for(i=0;i<n;i++)
          printf("%s  %s  %d  %d  %d  %d  %d  %d   %d\n",sa[i].name,sa[i].sex,sa[i].mon[0],sa[i].mon[1],sa[i].mon[2],sa[i].mon[3],sa[i].total,sa[i].aver,sa[i].num);
  }
 }
void showmenu()
{
 printf("  |------------------------------------------------|\n");
 printf("  |        Welcome to use our industrial process performance management      |\n");
  printf("  |------------------------------------------------|\n");
 printf("\n");
 printf("\n  |----------------------------------------|\n");
  printf("  |       0- The new file          |\n");
  printf("  |       1- Modification of employee performance        |\n");
  printf("  |       2- Display employee performance        |\n");
  printf("  |       3- Query employee performance        |\n");
  printf("  |       4- Delete employee performance        |\n");
  printf("  |       5- Rank employee performance information   |\n");
  printf("  |       6- Save the file          |\n");
  printf("  |       7- Read the information          |\n");
  printf("  |       8- Add records          |\n");
  printf("  |       9- End of run          |\n");
}

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


Related articles: