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. // constants
  19. #define STD_HOURS 40.0
  20. #define OT_RATE 1.5
  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. #define TAX_STATE_SIZE 3
  27. #define FED_TAX_RATE 0.25
  28. #define FIRST_NAME_SIZE 10
  29. #define LAST_NAME_SIZE 10
  30.  
  31. // macros
  32. #define CALC_OT_HOURS(h) ((h > STD_HOURS) ? h - STD_HOURS : 0)
  33. #define CALC_STATE_TAX(p,r) (p * r)
  34. #define CALC_FED_TAX(p) (p * FED_TAX_RATE)
  35. #define CALC_NET_PAY(p,s,f) (p - (s + f))
  36. #define CALC_NORMAL_PAY(w,h,o) (w * (h - o))
  37. #define CALC_OT_PAY(w,o) (o * (OT_RATE * w))
  38. #define CALC_MIN(v,m) ((v < m) ? v : m)
  39. #define CALC_MAX(v,m) ((v > m) ? v : m)
  40.  
  41. // structures
  42. struct name {
  43. char firstName[FIRST_NAME_SIZE];
  44. char lastName[LAST_NAME_SIZE];
  45. };
  46.  
  47. typedef struct employee {
  48. struct name empName;
  49. char taxState[TAX_STATE_SIZE];
  50. long int clockNumber;
  51. float wageRate, hours, overtimeHrs;
  52. float grossPay, stateTax, fedTax, netPay;
  53. struct employee *next;
  54. } EMPLOYEE;
  55.  
  56. typedef struct totals {
  57. float total_wageRate, total_hours, total_overtimeHrs;
  58. float total_grossPay, total_stateTax, total_fedTax, total_netPay;
  59. } TOTALS;
  60.  
  61. typedef struct min_max {
  62. float min_wageRate, min_hours, min_overtimeHrs;
  63. float min_grossPay, min_stateTax, min_fedTax, min_netPay;
  64. float max_wageRate, max_hours, max_overtimeHrs;
  65. float max_grossPay, max_stateTax, max_fedTax, max_netPay;
  66. } MIN_MAX;
  67.  
  68. // prototypes
  69. EMPLOYEE * getEmpData(void);
  70. int isEmployeeSize(EMPLOYEE *);
  71. void calcOvertimeHrs(EMPLOYEE *);
  72. void calcGrossPay(EMPLOYEE *);
  73. void calcStateTax(EMPLOYEE *);
  74. void calcFedTax(EMPLOYEE *);
  75. void calcNetPay(EMPLOYEE *);
  76. void calcEmployeeTotals(EMPLOYEE *, TOTALS *);
  77. void calcEmployeeMinMax(EMPLOYEE *, MIN_MAX *);
  78. void printHeader(void);
  79. void printEmp(EMPLOYEE *);
  80. void printEmpStatistics(TOTALS *, MIN_MAX *, int);
  81.  
  82. //********************************************************
  83.  
  84. int main() {
  85. EMPLOYEE *head_ptr;
  86. int size;
  87.  
  88. TOTALS totals = {0};
  89. MIN_MAX minmax = {0};
  90.  
  91. head_ptr = getEmpData();
  92. size = isEmployeeSize(head_ptr);
  93.  
  94. if (size <= 0) {
  95. printf("\nNo data.\n");
  96. return 0;
  97. }
  98.  
  99. calcOvertimeHrs(head_ptr);
  100. calcGrossPay(head_ptr);
  101. calcStateTax(head_ptr);
  102. calcFedTax(head_ptr);
  103. calcNetPay(head_ptr);
  104.  
  105. calcEmployeeTotals(head_ptr, &totals);
  106. calcEmployeeMinMax(head_ptr, &minmax);
  107.  
  108. printHeader();
  109. printEmp(head_ptr);
  110. printEmpStatistics(&totals, &minmax, size);
  111.  
  112. printf("\n\n *** End of Program ***\n");
  113. return 0;
  114. }
  115.  
  116. //********************************************************
  117.  
  118. EMPLOYEE * getEmpData(void) {
  119. EMPLOYEE *head = NULL, *curr = NULL;
  120. char cont = 'y';
  121.  
  122. while (cont == 'y' || cont == 'Y') {
  123. EMPLOYEE *node = malloc(sizeof(EMPLOYEE));
  124.  
  125. printf("First name: "); scanf("%s", node->empName.firstName);
  126. printf("Last name: "); scanf("%s", node->empName.lastName);
  127. printf("State: "); scanf("%s", node->taxState);
  128. printf("Clock#: "); scanf("%li", &node->clockNumber);
  129. printf("Wage: "); scanf("%f", &node->wageRate);
  130. printf("Hours: "); scanf("%f", &node->hours);
  131.  
  132. node->next = NULL;
  133.  
  134. if (!head) head = node;
  135. else curr->next = node;
  136.  
  137. curr = node;
  138.  
  139. printf("Add another? (y/n): ");
  140. scanf(" %c", &cont);
  141. }
  142. return head;
  143. }
  144.  
  145. //********************************************************
  146.  
  147. int isEmployeeSize(EMPLOYEE *h) {
  148. int count = 0;
  149. while (h) { count++; h = h->next; }
  150. return count;
  151. }
  152.  
  153. //********************************************************
  154.  
  155. void calcOvertimeHrs(EMPLOYEE *h) {
  156. for (; h; h = h->next)
  157. h->overtimeHrs = CALC_OT_HOURS(h->hours);
  158. }
  159.  
  160. //********************************************************
  161.  
  162. void calcGrossPay(EMPLOYEE *h) {
  163. for (; h; h = h->next)
  164. h->grossPay =
  165. CALC_NORMAL_PAY(h->wageRate,h->hours,h->overtimeHrs) +
  166. CALC_OT_PAY(h->wageRate,h->overtimeHrs);
  167. }
  168.  
  169. //********************************************************
  170.  
  171. void calcStateTax(EMPLOYEE *h) {
  172. for (; h; h = h->next) {
  173. float rate = DEFAULT_STATE_TAX_RATE;
  174.  
  175. if (!strcmp(h->taxState,"MA")) rate = MA_TAX_RATE;
  176. else if (!strcmp(h->taxState,"VT")) rate = VT_TAX_RATE;
  177. else if (!strcmp(h->taxState,"NH")) rate = NH_TAX_RATE;
  178. else if (!strcmp(h->taxState,"CA")) rate = CA_TAX_RATE;
  179.  
  180. h->stateTax = CALC_STATE_TAX(h->grossPay, rate);
  181. }
  182. }
  183.  
  184. //********************************************************
  185.  
  186. void calcFedTax(EMPLOYEE *h) {
  187. for (; h; h = h->next)
  188. h->fedTax = CALC_FED_TAX(h->grossPay);
  189. }
  190.  
  191. //********************************************************
  192.  
  193. void calcNetPay(EMPLOYEE *h) {
  194. for (; h; h = h->next)
  195. h->netPay = CALC_NET_PAY(h->grossPay,h->stateTax,h->fedTax);
  196. }
  197.  
  198. //********************************************************
  199.  
  200. void calcEmployeeTotals(EMPLOYEE *h, TOTALS *t) {
  201. for (; h; h = h->next) {
  202. t->total_wageRate += h->wageRate;
  203. t->total_hours += h->hours;
  204. t->total_overtimeHrs += h->overtimeHrs;
  205. t->total_grossPay += h->grossPay;
  206. t->total_stateTax += h->stateTax;
  207. t->total_fedTax += h->fedTax;
  208. t->total_netPay += h->netPay;
  209. }
  210. }
  211.  
  212. //********************************************************
  213.  
  214. void calcEmployeeMinMax(EMPLOYEE *h, MIN_MAX *m) {
  215. *m = (MIN_MAX){
  216. h->wageRate,h->hours,h->overtimeHrs,h->grossPay,h->stateTax,h->fedTax,h->netPay,
  217. h->wageRate,h->hours,h->overtimeHrs,h->grossPay,h->stateTax,h->fedTax,h->netPay
  218. };
  219.  
  220. for (h = h->next; h; h = h->next) {
  221. m->min_wageRate = CALC_MIN(h->wageRate,m->min_wageRate);
  222. m->max_wageRate = CALC_MAX(h->wageRate,m->max_wageRate);
  223.  
  224. m->min_hours = CALC_MIN(h->hours,m->min_hours);
  225. m->max_hours = CALC_MAX(h->hours,m->max_hours);
  226.  
  227. m->min_overtimeHrs = CALC_MIN(h->overtimeHrs,m->min_overtimeHrs);
  228. m->max_overtimeHrs = CALC_MAX(h->overtimeHrs,m->max_overtimeHrs);
  229.  
  230. m->min_grossPay = CALC_MIN(h->grossPay,m->min_grossPay);
  231. m->max_grossPay = CALC_MAX(h->grossPay,m->max_grossPay);
  232.  
  233. m->min_stateTax = CALC_MIN(h->stateTax,m->min_stateTax);
  234. m->max_stateTax = CALC_MAX(h->stateTax,m->max_stateTax);
  235.  
  236. m->min_fedTax = CALC_MIN(h->fedTax,m->min_fedTax);
  237. m->max_fedTax = CALC_MAX(h->fedTax,m->max_fedTax);
  238.  
  239. m->min_netPay = CALC_MIN(h->netPay,m->min_netPay);
  240. m->max_netPay = CALC_MAX(h->netPay,m->max_netPay);
  241. }
  242. }
  243.  
  244. //********************************************************
  245.  
  246. void printHeader(void) {
  247. printf("\n*** Pay Calculator ***\n");
  248. }
  249.  
  250. //********************************************************
  251.  
  252. void printEmp(EMPLOYEE *h) {
  253. for (; h; h = h->next)
  254. printf("%s %s Net: %.2f\n",
  255. h->empName.firstName,
  256. h->empName.lastName,
  257. h->netPay);
  258. }
  259.  
  260. //********************************************************
  261.  
  262. void printEmpStatistics(TOTALS *t, MIN_MAX *m, int n) {
  263. printf("\nTotals Net: %.2f", t->total_netPay);
  264. printf("\nMin Net: %.2f", m->min_netPay);
  265. printf("\nMax Net: %.2f\n", m->max_netPay);
  266. }
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
First name: Last name: State: Clock#: Wage: Hours: Add another? (y/n): First name: Last name: State: Clock#: Wage: Hours: Add another? (y/n): First name: Last name: State: Clock#: Wage: Hours: Add another? (y/n): First name: Last name: State: Clock#: Wage: Hours: Add another? (y/n): First name: Last name: State: Clock#: Wage: Hours: Add another? (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 Net: 1624.19
Min Net: 227.12
Max Net: 419.23


 *** End of Program ***