Advertisement
Mostafizur_Rahman

Employee_data

Jun 8th, 2021
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1. #include <stdio.h>
  2. int position =0;
  3. struct Employee
  4. {
  5.     char name[20], phoneNo[12];
  6.     float salary;
  7. };
  8. int main()
  9. {
  10.     int N;
  11.     char choice;
  12.      printf("Enter the size of the array : ");
  13.     scanf("%d", &N);
  14.     struct Employee e[N];
  15.  
  16.     printf("\n======= Office Pay Roll System =========\n");
  17.     printf("Enter 'x', to take information of all employee into the Employee structure array of size N.\n");
  18.     printf("Enter 'y', to find and display the info of employee with the highest salary.\n");
  19.     printf("Enter 'z', to display the information of employees with less than half of the highest salary in tabular format.\n");
  20.     printf("Enter 'q', to quit/exit the menu system\n");
  21.  
  22.     while (1)
  23.     {
  24.         getchar();
  25.         printf("\nEnter your choice: ");
  26.         scanf("%c", &choice);
  27.  
  28.         if (choice == 'q')
  29.             {printf("\nProcess end...\n");
  30.             break;}
  31.  
  32.         switch (choice)
  33.         {
  34.         case 'x':
  35.         {
  36.             takeEmployeesInfoFromKeyboard(e, N);
  37.             break;
  38.         }
  39.         case 'y':
  40.         {
  41.             findEmployeeWithHighestSalary(e, N);
  42.             break;
  43.         }
  44.         case 'z':
  45.  
  46.         {
  47.             displayAllEmployeesInfo(e, N);
  48.             break;
  49.         }
  50.  
  51.         default:
  52.         {
  53.             printf("Invalid Input. \n ");
  54.             break;
  55.         }
  56.         }
  57.     }
  58.     return 0;
  59. }
  60. void takeEmployeesInfoFromKeyboard(struct Employee e[], int n)
  61. {
  62.  
  63.     int i;
  64.     for (i = 0; i < n; i++)
  65.     {
  66.         printf("\n Employee no %d : ", i + 1);
  67.         printf("\n Enter name of employee - ");
  68.         scanf("%s", e[i].name);
  69.         printf(" Enter Phone No of employee - ");
  70.         scanf("%s", e[i].phoneNo);
  71.         printf(" Enter salary of employee - ");
  72.         scanf("%f", &e[i].salary);
  73.     }
  74. }
  75. void findEmployeeWithHighestSalary(struct Employee e[], int n)
  76. {
  77.     int i;
  78.     float Highest = e[0].salary;
  79.     printf("\n Employee with highest salary :");
  80.     for (i = 1; i < n; i++)
  81.     {
  82.         if (Highest < e[i].salary)
  83.         {
  84.             Highest = e[i].salary;
  85.             position = i;
  86.         }
  87.     }
  88.     printf("\n Name : %s\n Phone NO :%s\n Salary : %.2f\n", e[position].name, e[position].phoneNo, e[position].salary);
  89.  
  90. }
  91. void displayAllEmployeesInfo(struct Employee e[], int n )
  92. {
  93.     int i;
  94.     float half = e[position].salary/2;//position is globally declared.
  95.     printf("\n\n Employees’ information whose salary is less than half of the highest salary :");
  96.     printf("\n\n Employee Name      Employee Phone No     Salary\n");
  97.     for (i = 0; i < n; i++)
  98.     {
  99.         if (e[i].salary < half)
  100.         {
  101.             printf(" %s\t\t%s\t\t%.2f\n", e[i].name, e[i].phoneNo, e[i].salary);
  102.         }
  103.     }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement