fork download
  1.  
  2. //********************************************************
  3. //
  4. // Assignment 10 - Linked Lists, Typedef, and Macros
  5. //
  6. // Name: John Semenuk
  7. //
  8. // Class: C Programming, Spring 2026
  9. //
  10. // Date: April 20, 2026
  11. //
  12. // Description: Program which determines overtime and
  13. // gross pay for a set of employees with outputs sent
  14. // to standard output (the screen).
  15. //
  16. // This assignment also adds employee name, tax state,
  17. // and calculates state tax, federal tax, and net pay.
  18. // It also calculates totals, averages, minimum, and maximum.
  19. //
  20. // Linked list + typedef + macros version
  21. //
  22. //********************************************************
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <stdlib.h>
  28.  
  29. #define STD_HOURS 40.0
  30. #define OT_RATE 1.5
  31.  
  32. #define MA_TAX_RATE 0.05
  33. #define NH_TAX_RATE 0.0
  34. #define VT_TAX_RATE 0.06
  35. #define CA_TAX_RATE 0.07
  36. #define DEFAULT_STATE_TAX_RATE 0.08
  37.  
  38. #define FED_TAX_RATE 0.25
  39.  
  40. #define NAME_SIZE 20
  41. #define TAX_STATE_SIZE 3
  42. #define FIRST_NAME_SIZE 10
  43. #define LAST_NAME_SIZE 10
  44.  
  45. // Macros
  46. #define CALC_OT_HOURS(theHours) ((theHours > STD_HOURS) ? (theHours - STD_HOURS) : 0)
  47.  
  48. #define CALC_STATE_TAX(thePay,theStateTaxRate) ((thePay) * (theStateTaxRate))
  49.  
  50. // ✅ FIXED FED TAX MACRO
  51. #define CALC_FED_TAX(thePay) ((thePay) * FED_TAX_RATE)
  52.  
  53. #define CALC_NET_PAY(thePay,theStateTax,theFedTax) ((thePay) - ((theStateTax) + (theFedTax)))
  54.  
  55. #define CALC_NORMAL_PAY(theWageRate,theHours,theOvertimeHrs) \
  56. ((theWageRate) * ((theHours) - (theOvertimeHrs)))
  57.  
  58. #define CALC_OT_PAY(theWageRate,theOvertimeHrs) \
  59. ((theOvertimeHrs) * (OT_RATE * (theWageRate)))
  60.  
  61. // ✅ FIXED MIN/MAX MACROS
  62. #define CALC_MIN(theValue, currentMin) (((theValue) < (currentMin)) ? (theValue) : (currentMin))
  63. #define CALC_MAX(theValue, currentMax) (((theValue) > (currentMax)) ? (theValue) : (currentMax))
  64.  
  65. // structures
  66. struct name {
  67. char firstName[FIRST_NAME_SIZE];
  68. char lastName[LAST_NAME_SIZE];
  69. };
  70.  
  71. typedef struct employee {
  72. struct name empName;
  73. char taxState[TAX_STATE_SIZE];
  74. long int clockNumber;
  75. float wageRate;
  76. float hours;
  77. float overtimeHrs;
  78. float grossPay;
  79. float stateTax;
  80. float fedTax;
  81. float netPay;
  82. struct employee *next;
  83. } EMPLOYEE;
  84.  
  85. typedef struct totals {
  86. float total_wageRate;
  87. float total_hours;
  88. float total_overtimeHrs;
  89. float total_grossPay;
  90. float total_stateTax;
  91. float total_fedTax;
  92. float total_netPay;
  93. } TOTALS;
  94.  
  95. // ✅ MIN_MAX typedef added
  96. typedef struct min_max {
  97. float min_wageRate;
  98. float min_hours;
  99. float min_overtimeHrs;
  100. float min_grossPay;
  101. float min_stateTax;
  102. float min_fedTax;
  103. float min_netPay;
  104.  
  105. float max_wageRate;
  106. float max_hours;
  107. float max_overtimeHrs;
  108. float max_grossPay;
  109. float max_stateTax;
  110. float max_fedTax;
  111. float max_netPay;
  112. } MIN_MAX;
  113.  
  114. // prototypes
  115. EMPLOYEE * getEmpData(void);
  116. int isEmployeeSize(EMPLOYEE * head_ptr);
  117. void calcOvertimeHrs(EMPLOYEE * head_ptr);
  118. void calcGrossPay(EMPLOYEE * head_ptr);
  119. void calcStateTax(EMPLOYEE * head_ptr);
  120. void calcFedTax(EMPLOYEE * head_ptr);
  121. void calcNetPay(EMPLOYEE * head_ptr);
  122.  
  123. void calcEmployeeTotals(EMPLOYEE * head_ptr, TOTALS * emp_totals_ptr);
  124.  
  125. void calcEmployeeMinMax(EMPLOYEE * head_ptr, MIN_MAX * emp_minMax_ptr);
  126.  
  127. void printHeader(void);
  128. void printEmp(EMPLOYEE * head_ptr);
  129.  
  130. void printEmpStatistics(TOTALS * emp_totals_ptr, MIN_MAX * emp_minMax_ptr, int size);
  131.  
  132. //**************************************************************
  133. int main()
  134. {
  135. EMPLOYEE *head_ptr;
  136. int theSize;
  137.  
  138. TOTALS employeeTotals = {0};
  139. TOTALS *emp_totals_ptr = &employeeTotals;
  140.  
  141. MIN_MAX employeeMinMax = {0};
  142. MIN_MAX *emp_minMax_ptr = &employeeMinMax;
  143.  
  144. head_ptr = getEmpData();
  145.  
  146. theSize = isEmployeeSize(head_ptr);
  147.  
  148. if (theSize <= 0)
  149. {
  150. printf("\n\n**** There was no employee input to process ***\n");
  151. }
  152. else
  153. {
  154. calcOvertimeHrs(head_ptr);
  155. calcGrossPay(head_ptr);
  156. calcStateTax(head_ptr);
  157. calcFedTax(head_ptr);
  158. calcNetPay(head_ptr);
  159.  
  160. calcEmployeeTotals(head_ptr, emp_totals_ptr);
  161. calcEmployeeMinMax(head_ptr, emp_minMax_ptr);
  162.  
  163. printHeader();
  164. printEmp(head_ptr);
  165. printEmpStatistics(emp_totals_ptr, emp_minMax_ptr, theSize);
  166. }
  167.  
  168. printf("\n\n *** End of Program *** \n");
  169. return 0;
  170. }
  171.  
  172. //**************************************************************
  173. EMPLOYEE * getEmpData(void)
  174. {
  175. EMPLOYEE *head_ptr, *current_ptr;
  176. char answer[10];
  177. int more_data = 1;
  178.  
  179. head_ptr = malloc(sizeof(EMPLOYEE));
  180. current_ptr = head_ptr;
  181.  
  182. while (more_data)
  183. {
  184. printf("\nEnter employee first name: ");
  185. scanf("%s", current_ptr->empName.firstName);
  186.  
  187. printf("\nEnter employee last name: ");
  188. scanf("%s", current_ptr->empName.lastName);
  189.  
  190. printf("\nEnter employee tax state: ");
  191. scanf("%s", current_ptr->taxState);
  192.  
  193. printf("\nEnter clock number: ");
  194. scanf("%li", &current_ptr->clockNumber);
  195.  
  196. printf("\nEnter wage rate: ");
  197. scanf("%f", &current_ptr->wageRate);
  198.  
  199. printf("\nEnter hours: ");
  200. scanf("%f", &current_ptr->hours);
  201.  
  202. printf("\nAnother employee? (y/n): ");
  203. scanf("%s", answer);
  204.  
  205. if (toupper(answer[0]) != 'Y')
  206. {
  207. current_ptr->next = NULL;
  208. more_data = 0;
  209. }
  210. else
  211. {
  212. current_ptr->next = malloc(sizeof(EMPLOYEE));
  213. current_ptr = current_ptr->next;
  214. }
  215. }
  216.  
  217. return head_ptr;
  218. }
  219.  
  220. //**************************************************************
  221. int isEmployeeSize(EMPLOYEE *head_ptr)
  222. {
  223. int count = 0;
  224. EMPLOYEE *cur;
  225.  
  226. for (cur = head_ptr; cur; cur = cur->next)
  227. count++;
  228.  
  229. return count;
  230. }
  231.  
  232. //**************************************************************
  233. void calcOvertimeHrs(EMPLOYEE *head_ptr)
  234. {
  235. EMPLOYEE *cur;
  236. for (cur = head_ptr; cur; cur = cur->next)
  237. cur->overtimeHrs = CALC_OT_HOURS(cur->hours);
  238. }
  239.  
  240. //**************************************************************
  241. void calcGrossPay(EMPLOYEE *head_ptr)
  242. {
  243. EMPLOYEE *cur;
  244. float normal, ot;
  245.  
  246. for (cur = head_ptr; cur; cur = cur->next)
  247. {
  248. normal = CALC_NORMAL_PAY(cur->wageRate, cur->hours, cur->overtimeHrs);
  249. ot = CALC_OT_PAY(cur->wageRate, cur->overtimeHrs);
  250. cur->grossPay = normal + ot;
  251. }
  252. }
  253.  
  254. //**************************************************************
  255. void calcStateTax(EMPLOYEE *head_ptr)
  256. {
  257. EMPLOYEE *cur;
  258.  
  259. for (cur = head_ptr; cur; cur = cur->next)
  260. {
  261. if (strcmp(cur->taxState, "MA") == 0)
  262. cur->stateTax = CALC_STATE_TAX(cur->grossPay, MA_TAX_RATE);
  263. else if (strcmp(cur->taxState, "VT") == 0)
  264. cur->stateTax = CALC_STATE_TAX(cur->grossPay, VT_TAX_RATE);
  265. else if (strcmp(cur->taxState, "NH") == 0)
  266. cur->stateTax = CALC_STATE_TAX(cur->grossPay, NH_TAX_RATE);
  267. else if (strcmp(cur->taxState, "CA") == 0)
  268. cur->stateTax = CALC_STATE_TAX(cur->grossPay, CA_TAX_RATE);
  269. else
  270. cur->stateTax = CALC_STATE_TAX(cur->grossPay, DEFAULT_STATE_TAX_RATE);
  271. }
  272. }
  273.  
  274. //**************************************************************
  275. void calcFedTax(EMPLOYEE *head_ptr)
  276. {
  277. EMPLOYEE *cur;
  278.  
  279. for (cur = head_ptr; cur; cur = cur->next)
  280. cur->fedTax = CALC_FED_TAX(cur->grossPay);
  281. }
  282.  
  283. //**************************************************************
  284. void calcNetPay(EMPLOYEE *head_ptr)
  285. {
  286. EMPLOYEE *cur;
  287.  
  288. for (cur = head_ptr; cur; cur = cur->next)
  289. cur->netPay = CALC_NET_PAY(cur->grossPay, cur->stateTax, cur->fedTax);
  290. }
  291.  
  292. //**************************************************************
  293. void calcEmployeeTotals(EMPLOYEE *head_ptr, TOTALS *t)
  294. {
  295. EMPLOYEE *cur;
  296.  
  297. for (cur = head_ptr; cur; cur = cur->next)
  298. {
  299. t->total_wageRate += cur->wageRate;
  300. t->total_hours += cur->hours;
  301. t->total_overtimeHrs += cur->overtimeHrs;
  302. t->total_grossPay += cur->grossPay;
  303. t->total_stateTax += cur->stateTax;
  304. t->total_fedTax += cur->fedTax;
  305. t->total_netPay += cur->netPay;
  306. }
  307. }
  308.  
  309. //**************************************************************
  310. void calcEmployeeMinMax(EMPLOYEE *head_ptr, MIN_MAX *m)
  311. {
  312. EMPLOYEE *cur = head_ptr;
  313.  
  314. m->min_wageRate = m->max_wageRate = cur->wageRate;
  315. m->min_hours = m->max_hours = cur->hours;
  316. m->min_overtimeHrs = m->max_overtimeHrs = cur->overtimeHrs;
  317. m->min_grossPay = m->max_grossPay = cur->grossPay;
  318. m->min_stateTax = m->max_stateTax = cur->stateTax;
  319. m->min_fedTax = m->max_fedTax = cur->fedTax;
  320. m->min_netPay = m->max_netPay = cur->netPay;
  321.  
  322. cur = cur->next;
  323.  
  324. for (; cur; cur = cur->next)
  325. {
  326. m->min_wageRate = CALC_MIN(cur->wageRate, m->min_wageRate);
  327. m->max_wageRate = CALC_MAX(cur->wageRate, m->max_wageRate);
  328.  
  329. m->min_hours = CALC_MIN(cur->hours, m->min_hours);
  330. m->max_hours = CALC_MAX(cur->hours, m->max_hours);
  331.  
  332. m->min_overtimeHrs = CALC_MIN(cur->overtimeHrs, m->min_overtimeHrs);
  333. m->max_overtimeHrs = CALC_MAX(cur->overtimeHrs, m->max_overtimeHrs);
  334.  
  335. m->min_grossPay = CALC_MIN(cur->grossPay, m->min_grossPay);
  336. m->max_grossPay = CALC_MAX(cur->grossPay, m->max_grossPay);
  337.  
  338. m->min_stateTax = CALC_MIN(cur->stateTax, m->min_stateTax);
  339. m->max_stateTax = CALC_MAX(cur->stateTax, m->max_stateTax);
  340.  
  341. m->min_fedTax = CALC_MIN(cur->fedTax, m->min_fedTax);
  342. m->max_fedTax = CALC_MAX(cur->fedTax, m->max_fedTax);
  343.  
  344. m->min_netPay = CALC_MIN(cur->netPay, m->min_netPay);
  345. m->max_netPay = CALC_MAX(cur->netPay, m->max_netPay);
  346. }
  347. }
  348.  
  349. //**************************************************************
  350. void printHeader(void)
  351. {
  352. printf("\n\n*** Pay Calculator ***\n");
  353. printf("\n---------------------------------------------------------------------------------");
  354. printf("\nName Tax Clock# Wage Hours OT Gross State Fed Net");
  355. printf("\n State Pay Tax Tax Pay");
  356. printf("\n---------------------------------------------------------------------------------");
  357. }
  358.  
  359. //**************************************************************
  360. void printEmp(EMPLOYEE *head_ptr)
  361. {
  362. EMPLOYEE *cur;
  363. char name[30];
  364.  
  365. for (cur = head_ptr; cur; cur = cur->next)
  366. {
  367. strcpy(name, cur->empName.firstName);
  368. strcat(name, " ");
  369. strcat(name, cur->empName.lastName);
  370.  
  371. printf("\n%-20s %-2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f",
  372. name,
  373. cur->taxState,
  374. cur->clockNumber,
  375. cur->wageRate,
  376. cur->hours,
  377. cur->overtimeHrs,
  378. cur->grossPay,
  379. cur->stateTax,
  380. cur->fedTax,
  381. cur->netPay);
  382. }
  383. }
  384.  
  385. //**************************************************************
  386. void printEmpStatistics(TOTALS *t, MIN_MAX *m, int size)
  387. {
  388. printf("\n---------------------------------------------------------------------------------");
  389.  
  390. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  391. t->total_wageRate,
  392. t->total_hours,
  393. t->total_overtimeHrs,
  394. t->total_grossPay,
  395. t->total_stateTax,
  396. t->total_fedTax,
  397. t->total_netPay);
  398.  
  399. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  400. t->total_wageRate/size,
  401. t->total_hours/size,
  402. t->total_overtimeHrs/size,
  403. t->total_grossPay/size,
  404. t->total_stateTax/size,
  405. t->total_fedTax/size,
  406. t->total_netPay/size);
  407.  
  408. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  409. m->min_wageRate,
  410. m->min_hours,
  411. m->min_overtimeHrs,
  412. m->min_grossPay,
  413. m->min_stateTax,
  414. m->min_fedTax,
  415. m->min_netPay);
  416.  
  417. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  418. m->max_wageRate,
  419. m->max_hours,
  420. m->max_overtimeHrs,
  421. m->max_grossPay,
  422. m->max_stateTax,
  423. m->max_fedTax,
  424. m->max_netPay);
  425.  
  426. printf("\n\nThe total employees processed was: %d\n", size);
  427. }
