Advertisement
TukoVPN

Working employee

Dec 5th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /* structure to store employee salary details */
  6. struct employee {
  7. int empId;
  8. char name[32];
  9. int basic, bonus;
  10. int absent, salaryDeduc;
  11. float gross, net;
  12. };
  13.  
  14. /* prints payslip for the requested employee */
  15. void printSalary(struct employee e1) {
  16. printf("Salary Slip of %s:\n", e1.name);
  17. printf("Employee ID: %d\n", e1.empId);
  18. printf("Basic Salary: %d\n", e1.basic);
  19. printf("Bonus: %d\n", e1.bonus);
  20. printf("Gross Salary: %.2f PHP\n", e1.gross);
  21.  
  22. printf("\nDeductions: \n");
  23. printf("Absent: %d\n", e1.absent);
  24. printf("Salary Deduction: %d\n", e1.salaryDeduc);
  25. printf("\nNet Salary: %.2f PHP\n\n", e1.net);
  26. return;
  27. }
  28.  
  29. /* display all the employee records entered */
  30. void display(struct employee e1) {
  31. printf("%d \t %s \t %d \t %d \t %d \n", e1.empId, e1.name, e1.basic, e1.bonus, e1.absent);
  32. return;
  33. }
  34.  
  35. int main() {
  36. int i, ch, num, flag, empID;
  37. int choice;
  38. struct employee *e1;
  39.  
  40. /* get the number of employees from the user */
  41. printf("Enter the number of employees:");
  42. scanf("%d", &num);
  43.  
  44. /* dynamically allocate memory to store employee salary details */
  45. e1 = (struct employee *)malloc(sizeof(struct employee) * num);
  46.  
  47. /* get the employee salary details from the customer */
  48. printf("Enter your input for every employee:\n");
  49. for (i = 0; i < num; i++) {
  50. printf("Employee ID:");
  51. scanf("%d", &(e1[i].empId));
  52. getchar();
  53. printf("Employee Name:");
  54. fgets(e1[i].name, 32, stdin);
  55. e1[i].name[strlen(e1[i].name) - 1] = '\0';
  56. printf("Basic Salary:");
  57. scanf("%d", &(e1[i].basic));
  58. printf("Bonus:");
  59. scanf("%d", &(e1[i].bonus));
  60. printf("Enter the deductions: \n");
  61. printf("Absent:");
  62. scanf("%d", &(e1[i].absent));
  63. printf("\n");
  64. }
  65. /* printing payslip for the given employee ID */
  66. while (1) {
  67. printf("\n EMPLOYEE PAYROLL SYSTEM \n");
  68. printf("\n\n*****CHOOSE YOUR OPTION*****\n");
  69. printf("1) SHOW ALL RECORDS\n");
  70. printf("2) ADD NEW EMPLOYEE RECORD\n");
  71. printf("3) PRINT THE SALARY SLIP\n");
  72. printf("4) EXIT\n");
  73. printf("Enter your choice : ");
  74. scanf("%d", &choice);
  75.  
  76. if (choice != 5) {
  77. switch(choice){
  78. case 1 : /*printing all the records entered before printing the slip */
  79. printf("\nEmp. ID. Emp.Name \t Basic \t Bonus \t Absent \n") ;
  80.  
  81. for (i = 0; i < num; i++) {
  82. display(e1[i]);
  83. }
  84. break;
  85.  
  86. case 2 : /*adding a new member in the employee list created */
  87. num++;
  88. i = num-1;
  89. printf("Employee ID:");
  90. scanf("%d", &(e1[i].empId));
  91. getchar();
  92. printf("Employee Name:");
  93. fgets(e1[i].name, 32, stdin);
  94. e1[i].name[strlen(e1[i].name) - 1] = '\0';
  95. printf("Basic Salary:");
  96. scanf("%d", &(e1[i].basic));
  97. printf("Bonus:");
  98. scanf("%d", &(e1[i].bonus));
  99. printf("Enter the deductions:\n");
  100. printf("Absent:");
  101. scanf("%d", &(e1[i].absent));
  102. printf("\n");
  103. break;
  104.  
  105. case 3 : /* gross and net salary calculation */
  106. for (i = 0; i < num; i++) {
  107. e1[i].gross = e1[i].basic + e1[i].bonus;
  108. e1[i].salaryDeduc = (0.04 * e1[i].absent) * e1[i].basic;
  109. e1[i].net = e1[i].gross - e1[i].salaryDeduc;
  110. }
  111.  
  112. printf("Enter employee ID to get payslip:");
  113. scanf("%d", &empID);
  114.  
  115. flag = 0;
  116. for (i = 0; i < num; i++) {
  117. if (empID == e1[i].empId) {
  118. printSalary(e1[i]);
  119. flag = 1;
  120. }
  121. }
  122.  
  123. if (!flag) {
  124. printf("No Record Found!!\n");
  125. }
  126. break;
  127. case 4 : //printf("5");
  128. break;
  129.  
  130. default: printf("error");
  131. }
  132.  
  133. printf("\n Do You Want To Continue(1/0):");
  134. scanf("%d", &ch);
  135.  
  136. } else {
  137. ch = 0;
  138. }
  139.  
  140. if (!ch) {
  141. break;
  142. }
  143. }
  144. return 0;
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement