fork download
  1. //********************************************************
  2. //
  3. // Assignment 9 - Linked Lists
  4. //
  5. // Name: Jacquelin Saint Lucien
  6. //
  7. // Class: C Programming, Falls 2025
  8. //
  9. // Date: 11/14/2025
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. // This assignment also adds the employee name, their tax state,
  16. // and calculates the state tax, federal tax, and net pay. It
  17. // also calculates totals, averages, minimum, and maximum values.
  18. //
  19. // Array and Structure references have all been replaced with
  20. // pointer references to speed up the processing of this code.
  21. // A linked list has been created and deployed to dynamically
  22. // allocate and process employees as needed.
  23. //
  24. // Call by Reference design (using pointers)
  25. //
  26. //********************************************************
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32.  
  33. typedef struct Employee {
  34. char firstName[20];
  35. char lastName[20];
  36. char state[5];
  37. int clockNumber;
  38. float wage;
  39. float hours;
  40.  
  41. float gross;
  42. float stateTax;
  43. float federalTax;
  44. float net;
  45.  
  46. struct Employee *next;
  47. } Employee;
  48.  
  49. /* ---- Function Prototypes ---- */
  50. Employee* addEmployee(Employee *head, char *fn, char *ln, char *st, int clk, float wage, float hrs);
  51. void calcStateTax(Employee *e);
  52. void calcFedTax(Employee *e);
  53. void calcEmployeeTotals(Employee *head, float *totGross, float *totState, float *totFed, float *totNet);
  54. void calcEmployeeMinMax(Employee *head);
  55. void printEmployees(Employee *head);
  56.  
  57. int main() {
  58. Employee *head = NULL;
  59.  
  60. /* Example input (replace with scanf or file input depending on assignment) */
  61. head = addEmployee(head, "Connie", "Bryant", "CA", 98401, 10.60, 38.00);
  62. head = addEmployee(head, "Mary", "Apl", "NY", 526488, 12.58, 40.00);
  63. head = addEmployee(head, "Frank", "Krotman", "VT", 954984, 10.50, 42.00);
  64. head = addEmployee(head, "Aida", "Pett", "CA", 125615, 17.00, 38.00);
  65. head = addEmployee(head, "Jason", "Pascal", "CA", 127615, 12.85, 45.00);
  66.  
  67. Employee *curr = head;
  68.  
  69. /* ---- Perform Calculations ---- */
  70. while (curr != NULL) {
  71. curr->gross = curr->wage * curr->hours;
  72.  
  73. calcStateTax(curr);
  74. calcFedTax(curr);
  75.  
  76. curr->net = curr->gross - curr->stateTax - curr->federalTax;
  77.  
  78. curr = curr->next;
  79. }
  80.  
  81. /* ---- Print Output ---- */
  82. printEmployees(head);
  83.  
  84. /* ---- Totals ---- */
  85. float tGross=0, tState=0, tFed=0, tNet=0;
  86. calcEmployeeTotals(head, &tGross, &tState, &tFed, &tNet);
  87.  
  88. printf("\nTotals:\n");
  89. printf("Gross: %.2f\nState Tax: %.2f\nFed Tax: %.2f\nNet: %.2f\n",
  90. tGross, tState, tFed, tNet);
  91.  
  92. /* ---- Min/Max Summary ---- */
  93. calcEmployeeMinMax(head);
  94.  
  95. return 0;
  96. }
  97.  
  98.  
  99. // ADD EMPLOYEE (DYNAMIC LINKED LIST)
  100.  
  101. Employee* addEmployee(Employee *head, char *fn, char *ln, char *st, int clk, float wage, float hrs) {
  102. Employee *e = (Employee*)malloc(sizeof(Employee));
  103.  
  104. strcpy(e->firstName, fn);
  105. strcpy(e->lastName, ln);
  106. strcpy(e->state, st);
  107. e->clockNumber = clk;
  108. e->wage = wage;
  109. e->hours = hrs;
  110.  
  111. e->next = head;
  112. return e;
  113. }
  114.  
  115.  
  116. // TAX CALCULATION FUNCTIONS
  117.  
  118.  
  119. /* Example: 6% state tax */
  120. void calcStateTax(Employee *e) {
  121. e->stateTax = e->gross * 0.06;
  122. }
  123.  
  124. /* Example: 12% federal tax */
  125. void calcFedTax(Employee *e) {
  126. e->federalTax = e->gross * 0.12;
  127. }
  128.  
  129.  
  130. //TOTALS (SUM OF ALL EMPLOYEES)
  131.  
  132. void calcEmployeeTotals(Employee *head, float *tGross, float *tState, float *tFed, float *tNet) {
  133. Employee *c = head;
  134.  
  135. while (c != NULL) {
  136. *tGross += c->gross;
  137. *tState += c->stateTax;
  138. *tFed += c->federalTax;
  139. *tNet += c->net;
  140. c = c->next;
  141. }
  142. }
  143.  
  144.  
  145. // MIN / MAX
  146.  
  147. void calcEmployeeMinMax(Employee *head) {
  148. if (head == NULL) return;
  149.  
  150. float minGross = head->gross, maxGross = head->gross;
  151. Employee *c = head;
  152.  
  153. while (c != NULL) {
  154. if (c->gross < minGross) minGross = c->gross;
  155. if (c->gross > maxGross) maxGross = c->gross;
  156. c = c->next;
  157. }
  158.  
  159. printf("\nMinimum Gross Pay: %.2f\n", minGross);
  160. printf("Maximum Gross Pay: %.2f\n", maxGross);
  161. }
  162.  
  163.  
  164. //RINT EMPLOYEES
  165.  
  166. void printEmployees(Employee *head) {
  167. printf("\n*** Pay Calculator ***\n");
  168. printf("%-10s %-10s %-8s %-8s %-10s %-10s %-10s %-10s\n",
  169. "First", "Last", "State", "Clock#",
  170. "Gross", "StateTax", "FedTax", "Net");
  171.  
  172. Employee *c = head;
  173. while (c != NULL) {
  174. printf("%-10s %-10s %-8s %-8d $%-10.2f $%-10.2f $%-10.2f $%-10.2f\n",
  175. c->firstName, c->lastName, c->state, c->clockNumber,
  176. c->gross, c->stateTax, c->federalTax, c->net);
  177. c = c->next;
  178. }
  179. }
  180.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
*** Pay Calculator ***
First      Last       State    Clock#   Gross      StateTax   FedTax     Net       
Jason      Pascal     CA       127615   $578.25     $34.69      $69.39      $474.16    
Aida       Pett       CA       125615   $646.00     $38.76      $77.52      $529.72    
Frank      Krotman    VT       954984   $441.00     $26.46      $52.92      $361.62    
Mary       Apl        NY       526488   $503.20     $30.19      $60.38      $412.62    
Connie     Bryant     CA       98401    $402.80     $24.17      $48.34      $330.30    

Totals:
Gross: 2571.25
State Tax: 154.27
Fed Tax: 308.55
Net: 2108.42

Minimum Gross Pay: 402.80
Maximum Gross Pay: 646.00