fork download
  1. //**************************************************************
  2. //
  3. // Assignment 9 - Linked Lists
  4. //
  5. // Name: John Semenuk
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 04/08/2026
  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.
  17. //**************************************************************
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #define MAX_NAME 20
  24. #define STD_HOURS 40
  25. #define OT_RATE 1.5
  26. #define FED_TAX_RATE 0.10
  27. #define MA_TAX_RATE 0.05
  28. #define NH_TAX_RATE 0.00
  29. #define VT_TAX_RATE 0.06
  30. #define CA_TAX_RATE 0.08
  31. #define DEFAULT_TAX_RATE 0.05
  32.  
  33. //**************************************************************
  34. // Structure definitions
  35. //**************************************************************
  36. struct name {
  37. char firstName[MAX_NAME];
  38. char lastName[MAX_NAME];
  39. };
  40.  
  41. struct employee {
  42. struct name empName;
  43. char taxState[3];
  44. long clockNumber;
  45. float wageRate;
  46. float hours;
  47. float overtimeHrs;
  48. float grossPay;
  49. float stateTax;
  50. float fedTax;
  51. float netPay;
  52. struct employee *next;
  53. };
  54.  
  55. struct totals {
  56. float total_wageRate;
  57. float total_hours;
  58. float total_overtimeHrs;
  59. float total_grossPay;
  60. float total_stateTax;
  61. float total_fedTax;
  62. float total_netPay;
  63. };
  64.  
  65. struct min_max {
  66. float min_wageRate, max_wageRate;
  67. float min_hours, max_hours;
  68. float min_overtimeHrs, max_overtimeHrs;
  69. float min_grossPay, max_grossPay;
  70. float min_stateTax, max_stateTax;
  71. float min_fedTax, max_fedTax;
  72. float min_netPay, max_netPay;
  73. };
  74.  
  75. //**************************************************************
  76. // Function prototypes
  77. //**************************************************************
  78. void getEmpData(struct employee *current_ptr);
  79. void calcOvertimeHrs(struct employee *head_ptr);
  80. void calcGrossPay(struct employee *head_ptr);
  81. void calcStateTax(struct employee *head_ptr);
  82. void calcFedTax(struct employee *head_ptr);
  83. void calcNetPay(struct employee *head_ptr);
  84. void calcEmployeeTotals(struct employee *head_ptr, struct totals *emp_totals_ptr);
  85. void calcEmployeeMinMax(struct employee *head_ptr, struct min_max *emp_minMax_ptr);
  86. void printEmpReport(struct employee *head_ptr);
  87. void printEmpStatistics(struct totals *emp_totals_ptr, struct min_max *emp_minMax_ptr);
  88.  
  89. int main() {
  90. //**************************************************************
  91. // Create linked list of employees
  92. //**************************************************************
  93. int numEmployees = 5;
  94. struct employee *head = NULL, *current = NULL, *prev = NULL;
  95.  
  96. for (int i = 0; i < numEmployees; i++) {
  97. current = malloc(sizeof(struct employee));
  98. if (!current) { printf("Memory allocation failed\n"); return 1; }
  99. current->next = NULL;
  100.  
  101. getEmpData(current);
  102.  
  103. if (!head) head = current;
  104. if (prev) prev->next = current;
  105. prev = current;
  106. }
  107.  
  108. //**************************************************************
  109. // Pointers to totals and min_max structures
  110. //**************************************************************
  111. struct totals employeeTotals = {0};
  112. struct totals *emp_totals_ptr = &employeeTotals;
  113.  
  114. struct min_max employeeMinMax;
  115. struct min_max *emp_minMax_ptr = &employeeMinMax;
  116.  
  117. //**************************************************************
  118. // Perform calculations
  119. //**************************************************************
  120. calcOvertimeHrs(head);
  121. calcGrossPay(head);
  122. calcStateTax(head);
  123. calcFedTax(head);
  124. calcNetPay(head);
  125. calcEmployeeTotals(head, emp_totals_ptr);
  126. calcEmployeeMinMax(head, emp_minMax_ptr);
  127.  
  128. //**************************************************************
  129. // Print report and statistics
  130. //**************************************************************
  131. printEmpReport(head);
  132. printEmpStatistics(emp_totals_ptr, emp_minMax_ptr);
  133.  
  134. //**************************************************************
  135. // Free allocated memory
  136. //**************************************************************
  137. current = head;
  138. struct employee *next;
  139. while (current) {
  140. next = current->next;
  141. free(current);
  142. current = next;
  143. }
  144.  
  145. return 0;
  146. }
  147.  
  148. //**************************************************************
  149. // Get employee data
  150. //**************************************************************
  151. void getEmpData(struct employee *current_ptr) {
  152. char answer[3];
  153.  
  154. printf("Enter first name: ");
  155. (void) scanf("%s", current_ptr->empName.firstName);
  156.  
  157. printf("Enter last name: ");
  158. (void) scanf("%s", current_ptr->empName.lastName);
  159.  
  160. printf("Enter tax state (MA/NH/VT/CA): ");
  161. (void) scanf("%s", current_ptr->taxState);
  162.  
  163. printf("Enter clock number: ");
  164. (void) scanf("%li", &current_ptr->clockNumber);
  165.  
  166. printf("Enter wage rate: ");
  167. (void) scanf("%f", &current_ptr->wageRate);
  168.  
  169. printf("Enter hours worked: ");
  170. (void) scanf("%f", &current_ptr->hours);
  171.  
  172. printf("\n");
  173. }
  174.  
  175. //**************************************************************
  176. // Calculations
  177. //**************************************************************
  178. void calcOvertimeHrs(struct employee *head_ptr) {
  179. struct employee *current_ptr;
  180. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
  181. current_ptr->overtimeHrs = 0.0;
  182. if (current_ptr->hours > STD_HOURS)
  183. current_ptr->overtimeHrs = current_ptr->hours - STD_HOURS;
  184. }
  185. }
  186.  
  187. void calcGrossPay(struct employee *head_ptr) {
  188. struct employee *current_ptr;
  189. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
  190. float regularHours = current_ptr->hours;
  191. if (regularHours > STD_HOURS) regularHours = STD_HOURS;
  192. current_ptr->grossPay = regularHours * current_ptr->wageRate
  193. + current_ptr->overtimeHrs * current_ptr->wageRate * OT_RATE;
  194. }
  195. }
  196.  
  197. void calcStateTax(struct employee *head_ptr) {
  198. struct employee *current_ptr;
  199. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
  200. if (strcmp(current_ptr->taxState,"MA")==0) current_ptr->stateTax = current_ptr->grossPay * MA_TAX_RATE;
  201. else if (strcmp(current_ptr->taxState,"NH")==0) current_ptr->stateTax = current_ptr->grossPay * NH_TAX_RATE;
  202. else if (strcmp(current_ptr->taxState,"VT")==0) current_ptr->stateTax = current_ptr->grossPay * VT_TAX_RATE;
  203. else if (strcmp(current_ptr->taxState,"CA")==0) current_ptr->stateTax = current_ptr->grossPay * CA_TAX_RATE;
  204. else current_ptr->stateTax = current_ptr->grossPay * DEFAULT_TAX_RATE;
  205. }
  206. }
  207.  
  208. void calcFedTax(struct employee *head_ptr) {
  209. struct employee *current_ptr;
  210. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  211. current_ptr->fedTax = current_ptr->grossPay * FED_TAX_RATE;
  212. }
  213.  
  214. void calcNetPay(struct employee *head_ptr) {
  215. struct employee *current_ptr;
  216. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  217. current_ptr->netPay = current_ptr->grossPay - current_ptr->stateTax - current_ptr->fedTax;
  218. }
  219.  
  220. void calcEmployeeTotals(struct employee *head_ptr, struct totals *emp_totals_ptr) {
  221. struct employee *current_ptr;
  222. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
  223. emp_totals_ptr->total_wageRate += current_ptr->wageRate;
  224. emp_totals_ptr->total_hours += current_ptr->hours;
  225. emp_totals_ptr->total_overtimeHrs += current_ptr->overtimeHrs;
  226. emp_totals_ptr->total_grossPay += current_ptr->grossPay;
  227. emp_totals_ptr->total_stateTax += current_ptr->stateTax;
  228. emp_totals_ptr->total_fedTax += current_ptr->fedTax;
  229. emp_totals_ptr->total_netPay += current_ptr->netPay;
  230. }
  231. }
  232.  
  233. void calcEmployeeMinMax(struct employee *head_ptr, struct min_max *emp_minMax_ptr) {
  234. struct employee *current_ptr = head_ptr;
  235. if (!current_ptr) return;
  236.  
  237. emp_minMax_ptr->min_wageRate = emp_minMax_ptr->max_wageRate = current_ptr->wageRate;
  238. emp_minMax_ptr->min_hours = emp_minMax_ptr->max_hours = current_ptr->hours;
  239. emp_minMax_ptr->min_overtimeHrs = emp_minMax_ptr->max_overtimeHrs = current_ptr->overtimeHrs;
  240. emp_minMax_ptr->min_grossPay = emp_minMax_ptr->max_grossPay = current_ptr->grossPay;
  241. emp_minMax_ptr->min_stateTax = emp_minMax_ptr->max_stateTax = current_ptr->stateTax;
  242. emp_minMax_ptr->min_fedTax = emp_minMax_ptr->max_fedTax = current_ptr->fedTax;
  243. emp_minMax_ptr->min_netPay = emp_minMax_ptr->max_netPay = current_ptr->netPay;
  244.  
  245. for (current_ptr = current_ptr->next; current_ptr; current_ptr = current_ptr->next) {
  246. if (current_ptr->wageRate < emp_minMax_ptr->min_wageRate) emp_minMax_ptr->min_wageRate = current_ptr->wageRate;
  247. if (current_ptr->wageRate > emp_minMax_ptr->max_wageRate) emp_minMax_ptr->max_wageRate = current_ptr->wageRate;
  248. if (current_ptr->hours < emp_minMax_ptr->min_hours) emp_minMax_ptr->min_hours = current_ptr->hours;
  249. if (current_ptr->hours > emp_minMax_ptr->max_hours) emp_minMax_ptr->max_hours = current_ptr->hours;
  250. if (current_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs) emp_minMax_ptr->min_overtimeHrs = current_ptr->overtimeHrs;
  251. if (current_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs) emp_minMax_ptr->max_overtimeHrs = current_ptr->overtimeHrs;
  252. if (current_ptr->grossPay < emp_minMax_ptr->min_grossPay) emp_minMax_ptr->min_grossPay = current_ptr->grossPay;
  253. if (current_ptr->grossPay > emp_minMax_ptr->max_grossPay) emp_minMax_ptr->max_grossPay = current_ptr->grossPay;
  254. if (current_ptr->stateTax < emp_minMax_ptr->min_stateTax) emp_minMax_ptr->min_stateTax = current_ptr->stateTax;
  255. if (current_ptr->stateTax > emp_minMax_ptr->max_stateTax) emp_minMax_ptr->max_stateTax = current_ptr->stateTax;
  256. if (current_ptr->fedTax < emp_minMax_ptr->min_fedTax) emp_minMax_ptr->min_fedTax = current_ptr->fedTax;
  257. if (current_ptr->fedTax > emp_minMax_ptr->max_fedTax) emp_minMax_ptr->max_fedTax = current_ptr->fedTax;
  258. if (current_ptr->netPay < emp_minMax_ptr->min_netPay) emp_minMax_ptr->min_netPay = current_ptr->netPay;
  259. if (current_ptr->netPay > emp_minMax_ptr->max_netPay) emp_minMax_ptr->max_netPay = current_ptr->netPay;
  260. }
  261. }
  262.  
  263. //**************************************************************
  264. // Print employee report
  265. //**************************************************************
  266. void printEmpReport(struct employee *head_ptr) {
  267. struct employee *current_ptr;
  268. printf("\nEmployee Payroll Report\n");
  269. printf("----------------------------------------------------------\n");
  270. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
  271. printf("%s %s | Net Pay: $%.2f\n",
  272. current_ptr->empName.firstName,
  273. current_ptr->empName.lastName,
  274. current_ptr->netPay);
  275. }
  276. }
  277.  
  278. //**************************************************************
  279. // Print totals and min/max statistics
  280. //**************************************************************
  281. void printEmpStatistics(struct totals *emp_totals_ptr, struct min_max *emp_minMax_ptr) {
  282. printf("\nEmployee Totals and Statistics\n");
  283. printf("----------------------------------------------------------\n");
  284. printf("Total Gross Pay: $%.2f\n", emp_totals_ptr->total_grossPay);
  285. printf("Min Gross Pay: $%.2f | Max Gross Pay: $%.2f\n", emp_minMax_ptr->min_grossPay, emp_minMax_ptr->max_grossPay);
  286. }
