fork download
  1. //********************************************************
  2. //
  3. // Assignment 10 - Linked Lists, Typedef, and Macros
  4. //
  5. // Name: John Semenuk
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: April 20, 2026
  10. //
  11. //********************************************************
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. #include <stdlib.h>
  17.  
  18. #define STD_HOURS 40.0
  19. #define OT_RATE 1.5
  20.  
  21. #define MA_TAX_RATE 0.05
  22. #define NH_TAX_RATE 0.0
  23. #define VT_TAX_RATE 0.06
  24. #define CA_TAX_RATE 0.07
  25. #define DEFAULT_STATE_TAX_RATE 0.08
  26.  
  27. #define FED_TAX_RATE 0.25
  28.  
  29. #define FIRST_NAME_SIZE 10
  30. #define LAST_NAME_SIZE 10
  31. #define TAX_STATE_SIZE 3
  32.  
  33. // ================= MACROS =================
  34.  
  35. #define CALC_OT_HOURS(theHours) ((theHours > STD_HOURS) ? theHours - STD_HOURS : 0)
  36.  
  37. #define CALC_STATE_TAX(thePay,theRate) (thePay * theRate)
  38.  
  39. #define CALC_FED_TAX(thePay) (thePay * FED_TAX_RATE)
  40.  
  41. #define CALC_NET_PAY(thePay,theStateTax,theFedTax) \
  42. (thePay - (theStateTax + theFedTax))
  43.  
  44. #define CALC_NORMAL_PAY(rate,hours,ot) \
  45. (rate * (hours - ot))
  46.  
  47. #define CALC_OT_PAY(rate,ot) \
  48. (ot * (OT_RATE * rate))
  49.  
  50. #define CALC_MIN(value,currentMin) ((value < currentMin) ? value : currentMin)
  51.  
  52. #define CALC_MAX(value,currentMax) ((value > currentMax) ? value : currentMax)
  53.  
  54. // ================= STRUCTS =================
  55.  
  56. struct name {
  57. char firstName[FIRST_NAME_SIZE];
  58. char lastName[LAST_NAME_SIZE];
  59. };
  60.  
  61. typedef struct employee {
  62. struct name empName;
  63. char taxState[TAX_STATE_SIZE];
  64. long clockNumber;
  65. float wageRate;
  66. float hours;
  67. float overtimeHrs;
  68. float grossPay;
  69. float stateTax;
  70. float fedTax;
  71. float netPay;
  72. struct employee *next;
  73. } EMPLOYEE;
  74.  
  75. typedef struct totals {
  76. float total_wageRate;
  77. float total_hours;
  78. float total_overtimeHrs;
  79. float total_grossPay;
  80. float total_stateTax;
  81. float total_fedTax;
  82. float total_netPay;
  83. } TOTALS;
  84.  
  85. typedef struct min_max {
  86. float min_wageRate;
  87. float min_hours;
  88. float min_overtimeHrs;
  89. float min_grossPay;
  90. float min_stateTax;
  91. float min_fedTax;
  92. float min_netPay;
  93.  
  94. float max_wageRate;
  95. float max_hours;
  96. float max_overtimeHrs;
  97. float max_grossPay;
  98. float max_stateTax;
  99. float max_fedTax;
  100. float max_netPay;
  101. } MIN_MAX;
  102.  
  103. // ================= PROTOTYPES =================
  104.  
  105. EMPLOYEE * getEmpData(void);
  106. int isEmployeeSize(EMPLOYEE *head_ptr);
  107. void calcOvertimeHrs(EMPLOYEE *head_ptr);
  108. void calcGrossPay(EMPLOYEE *head_ptr);
  109. void calcStateTax(EMPLOYEE *head_ptr);
  110. void calcFedTax(EMPLOYEE *head_ptr);
  111. void calcNetPay(EMPLOYEE *head_ptr);
  112. void calcEmployeeTotals(EMPLOYEE *head_ptr, TOTALS *totals);
  113. void calcEmployeeMinMax(EMPLOYEE *head_ptr, MIN_MAX *minmax);
  114. void printHeader(void);
  115. void printEmp(EMPLOYEE *head_ptr);
  116. void printEmpStatistics(TOTALS *totals, MIN_MAX *minmax, int size);
  117.  
  118. // ================= MAIN =================
  119.  
  120. int main() {
  121.  
  122. EMPLOYEE *head_ptr;
  123. int size;
  124.  
  125. TOTALS totals = {0};
  126. MIN_MAX minmax;
  127.  
  128. head_ptr = getEmpData();
  129. size = isEmployeeSize(head_ptr);
  130.  
  131. if (size <= 0) {
  132. printf("\nNo employees to process\n");
  133. return 0;
  134. }
  135.  
  136. calcOvertimeHrs(head_ptr);
  137. calcGrossPay(head_ptr);
  138. calcStateTax(head_ptr);
  139. calcFedTax(head_ptr);
  140. calcNetPay(head_ptr);
  141.  
  142. calcEmployeeTotals(head_ptr, &totals);
  143. calcEmployeeMinMax(head_ptr, &minmax);
  144.  
  145. printHeader();
  146. printEmp(head_ptr);
  147. printEmpStatistics(&totals, &minmax, size);
  148.  
  149. printf("\n\n *** End of Program *** \n");
  150. return 0;
  151. }
  152.  
  153. // ================= FUNCTIONS =================
  154.  
  155. EMPLOYEE * getEmpData(void)
  156. {
  157. EMPLOYEE *head_ptr = malloc(sizeof(EMPLOYEE));
  158. EMPLOYEE *current_ptr = head_ptr;
  159.  
  160. char answer[10];
  161.  
  162. while (1)
  163. {
  164. printf("\nFirst name: ");
  165. scanf("%s", current_ptr->empName.firstName);
  166.  
  167. printf("Last name: ");
  168. scanf("%s", current_ptr->empName.lastName);
  169.  
  170. printf("State: ");
  171. scanf("%s", current_ptr->taxState);
  172.  
  173. printf("Clock #: ");
  174. scanf("%ld", &current_ptr->clockNumber);
  175.  
  176. printf("Wage: ");
  177. scanf("%f", &current_ptr->wageRate);
  178.  
  179. printf("Hours: ");
  180. scanf("%f", &current_ptr->hours);
  181.  
  182. printf("More employees? (y/n): ");
  183. scanf("%s", answer);
  184.  
  185. if (toupper(answer[0]) != 'Y') {
  186. current_ptr->next = NULL;
  187. break;
  188. }
  189.  
  190. current_ptr->next = malloc(sizeof(EMPLOYEE));
  191. current_ptr = current_ptr->next;
  192. }
  193.  
  194. return head_ptr;
  195. }
  196.  
  197. int isEmployeeSize(EMPLOYEE *head_ptr)
  198. {
  199. int count = 0;
  200.  
  201. while (head_ptr)
  202. {
  203. count++;
  204. head_ptr = head_ptr->next;
  205. }
  206.  
  207. return count;
  208. }
  209.  
  210. void calcOvertimeHrs(EMPLOYEE *head_ptr)
  211. {
  212. while (head_ptr)
  213. {
  214. head_ptr->overtimeHrs = CALC_OT_HOURS(head_ptr->hours);
  215. head_ptr = head_ptr->next;
  216. }
  217. }
  218.  
  219. void calcGrossPay(EMPLOYEE *head_ptr)
  220. {
  221. while (head_ptr)
  222. {
  223. float normal = CALC_NORMAL_PAY(head_ptr->wageRate, head_ptr->hours, head_ptr->overtimeHrs);
  224. float ot = CALC_OT_PAY(head_ptr->wageRate, head_ptr->overtimeHrs);
  225.  
  226. head_ptr->grossPay = normal + ot;
  227.  
  228. head_ptr = head_ptr->next;
  229. }
  230. }
  231.  
  232. void calcStateTax(EMPLOYEE *head_ptr)
  233. {
  234. while (head_ptr)
  235. {
  236. if (!strcmp(head_ptr->taxState, "MA"))
  237. head_ptr->stateTax = CALC_STATE_TAX(head_ptr->grossPay, MA_TAX_RATE);
  238. else if (!strcmp(head_ptr->taxState, "NH"))
  239. head_ptr->stateTax = CALC_STATE_TAX(head_ptr->grossPay, NH_TAX_RATE);
  240. else if (!strcmp(head_ptr->taxState, "VT"))
  241. head_ptr->stateTax = CALC_STATE_TAX(head_ptr->grossPay, VT_TAX_RATE);
  242. else if (!strcmp(head_ptr->taxState, "CA"))
  243. head_ptr->stateTax = CALC_STATE_TAX(head_ptr->grossPay, CA_TAX_RATE);
  244. else
  245. head_ptr->stateTax = CALC_STATE_TAX(head_ptr->grossPay, DEFAULT_STATE_TAX_RATE);
  246.  
  247. head_ptr = head_ptr->next;
  248. }
  249. }
  250.  
  251. void calcFedTax(EMPLOYEE *head_ptr)
  252. {
  253. while (head_ptr)
  254. {
  255. head_ptr->fedTax = CALC_FED_TAX(head_ptr->grossPay);
  256. head_ptr = head_ptr->next;
  257. }
  258. }
  259.  
  260. void calcNetPay(EMPLOYEE *head_ptr)
  261. {
  262. while (head_ptr)
  263. {
  264. head_ptr->netPay = CALC_NET_PAY(head_ptr->grossPay,
  265. head_ptr->stateTax,
  266. head_ptr->fedTax);
  267. head_ptr = head_ptr->next;
  268. }
  269. }
  270.  
  271. void calcEmployeeTotals(EMPLOYEE *head_ptr, TOTALS *t)
  272. {
  273. while (head_ptr)
  274. {
  275. t->total_wageRate += head_ptr->wageRate;
  276. t->total_hours += head_ptr->hours;
  277. t->total_overtimeHrs += head_ptr->overtimeHrs;
  278. t->total_grossPay += head_ptr->grossPay;
  279. t->total_stateTax += head_ptr->stateTax;
  280. t->total_fedTax += head_ptr->fedTax;
  281. t->total_netPay += head_ptr->netPay;
  282.  
  283. head_ptr = head_ptr->next;
  284. }
  285. }
  286.  
  287. void calcEmployeeMinMax(EMPLOYEE *head_ptr, MIN_MAX *m)
  288. {
  289. EMPLOYEE *current = head_ptr;
  290.  
  291. *m = (MIN_MAX){
  292. current->wageRate, current->hours, current->overtimeHrs,
  293. current->grossPay, current->stateTax, current->fedTax, current->netPay,
  294. current->wageRate, current->hours, current->overtimeHrs,
  295. current->grossPay, current->stateTax, current->fedTax, current->netPay
  296. };
  297.  
  298. current = current->next;
  299.  
  300. while (current)
  301. {
  302. m->min_wageRate = CALC_MIN(current->wageRate, m->min_wageRate);
  303. m->max_wageRate = CALC_MAX(current->wageRate, m->max_wageRate);
  304.  
  305. m->min_hours = CALC_MIN(current->hours, m->min_hours);
  306. m->max_hours = CALC_MAX(current->hours, m->max_hours);
  307.  
  308. m->min_overtimeHrs = CALC_MIN(current->overtimeHrs, m->min_overtimeHrs);
  309. m->max_overtimeHrs = CALC_MAX(current->overtimeHrs, m->max_overtimeHrs);
  310.  
  311. m->min_grossPay = CALC_MIN(current->grossPay, m->min_grossPay);
  312. m->max_grossPay = CALC_MAX(current->grossPay, m->max_grossPay);
  313.  
  314. m->min_stateTax = CALC_MIN(current->stateTax, m->min_stateTax);
  315. m->max_stateTax = CALC_MAX(current->stateTax, m->max_stateTax);
  316.  
  317. m->min_fedTax = CALC_MIN(current->fedTax, m->min_fedTax);
  318. m->max_fedTax = CALC_MAX(current->fedTax, m->max_fedTax);
  319.  
  320. m->min_netPay = CALC_MIN(current->netPay, m->min_netPay);
  321. m->max_netPay = CALC_MAX(current->netPay, m->max_netPay);
  322.  
  323. current = current->next;
  324. }
  325. }
  326.  
  327. void printHeader(void)
  328. {
  329. printf("\n*** Pay Calculator ***\n");
  330. }
  331.  
  332. void printEmp(EMPLOYEE *head_ptr)
  333. {
  334. while (head_ptr)
  335. {
  336. printf("\n%-10s %-10s %ld %.2f %.1f %.1f %.2f %.2f %.2f %.2f",
  337. head_ptr->empName.firstName,
  338. head_ptr->empName.lastName,
  339. head_ptr->clockNumber,
  340. head_ptr->wageRate,
  341. head_ptr->hours,
  342. head_ptr->overtimeHrs,
  343. head_ptr->grossPay,
  344. head_ptr->stateTax,
  345. head_ptr->fedTax,
  346. head_ptr->netPay);
  347.  
  348. head_ptr = head_ptr->next;
  349. }
  350. }
  351.  
  352. void printEmpStatistics(TOTALS *t, MIN_MAX *m, int size)
  353. {
  354. printf("\n\nTotals Gross: %.2f", t->total_grossPay);
  355. printf("\nAverage Gross: %.2f", t->total_grossPay / size);
  356.  
  357. printf("\nMin Gross: %.2f", m->min_grossPay);
  358. printf("\nMax Gross: %.2f", m->max_grossPay);
  359. }
  360.  
Success #stdin #stdout 0s 5296KB
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
First name: Last name: State: Clock #: Wage: Hours: More employees? (y/n): 
First name: Last name: State: Clock #: Wage: Hours: More employees? (y/n): 
First name: Last name: State: Clock #: Wage: Hours: More employees? (y/n): 
First name: Last name: State: Clock #: Wage: Hours: More employees? (y/n): 
First name: Last name: State: Clock #: Wage: Hours: More employees? (y/n): 
*** Pay Calculator ***

Connie     Cobol      98401 10.60 51.0 11.0 598.90 29.95 149.73 419.23
Mary       Apl        526488 9.75 42.5 2.5 426.56 0.00 106.64 319.92
Frank      Fortran    765349 10.50 37.0 0.0 388.50 23.31 97.12 268.07
Jeff       Ada        34645 12.25 45.0 5.0 581.88 46.55 145.47 389.86
Anton      Pascal     127615 8.35 40.0 0.0 334.00 23.38 83.50 227.12

Totals Gross: 2329.84
Average Gross: 465.97
Min Gross: 334.00
Max Gross: 598.90

 *** End of Program ***