TukoVPN

without cls

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