Success #stdin #stdout 0s 5324KB
stdin
Connie
Cobol
MA
98401
10.60
51.0
Y
Mary
Apl
NH
526488
9.75
42.5
Y
Frank
Fortran
VT
765349
10.50
37.0
Y
Jeff
Ada
NY
34645
12.25
45
Y
Anton
Pascal
CA
127615
8.35
40.0
N
stdout
Enter first name: Enter last name: Enter tax state (MA/NH/VT/CA): Enter clock number: Enter wage rate: Enter hours worked: 
Enter first name: Enter last name: Enter tax state (MA/NH/VT/CA): Enter clock number: Enter wage rate: Enter hours worked: 
Enter first name: Enter last name: Enter tax state (MA/NH/VT/CA): Enter clock number: Enter wage rate: Enter hours worked: 
Enter first name: Enter last name: Enter tax state (MA/NH/VT/CA): Enter clock number: Enter wage rate: Enter hours worked: 
Enter first name: Enter last name: Enter tax state (MA/NH/VT/CA): Enter clock number: Enter wage rate: Enter hours worked: 

Employee Payroll Report
----------------------------------------------------------
Connie Cobol | Net Pay: $509.07
Y Mary | Net Pay: $0.00
9.75 42.5 | Net Pay: $0.00
Frank Fortran | Net Pay: $326.34
Y Jeff | Net Pay: $0.00

Employee Totals and Statistics
----------------------------------------------------------
Total Gross Pay: $987.40
Min Gross Pay: $0.00 | Max Gross Pay: $598.90