fork download
  1. //********************************************************
  2. //
  3. // Assignment 8 - Pointers
  4. //
  5. // Name: Seth Hin
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: April 04 2026
  10. //
  11. // Description: Program which determines overtime, gross pay,
  12. // state tax, federal tax, and net pay for a set of employees.
  13. // It also calculates totals, averages, minimum, and maximum
  14. // values for all floating point employee data.
  15. //
  16. //********************************************************
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <ctype.h>
  21.  
  22. //---------------- CONSTANTS ----------------//
  23. #define SIZE 5
  24. #define STD_HOURS 40.0
  25. #define OT_RATE 1.5
  26. #define MA_TAX_RATE 0.05
  27. #define NH_TAX_RATE 0.0
  28. #define VT_TAX_RATE 0.06
  29. #define CA_TAX_RATE 0.07
  30. #define DEFAULT_TAX_RATE 0.08
  31. #define TAX_STATE_SIZE 3
  32. #define FED_TAX_RATE 0.25
  33. #define FIRST_NAME_SIZE 10
  34. #define LAST_NAME_SIZE 10
  35.  
  36. //---------------- STRUCTURES ----------------//
  37. struct name
  38. {
  39. char firstName[FIRST_NAME_SIZE];
  40. char lastName[LAST_NAME_SIZE];
  41. };
  42.  
  43. struct employee
  44. {
  45. struct name empName;
  46. char taxState[TAX_STATE_SIZE];
  47. long int clockNumber;
  48. float wageRate;
  49. float hours;
  50. float overtimeHrs;
  51. float grossPay;
  52. float stateTax;
  53. float fedTax;
  54. float netPay;
  55. };
  56.  
  57. struct totals
  58. {
  59. float total_wageRate;
  60. float total_hours;
  61. float total_overtimeHrs;
  62. float total_grossPay;
  63. float total_stateTax;
  64. float total_fedTax;
  65. float total_netPay;
  66. };
  67.  
  68. struct min_max
  69. {
  70. float min_wageRate, min_hours, min_overtimeHrs, min_grossPay, min_stateTax, min_fedTax, min_netPay;
  71. float max_wageRate, max_hours, max_overtimeHrs, max_grossPay, max_stateTax, max_fedTax, max_netPay;
  72. };
  73.  
  74. //---------------- FUNCTION PROTOTYPES ----------------//
  75. void getHours(struct employee *, int);
  76. void calcOvertimeHrs(struct employee *, int);
  77. void calcGrossPay(struct employee *, int);
  78. void calcStateTax(struct employee *, int);
  79. void calcFedTax(struct employee *, int);
  80. void calcNetPay(struct employee *, int);
  81. void printHeader(void);
  82. void printEmp(struct employee *, int);
  83. void calcEmployeeTotals(struct employee *, struct totals *, int);
  84. void calcEmployeeMinMax(struct employee *, struct min_max *, int);
  85. void printEmpStatistics(struct totals *, struct min_max *, int);
  86.  
  87. //---------------- MAIN ----------------//
  88. int main()
  89. {
  90. struct employee employeeData[SIZE] = {
  91. { {"Connie", "Cobol"}, "MA", 98401, 10.60},
  92. { {"Mary", "Apl"}, "NH", 526488, 9.75 },
  93. { {"Frank", "Fortran"}, "VT", 765349, 10.50 },
  94. { {"Jeff", "Ada"}, "NY", 34645, 12.25 },
  95. { {"Anton", "Pascal"},"CA",127615, 8.35 }
  96. };
  97.  
  98. struct employee *emp_ptr;
  99. emp_ptr = employeeData;
  100.  
  101. struct totals employeeTotals = {0};
  102. struct totals *emp_totals_ptr = &employeeTotals;
  103.  
  104. struct min_max employeeMinMax = {0};
  105. struct min_max *emp_minMax_ptr = &employeeMinMax;
  106.  
  107. getHours(emp_ptr, SIZE);
  108. calcOvertimeHrs(emp_ptr, SIZE);
  109. calcGrossPay(emp_ptr, SIZE);
  110. calcStateTax(emp_ptr, SIZE);
  111. calcFedTax(emp_ptr, SIZE);
  112. calcNetPay(emp_ptr, SIZE);
  113.  
  114. calcEmployeeTotals(emp_ptr, emp_totals_ptr, SIZE);
  115. calcEmployeeMinMax(emp_ptr, emp_minMax_ptr, SIZE);
  116.  
  117. printHeader();
  118. printEmp(emp_ptr, SIZE);
  119. printEmpStatistics(emp_totals_ptr, emp_minMax_ptr, SIZE);
  120.  
  121. return 0;
  122. }
  123.  
  124. //**************************************************************
  125. // Function: getHours
  126. // Purpose: Reads hours worked
  127. // Parameters: emp_ptr (pointer), size
  128. //**************************************************************
  129. void getHours(struct employee *emp_ptr, int size)
  130. {
  131. for (int i = 0; i < size; i++)
  132. {
  133. printf("\nEnter hours worked by emp # %06li: ", emp_ptr[i].clockNumber);
  134. scanf("%f", &emp_ptr[i].hours);
  135. }
  136. }
  137.  
  138. //**************************************************************
  139. void calcOvertimeHrs(struct employee *emp_ptr, int size)
  140. {
  141. for (int i = 0; i < size; i++)
  142. {
  143. if (emp_ptr[i].hours > STD_HOURS)
  144. emp_ptr[i].overtimeHrs = emp_ptr[i].hours - STD_HOURS;
  145. else
  146. emp_ptr[i].overtimeHrs = 0;
  147. }
  148. }
  149.  
  150. //**************************************************************
  151. void calcGrossPay(struct employee *emp_ptr, int size)
  152. {
  153. for (int i = 0; i < size; i++)
  154. {
  155. float normal = (emp_ptr[i].hours - emp_ptr[i].overtimeHrs) * emp_ptr[i].wageRate;
  156. float overtime = emp_ptr[i].overtimeHrs * OT_RATE * emp_ptr[i].wageRate;
  157. emp_ptr[i].grossPay = normal + overtime;
  158. }
  159. }
  160.  
  161. //**************************************************************
  162. void calcStateTax(struct employee *emp_ptr, int size)
  163. {
  164. for (int i = 0; i < size; i++)
  165. {
  166. if (strcmp(emp_ptr[i].taxState, "MA") == 0)
  167. emp_ptr[i].stateTax = emp_ptr[i].grossPay * MA_TAX_RATE;
  168. else if (strcmp(emp_ptr[i].taxState, "NH") == 0)
  169. emp_ptr[i].stateTax = emp_ptr[i].grossPay * NH_TAX_RATE;
  170. else if (strcmp(emp_ptr[i].taxState, "VT") == 0)
  171. emp_ptr[i].stateTax = emp_ptr[i].grossPay * VT_TAX_RATE;
  172. else if (strcmp(emp_ptr[i].taxState, "CA") == 0)
  173. emp_ptr[i].stateTax = emp_ptr[i].grossPay * CA_TAX_RATE;
  174. else
  175. emp_ptr[i].stateTax = emp_ptr[i].grossPay * DEFAULT_TAX_RATE;
  176. }
  177. }
  178.  
  179. //**************************************************************
  180. void calcFedTax(struct employee *emp_ptr, int size)
  181. {
  182. for (int i = 0; i < size; i++)
  183. {
  184. emp_ptr[i].fedTax = emp_ptr[i].grossPay * FED_TAX_RATE;
  185. }
  186. }
  187.  
  188. //**************************************************************
  189. void calcNetPay(struct employee *emp_ptr, int size)
  190. {
  191. for (int i = 0; i < size; i++)
  192. {
  193. emp_ptr[i].netPay = emp_ptr[i].grossPay - (emp_ptr[i].stateTax + emp_ptr[i].fedTax);
  194. }
  195. }
  196.  
  197. //**************************************************************
  198. void printHeader(void)
  199. {
  200. printf("\n\n*** Pay Calculator ***\n");
  201. printf("\n---------------------------------------------------------------------------------");
  202. printf("\nName Tax Clock# Wage Hours OT Gross State Fed Net");
  203. printf("\n State Pay Tax Tax Pay");
  204. printf("\n---------------------------------------------------------------------------------");
  205. }
  206.  
  207. //**************************************************************
  208. void printEmp(struct employee *emp_ptr, int size)
  209. {
  210. char name[25];
  211.  
  212. for (int i = 0; i < size; i++)
  213. {
  214. strcpy(name, emp_ptr[i].empName.firstName);
  215. strcat(name, " ");
  216. strcat(name, emp_ptr[i].empName.lastName);
  217.  
  218. printf("\n%-20s %-2s %06li %6.2f %6.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  219. name, emp_ptr[i].taxState, emp_ptr[i].clockNumber,
  220. emp_ptr[i].wageRate, emp_ptr[i].hours,
  221. emp_ptr[i].overtimeHrs, emp_ptr[i].grossPay,
  222. emp_ptr[i].stateTax, emp_ptr[i].fedTax,
  223. emp_ptr[i].netPay);
  224. }
  225. }
  226.  
  227. //**************************************************************
  228. void calcEmployeeTotals(struct employee *emp_ptr, struct totals *tot_ptr, int size)
  229. {
  230. for (int i = 0; i < size; i++)
  231. {
  232. tot_ptr->total_wageRate += emp_ptr[i].wageRate;
  233. tot_ptr->total_hours += emp_ptr[i].hours;
  234. tot_ptr->total_overtimeHrs += emp_ptr[i].overtimeHrs;
  235. tot_ptr->total_grossPay += emp_ptr[i].grossPay;
  236. tot_ptr->total_stateTax += emp_ptr[i].stateTax;
  237. tot_ptr->total_fedTax += emp_ptr[i].fedTax;
  238. tot_ptr->total_netPay += emp_ptr[i].netPay;
  239. }
  240. }
  241.  
  242. //**************************************************************
  243. void calcEmployeeMinMax(struct employee *emp_ptr, struct min_max *m, int size)
  244. {
  245. *m = (struct min_max){
  246. emp_ptr[0].wageRate, emp_ptr[0].hours, emp_ptr[0].overtimeHrs, emp_ptr[0].grossPay, emp_ptr[0].stateTax, emp_ptr[0].fedTax, emp_ptr[0].netPay,
  247. emp_ptr[0].wageRate, emp_ptr[0].hours, emp_ptr[0].overtimeHrs, emp_ptr[0].grossPay, emp_ptr[0].stateTax, emp_ptr[0].fedTax, emp_ptr[0].netPay
  248. };
  249.  
  250. for (int i = 1; i < size; i++)
  251. {
  252. if (emp_ptr[i].wageRate < m->min_wageRate) m->min_wageRate = emp_ptr[i].wageRate;
  253. if (emp_ptr[i].wageRate > m->max_wageRate) m->max_wageRate = emp_ptr[i].wageRate;
  254.  
  255. if (emp_ptr[i].hours < m->min_hours) m->min_hours = emp_ptr[i].hours;
  256. if (emp_ptr[i].hours > m->max_hours) m->max_hours = emp_ptr[i].hours;
  257.  
  258. if (emp_ptr[i].overtimeHrs < m->min_overtimeHrs) m->min_overtimeHrs = emp_ptr[i].overtimeHrs;
  259. if (emp_ptr[i].overtimeHrs > m->max_overtimeHrs) m->max_overtimeHrs = emp_ptr[i].overtimeHrs;
  260.  
  261. if (emp_ptr[i].grossPay < m->min_grossPay) m->min_grossPay = emp_ptr[i].grossPay;
  262. if (emp_ptr[i].grossPay > m->max_grossPay) m->max_grossPay = emp_ptr[i].grossPay;
  263.  
  264. if (emp_ptr[i].stateTax < m->min_stateTax) m->min_stateTax = emp_ptr[i].stateTax;
  265. if (emp_ptr[i].stateTax > m->max_stateTax) m->max_stateTax = emp_ptr[i].stateTax;
  266.  
  267. if (emp_ptr[i].fedTax < m->min_fedTax) m->min_fedTax = emp_ptr[i].fedTax;
  268. if (emp_ptr[i].fedTax > m->max_fedTax) m->max_fedTax = emp_ptr[i].fedTax;
  269.  
  270. if (emp_ptr[i].netPay < m->min_netPay) m->min_netPay = emp_ptr[i].netPay;
  271. if (emp_ptr[i].netPay > m->max_netPay) m->max_netPay = emp_ptr[i].netPay;
  272. }
  273. }
  274.  
  275. //**************************************************************
  276. void printEmpStatistics(struct totals *t, struct min_max *m, int size)
  277. {
  278. printf("\n---------------------------------------------------------------------------------");
  279.  
  280. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  281. t->total_wageRate, t->total_hours, t->total_overtimeHrs,
  282. t->total_grossPay, t->total_stateTax, t->total_fedTax, t->total_netPay);
  283.  
  284. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  285. t->total_wageRate/size, t->total_hours/size, t->total_overtimeHrs/size,
  286. t->total_grossPay/size, t->total_stateTax/size, t->total_fedTax/size, t->total_netPay/size);
  287.  
  288. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  289. m->min_wageRate, m->min_hours, m->min_overtimeHrs,
  290. m->min_grossPay, m->min_stateTax, m->min_fedTax, m->min_netPay);
  291.  
  292. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f\n",
  293. m->max_wageRate, m->max_hours, m->max_overtimeHrs,
  294. m->max_grossPay, m->max_stateTax, m->max_fedTax, m->max_netPay);
  295. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
40.0
stdout
Enter hours worked by emp # 098401: 
Enter hours worked by emp # 526488: 
Enter hours worked by emp # 765349: 
Enter hours worked by emp # 034645: 
Enter hours worked by emp # 127615: 

*** 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