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. #define MA_TAX_RATE 0.05
  21. #define NH_TAX_RATE 0.0
  22. #define VT_TAX_RATE 0.06
  23. #define CA_TAX_RATE 0.07
  24. #define DEFAULT_STATE_TAX_RATE 0.08
  25. #define FED_TAX_RATE 0.25
  26.  
  27. #define FIRST_NAME_SIZE 10
  28. #define LAST_NAME_SIZE 10
  29. #define TAX_STATE_SIZE 3
  30.  
  31. // macros
  32. #define CALC_OT_HOURS(theHours) ((theHours > STD_HOURS) ? theHours - STD_HOURS : 0)
  33. #define CALC_STATE_TAX(thePay,theRate) (thePay * theRate)
  34. #define CALC_FED_TAX(thePay) (thePay * FED_TAX_RATE)
  35. #define CALC_NET_PAY(thePay,theStateTax,theFedTax) (thePay - (theStateTax + theFedTax))
  36. #define CALC_NORMAL_PAY(rate,hours,ot) (rate * (hours - ot))
  37. #define CALC_OT_PAY(rate,ot) (ot * (OT_RATE * rate))
  38.  
  39. // FIXED MIN/MAX
  40. #define CALC_MIN(val,min) ((val < min) ? val : min)
  41. #define CALC_MAX(val,max) ((val > max) ? val : max)
  42.  
  43. // name struct
  44. struct name {
  45. char firstName[FIRST_NAME_SIZE];
  46. char lastName[LAST_NAME_SIZE];
  47. };
  48.  
  49. // employee typedef
  50. typedef struct employee {
  51. struct name empName;
  52. char taxState[TAX_STATE_SIZE];
  53. long int clockNumber;
  54. float wageRate;
  55. float hours;
  56. float overtimeHrs;
  57. float grossPay;
  58. float stateTax;
  59. float fedTax;
  60. float netPay;
  61. struct employee *next;
  62. } EMPLOYEE;
  63.  
  64. // totals typedef
  65. typedef struct totals {
  66. float total_wageRate;
  67. float total_hours;
  68. float total_overtimeHrs;
  69. float total_grossPay;
  70. float total_stateTax;
  71. float total_fedTax;
  72. float total_netPay;
  73. } TOTALS;
  74.  
  75. // MIN_MAX typedef FIXED
  76. typedef struct min_max {
  77. float min_wageRate;
  78. float min_hours;
  79. float min_overtimeHrs;
  80. float min_grossPay;
  81. float min_stateTax;
  82. float min_fedTax;
  83. float min_netPay;
  84. float max_wageRate;
  85. float max_hours;
  86. float max_overtimeHrs;
  87. float max_grossPay;
  88. float max_stateTax;
  89. float max_fedTax;
  90. float max_netPay;
  91. } MIN_MAX;
  92.  
  93. // prototypes
  94. EMPLOYEE * getEmpData(void);
  95. int isEmployeeSize(EMPLOYEE *head_ptr);
  96. void calcOvertimeHrs(EMPLOYEE *head_ptr);
  97. void calcGrossPay(EMPLOYEE *head_ptr);
  98. void calcStateTax(EMPLOYEE *head_ptr);
  99. void calcFedTax(EMPLOYEE *head_ptr);
  100. void calcNetPay(EMPLOYEE *head_ptr);
  101. void calcEmployeeTotals(EMPLOYEE *head_ptr, TOTALS *totals);
  102. void calcEmployeeMinMax(EMPLOYEE *head_ptr, MIN_MAX *minmax);
  103. void printHeader(void);
  104. void printEmp(EMPLOYEE *head_ptr);
  105. void printEmpStatistics(TOTALS *totals, MIN_MAX *minmax, int size);
  106.  
  107. int main() {
  108.  
  109. EMPLOYEE *head_ptr;
  110. int size;
  111.  
  112. TOTALS totals = {0};
  113. MIN_MAX minmax;
  114.  
  115. head_ptr = getEmpData();
  116. size = isEmployeeSize(head_ptr);
  117.  
  118. if (size <= 0) {
  119. printf("\nNo 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. calcEmployeeTotals(head_ptr, &totals);
  129. calcEmployeeMinMax(head_ptr, &minmax);
  130.  
  131. printHeader();
  132. printEmp(head_ptr);
  133. printEmpStatistics(&totals, &minmax, size);
  134.  
  135. printf("\n*** End of Program ***\n");
  136. return 0;
  137. }
  138.  
  139. //================ FUNCTIONS =================
  140.  
  141. EMPLOYEE * getEmpData(void) {
  142.  
  143. EMPLOYEE *head = malloc(sizeof(EMPLOYEE));
  144. EMPLOYEE *curr = head;
  145.  
  146. char ans[10];
  147. int more = 1;
  148.  
  149. while (more) {
  150. printf("First name: "); scanf("%s", curr->empName.firstName);
  151. printf("Last name: "); scanf("%s", curr->empName.lastName);
  152. printf("State: "); scanf("%s", curr->taxState);
  153. printf("Clock #: "); scanf("%ld", &curr->clockNumber);
  154. printf("Wage: "); scanf("%f", &curr->wageRate);
  155. printf("Hours: "); scanf("%f", &curr->hours);
  156.  
  157. printf("More? (y/n): ");
  158. scanf("%s", ans);
  159.  
  160. if (toupper(ans[0]) != 'Y') {
  161. curr->next = NULL;
  162. more = 0;
  163. } else {
  164. curr->next = malloc(sizeof(EMPLOYEE));
  165. curr = curr->next;
  166. }
  167. }
  168. return head;
  169. }
  170.  
  171. int isEmployeeSize(EMPLOYEE *head) {
  172. int count = 0;
  173. while (head) {
  174. count++;
  175. head = head->next;
  176. }
  177. return count;
  178. }
  179.  
  180. void calcOvertimeHrs(EMPLOYEE *head) {
  181. while (head) {
  182. head->overtimeHrs = CALC_OT_HOURS(head->hours);
  183. head = head->next;
  184. }
  185. }
  186.  
  187. void calcGrossPay(EMPLOYEE *head) {
  188. while (head) {
  189. float normal = CALC_NORMAL_PAY(head->wageRate, head->hours, head->overtimeHrs);
  190. float ot = CALC_OT_PAY(head->wageRate, head->overtimeHrs);
  191. head->grossPay = normal + ot;
  192. head = head->next;
  193. }
  194. }
  195.  
  196. void calcStateTax(EMPLOYEE *head) {
  197. while (head) {
  198. if (!strcmp(head->taxState,"MA"))
  199. head->stateTax = CALC_STATE_TAX(head->grossPay, MA_TAX_RATE);
  200. else if (!strcmp(head->taxState,"VT"))
  201. head->stateTax = CALC_STATE_TAX(head->grossPay, VT_TAX_RATE);
  202. else if (!strcmp(head->taxState,"NH"))
  203. head->stateTax = CALC_STATE_TAX(head->grossPay, NH_TAX_RATE);
  204. else if (!strcmp(head->taxState,"CA"))
  205. head->stateTax = CALC_STATE_TAX(head->grossPay, CA_TAX_RATE);
  206. else
  207. head->stateTax = CALC_STATE_TAX(head->grossPay, DEFAULT_STATE_TAX_RATE);
  208.  
  209. head = head->next;
  210. }
  211. }
  212.  
  213. void calcFedTax(EMPLOYEE *head) {
  214. while (head) {
  215. head->fedTax = CALC_FED_TAX(head->grossPay);
  216. head = head->next;
  217. }
  218. }
  219.  
  220. void calcNetPay(EMPLOYEE *head) {
  221. while (head) {
  222. head->netPay = CALC_NET_PAY(head->grossPay, head->stateTax, head->fedTax);
  223. head = head->next;
  224. }
  225. }
  226.  
  227. void calcEmployeeTotals(EMPLOYEE *head, TOTALS *t) {
  228. while (head) {
  229. t->total_wageRate += head->wageRate;
  230. t->total_hours += head->hours;
  231. t->total_overtimeHrs += head->overtimeHrs;
  232. t->total_grossPay += head->grossPay;
  233. t->total_stateTax += head->stateTax;
  234. t->total_fedTax += head->fedTax;
  235. t->total_netPay += head->netPay;
  236. head = head->next;
  237. }
  238. }
  239.  
  240. void calcEmployeeMinMax(EMPLOYEE *head, MIN_MAX *m) {
  241.  
  242. *m = (MIN_MAX){head->wageRate,head->hours,head->overtimeHrs,
  243. head->grossPay,head->stateTax,head->fedTax,head->netPay,
  244. head->wageRate,head->hours,head->overtimeHrs,
  245. head->grossPay,head->stateTax,head->fedTax,head->netPay};
  246.  
  247. head = head->next;
  248.  
  249. while (head) {
  250. m->min_wageRate = CALC_MIN(head->wageRate, m->min_wageRate);
  251. m->max_wageRate = CALC_MAX(head->wageRate, m->max_wageRate);
  252.  
  253. m->min_hours = CALC_MIN(head->hours, m->min_hours);
  254. m->max_hours = CALC_MAX(head->hours, m->max_hours);
  255.  
  256. m->min_overtimeHrs = CALC_MIN(head->overtimeHrs, m->min_overtimeHrs);
  257. m->max_overtimeHrs = CALC_MAX(head->overtimeHrs, m->max_overtimeHrs);
  258.  
  259. m->min_grossPay = CALC_MIN(head->grossPay, m->min_grossPay);
  260. m->max_grossPay = CALC_MAX(head->grossPay, m->max_grossPay);
  261.  
  262. m->min_stateTax = CALC_MIN(head->stateTax, m->min_stateTax);
  263. m->max_stateTax = CALC_MAX(head->stateTax, m->max_stateTax);
  264.  
  265. m->min_fedTax = CALC_MIN(head->fedTax, m->min_fedTax);
  266. m->max_fedTax = CALC_MAX(head->fedTax, m->max_fedTax);
  267.  
  268. m->min_netPay = CALC_MIN(head->netPay, m->min_netPay);
  269. m->max_netPay = CALC_MAX(head->netPay, m->max_netPay);
  270.  
  271. head = head->next;
  272. }
  273. }
  274.  
  275. void printHeader() {
  276. printf("\n*** Pay Calculator ***\n");
  277. }
  278.  
  279. void printEmp(EMPLOYEE *head) {
  280. while (head) {
  281. printf("\n%s %s Net: %.2f",
  282. head->empName.firstName,
  283. head->empName.lastName,
  284. head->netPay);
  285. head = head->next;
  286. }
  287. }
  288.  
  289. void printEmpStatistics(TOTALS *t, MIN_MAX *m, int size) {
  290.  
  291. printf("\nTotals Gross: %.2f", t->total_grossPay);
  292. printf("\nAverage Gross: %.2f", t->total_grossPay / size);
  293. printf("\nMin Gross: %.2f", m->min_grossPay);
  294. printf("\nMax Gross: %.2f", m->max_grossPay);
  295. }
Success #stdin #stdout 0.01s 5316KB
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? (y/n): First name: Last name: State: Clock #: Wage: Hours: More? (y/n): First name: Last name: State: Clock #: Wage: Hours: More? (y/n): First name: Last name: State: Clock #: Wage: Hours: More? (y/n): First name: Last name: State: Clock #: Wage: Hours: More? (y/n): 
*** Pay Calculator ***

Connie Cobol Net: 419.23
Mary Apl Net: 319.92
Frank Fortran Net: 268.07
Jeff Ada Net: 389.86
Anton Pascal Net: 227.12
Totals Gross: 2329.84
Average Gross: 465.97
Min Gross: 334.00
Max Gross: 598.90
*** End of Program ***