Success #stdin #stdout 0s 5284KB
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 employee tax state: 
Enter clock number: 
Enter wage rate: 
Enter hours: 
Another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee tax state: 
Enter clock number: 
Enter wage rate: 
Enter hours: 
Another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee tax state: 
Enter clock number: 
Enter wage rate: 
Enter hours: 
Another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee tax state: 
Enter clock number: 
Enter wage rate: 
Enter hours: 
Another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee tax state: 
Enter clock number: 
Enter wage rate: 
Enter hours: 
Another employee? (y/n): 

*** Pay Calculator ***

---------------------------------------------------------------------------------
Name                Tax  Clock#  Wage   Hours  OT   Gross   State  Fed      Net
                    State                           Pay     Tax    Tax      Pay
---------------------------------------------------------------------------------
Connie Cobol         MA  098401  10.60  51.0  11.0   598.90   29.95   149.73    419.23
Mary Apl             NH  526488   9.75  42.5   2.5   426.56    0.00   106.64    319.92
Frank Fortran        VT  765349  10.50  37.0   0.0   388.50   23.31    97.12    268.07
Jeff Ada             NY  034645  12.25  45.0   5.0   581.88   46.55   145.47    389.86
Anton Pascal         CA  127615   8.35  40.0   0.0   334.00   23.38    83.50    227.12
---------------------------------------------------------------------------------
Totals:                          51.45 215.5  18.5 2329.84 123.18  582.46  1624.19
Averages:                        10.29  43.1   3.7  465.97  24.64  116.49   324.84
Minimum:                          8.35  37.0   0.0  334.00   0.00   83.50   227.12
Maximum:                         12.25  51.0  11.0  598.90  46.55  149.73   419.23

The total employees processed was: 5


 *** End of Program ***