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. // 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. // Also calculates taxes, totals, averages, min, and max
  16. // using linked lists, pointers, and macros.
  17. //
  18. //********************************************************
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23. #include <stdlib.h>
  24.  
  25. #define STD_HOURS 40.0
  26. #define OT_RATE 1.5
  27.  
  28. #define MA_TAX_RATE 0.05
  29. #define NH_TAX_RATE 0.0
  30. #define VT_TAX_RATE 0.06
  31. #define CA_TAX_RATE 0.07
  32. #define DEFAULT_STATE_TAX_RATE 0.08
  33.  
  34. #define FED_TAX_RATE 0.25
  35.  
  36. #define FIRST_NAME_SIZE 10
  37. #define LAST_NAME_SIZE 10
  38. #define TAX_STATE_SIZE 3
  39.  
  40. // Macros
  41. #define CALC_OT_HOURS(h) ((h > STD_HOURS) ? (h - STD_HOURS) : 0)
  42. #define CALC_STATE_TAX(p,r) ((p)*(r))
  43. #define CALC_FED_TAX(p) ((p)*FED_TAX_RATE)
  44. #define CALC_NET_PAY(p,s,f) ((p)-((s)+(f)))
  45.  
  46. #define CALC_NORMAL_PAY(w,h,ot) ((w)*((h)-(ot)))
  47. #define CALC_OT_PAY(w,ot) ((ot)*(OT_RATE*(w)))
  48.  
  49. #define CALC_MIN(v,m) ((v)<(m)?(v):(m))
  50. #define CALC_MAX(v,m) ((v)>(m)?(v):(m))
  51.  
  52. // Structures
  53. struct name {
  54. char firstName[FIRST_NAME_SIZE];
  55. char lastName[LAST_NAME_SIZE];
  56. };
  57.  
  58. typedef struct employee {
  59. struct name empName;
  60. char taxState[TAX_STATE_SIZE];
  61. long int clockNumber;
  62. float wageRate;
  63. float hours;
  64. float overtimeHrs;
  65. float grossPay;
  66. float stateTax;
  67. float fedTax;
  68. float netPay;
  69. struct employee *next;
  70. } EMPLOYEE;
  71.  
  72. typedef struct totals {
  73. float total_wageRate;
  74. float total_hours;
  75. float total_overtimeHrs;
  76. float total_grossPay;
  77. float total_stateTax;
  78. float total_fedTax;
  79. float total_netPay;
  80. } TOTALS;
  81.  
  82. typedef struct min_max {
  83. float min_wageRate, min_hours, min_overtimeHrs, min_grossPay, min_stateTax, min_fedTax, min_netPay;
  84. float max_wageRate, max_hours, max_overtimeHrs, max_grossPay, max_stateTax, max_fedTax, max_netPay;
  85. } MIN_MAX;
  86.  
  87. // Prototypes
  88. EMPLOYEE *getEmpData(void);
  89. int isEmployeeSize(EMPLOYEE *head_ptr);
  90.  
  91. void calcOvertimeHrs(EMPLOYEE *head_ptr);
  92. void calcGrossPay(EMPLOYEE *head_ptr);
  93. void calcStateTax(EMPLOYEE *head_ptr);
  94. void calcFedTax(EMPLOYEE *head_ptr);
  95. void calcNetPay(EMPLOYEE *head_ptr);
  96.  
  97. void calcEmployeeTotals(EMPLOYEE *head_ptr, TOTALS *t);
  98. void calcEmployeeMinMax(EMPLOYEE *head_ptr, MIN_MAX *m);
  99.  
  100. void printHeader(void);
  101. void printEmp(EMPLOYEE *head_ptr);
  102. void printEmpStatistics(TOTALS *t, MIN_MAX *m, int size);
  103.  
  104. // MAIN
  105. int main()
  106. {
  107. EMPLOYEE *head_ptr;
  108. int size;
  109.  
  110. TOTALS employeeTotals = {0,0,0,0,0,0,0};
  111. MIN_MAX employeeMinMax = {0};
  112. MIN_MAX *emp_minMax_ptr = &employeeMinMax;
  113.  
  114. head_ptr = getEmpData();
  115. size = isEmployeeSize(head_ptr);
  116.  
  117. if (size <= 0)
  118. {
  119. printf("\n**** No employees ****\n");
  120. return 0;
  121. }
  122.  
  123. calcOvertimeHrs(head_ptr);
  124. calcGrossPay(head_ptr);
  125. calcStateTax(head_ptr);
  126. calcFedTax(head_ptr);
  127. calcNetPay(head_ptr);
  128.  
  129. calcEmployeeTotals(head_ptr, &employeeTotals);
  130. calcEmployeeMinMax(head_ptr, emp_minMax_ptr);
  131.  
  132. printHeader();
  133. printEmp(head_ptr);
  134. printEmpStatistics(&employeeTotals, emp_minMax_ptr, size);
  135.  
  136. printf("\n\n*** End of Program ***\n");
  137. return 0;
  138. }
  139.  
  140. //**************************************************************
  141. // Input Function
  142. //**************************************************************
  143. EMPLOYEE *getEmpData(void)
  144. {
  145. char answer[80];
  146. int more_data = 1;
  147. char value;
  148.  
  149. EMPLOYEE *current_ptr, *head_ptr;
  150.  
  151. head_ptr = (EMPLOYEE *)malloc(sizeof(EMPLOYEE));
  152. current_ptr = head_ptr;
  153.  
  154. while (more_data)
  155. {
  156. printf("\nEnter employee first name: ");
  157. scanf("%s", current_ptr->empName.firstName);
  158.  
  159. printf("Enter employee last name: ");
  160. scanf("%s", current_ptr->empName.lastName);
  161.  
  162. printf("Enter tax state: ");
  163. scanf("%s", current_ptr->taxState);
  164.  
  165. printf("Enter clock number: ");
  166. scanf("%li", &current_ptr->clockNumber);
  167.  
  168. printf("Enter wage rate: ");
  169. scanf("%f", &current_ptr->wageRate);
  170.  
  171. printf("Enter hours: ");
  172. scanf("%f", &current_ptr->hours);
  173.  
  174. printf("Add another employee? (y/n): ");
  175. scanf("%s", answer);
  176.  
  177. value = toupper(answer[0]);
  178.  
  179. if (value != 'Y')
  180. {
  181. current_ptr->next = NULL;
  182. more_data = 0;
  183. }
  184. else
  185. {
  186. current_ptr->next = (EMPLOYEE *)malloc(sizeof(EMPLOYEE));
  187. current_ptr = current_ptr->next;
  188. }
  189. }
  190.  
  191. return head_ptr;
  192. }
  193.  
  194. //**************************************************************
  195. int isEmployeeSize(EMPLOYEE *head_ptr)
  196. {
  197. int count = 0;
  198. EMPLOYEE *cur = head_ptr;
  199.  
  200. while (cur != NULL)
  201. {
  202. count++;
  203. cur = cur->next;
  204. }
  205. return count;
  206. }
  207.  
  208. //**************************************************************
  209. void calcOvertimeHrs(EMPLOYEE *head_ptr)
  210. {
  211. for (EMPLOYEE *cur = head_ptr; cur; cur = cur->next)
  212. cur->overtimeHrs = CALC_OT_HOURS(cur->hours);
  213. }
  214.  
  215. //**************************************************************
  216. void calcGrossPay(EMPLOYEE *head_ptr)
  217. {
  218. for (EMPLOYEE *cur = head_ptr; cur; cur = cur->next)
  219. {
  220. float normal = CALC_NORMAL_PAY(cur->wageRate, cur->hours, cur->overtimeHrs);
  221. float ot = CALC_OT_PAY(cur->wageRate, cur->overtimeHrs);
  222. cur->grossPay = normal + ot;
  223. }
  224. }
  225.  
  226. //**************************************************************
  227. void calcStateTax(EMPLOYEE *head_ptr)
  228. {
  229. for (EMPLOYEE *cur = head_ptr; cur; cur = cur->next)
  230. {
  231. if (strcmp(cur->taxState, "MA") == 0)
  232. cur->stateTax = CALC_STATE_TAX(cur->grossPay, MA_TAX_RATE);
  233. else if (strcmp(cur->taxState, "VT") == 0)
  234. cur->stateTax = CALC_STATE_TAX(cur->grossPay, VT_TAX_RATE);
  235. else if (strcmp(cur->taxState, "NH") == 0)
  236. cur->stateTax = CALC_STATE_TAX(cur->grossPay, NH_TAX_RATE);
  237. else if (strcmp(cur->taxState, "CA") == 0)
  238. cur->stateTax = CALC_STATE_TAX(cur->grossPay, CA_TAX_RATE);
  239. else
  240. cur->stateTax = CALC_STATE_TAX(cur->grossPay, DEFAULT_STATE_TAX_RATE);
  241. }
  242. }
  243.  
  244. //**************************************************************
  245. void calcFedTax(EMPLOYEE *head_ptr)
  246. {
  247. for (EMPLOYEE *cur = head_ptr; cur; cur = cur->next)
  248. cur->fedTax = CALC_FED_TAX(cur->grossPay);
  249. }
  250.  
  251. //**************************************************************
  252. void calcNetPay(EMPLOYEE *head_ptr)
  253. {
  254. for (EMPLOYEE *cur = head_ptr; cur; cur = cur->next)
  255. cur->netPay = CALC_NET_PAY(cur->grossPay, cur->stateTax, cur->fedTax);
  256. }
  257.  
  258. //**************************************************************
  259. void calcEmployeeTotals(EMPLOYEE *head_ptr, TOTALS *t)
  260. {
  261. for (EMPLOYEE *cur = head_ptr; cur; cur = cur->next)
  262. {
  263. t->total_wageRate += cur->wageRate;
  264. t->total_hours += cur->hours;
  265. t->total_overtimeHrs += cur->overtimeHrs;
  266. t->total_grossPay += cur->grossPay;
  267. t->total_stateTax += cur->stateTax;
  268. t->total_fedTax += cur->fedTax;
  269. t->total_netPay += cur->netPay;
  270. }
  271. }
  272.  
  273. //**************************************************************
  274. void calcEmployeeMinMax(EMPLOYEE *head_ptr, MIN_MAX *m)
  275. {
  276. EMPLOYEE *cur = head_ptr;
  277.  
  278. m->min_wageRate = m->max_wageRate = cur->wageRate;
  279. m->min_hours = m->max_hours = cur->hours;
  280. m->min_overtimeHrs = m->max_overtimeHrs = cur->overtimeHrs;
  281. m->min_grossPay = m->max_grossPay = cur->grossPay;
  282. m->min_stateTax = m->max_stateTax = cur->stateTax;
  283. m->min_fedTax = m->max_fedTax = cur->fedTax;
  284. m->min_netPay = m->max_netPay = cur->netPay;
  285.  
  286. cur = cur->next;
  287.  
  288. for (; cur; cur = cur->next)
  289. {
  290. m->min_wageRate = CALC_MIN(cur->wageRate, m->min_wageRate);
  291. m->max_wageRate = CALC_MAX(cur->wageRate, m->max_wageRate);
  292. }
  293. }
  294.  
  295. //**************************************************************
  296. void printHeader(void)
  297. {
  298. printf("\n*** Pay Calculator ***\n");
  299. }
  300.  
  301. //**************************************************************
  302. void printEmp(EMPLOYEE *head_ptr)
  303. {
  304. for (EMPLOYEE *cur = head_ptr; cur; cur = cur->next)
  305. printf("%s %s %.2f %.2f %.2f %.2f\n",
  306. cur->empName.firstName,
  307. cur->empName.lastName,
  308. cur->wageRate,
  309. cur->hours,
  310. cur->grossPay,
  311. cur->netPay);
  312. }
  313.  
  314. //**************************************************************
  315. void printEmpStatistics(TOTALS *t, MIN_MAX *m, int size)
  316. {
  317. printf("\nTotals: %.2f %.2f %.2f %.2f %.2f %.2f %.2f",
  318. t->total_wageRate,
  319. t->total_hours,
  320. t->total_overtimeHrs,
  321. t->total_grossPay,
  322. t->total_stateTax,
  323. t->total_fedTax,
  324. t->total_netPay);
  325.  
  326. printf("\nEmployees: %d\n", size);
  327. }
  328.  
Success #stdin #stdout 0s 5320KB
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 employee first name: Enter employee last name: Enter tax state: Enter clock number: Enter wage rate: Enter hours: Add another employee? (y/n): 
Enter employee first name: Enter employee last name: Enter tax state: Enter clock number: Enter wage rate: Enter hours: Add another employee? (y/n): 
Enter employee first name: Enter employee last name: Enter tax state: Enter clock number: Enter wage rate: Enter hours: Add another employee? (y/n): 
Enter employee first name: Enter employee last name: Enter tax state: Enter clock number: Enter wage rate: Enter hours: Add another employee? (y/n): 
Enter employee first name: Enter employee last name: Enter tax state: Enter clock number: Enter wage rate: Enter hours: Add another employee? (y/n): 
*** Pay Calculator ***
Connie Cobol 10.60 51.00 598.90 419.23
Mary Apl 9.75 42.50 426.56 319.92
Frank Fortran 10.50 37.00 388.50 268.07
Jeff Ada 12.25 45.00 581.88 389.86
Anton Pascal 8.35 40.00 334.00 227.12

Totals: 51.45 215.50 18.50 2329.84 123.18 582.46 1624.19
Employees: 5


*** End of Program ***