TukoVPN

Employee Payroll System

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