fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays and Structures
  4. //
  5. // Name: John Semenuk
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 29-Mar-2026
  10. //
  11. // Description: Program calculates pay for employees, including
  12. // overtime, taxes, and tracks totals, averages, min, and max.
  13. //
  14. //********************************************************
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #define SIZE 5
  20. #define FIRST_NAME_SIZE 15
  21. #define LAST_NAME_SIZE 15
  22. #define STATE_SIZE 3
  23.  
  24. // Employee structure
  25. struct employee {
  26. char firstName[FIRST_NAME_SIZE];
  27. char lastName[LAST_NAME_SIZE];
  28. char state[STATE_SIZE];
  29. long int clockNumber;
  30. float wageRate;
  31. float hours;
  32. float overtimeHrs;
  33. float grossPay;
  34. float stateTax;
  35. float fedTax;
  36. float netPay;
  37. };
  38.  
  39. // Totals structure
  40. struct totals {
  41. float total_wageRate;
  42. float total_hours;
  43. float total_overtimeHrs;
  44. float total_grossPay;
  45. float total_stateTax;
  46. float total_fedTax;
  47. float total_netPay;
  48. };
  49.  
  50. // Min/Max structure
  51. struct min_max {
  52. float min_wageRate;
  53. float max_wageRate;
  54. float min_hours;
  55. float max_hours;
  56. float min_overtimeHrs;
  57. float max_overtimeHrs;
  58. float min_grossPay;
  59. float max_grossPay;
  60. float min_stateTax;
  61. float max_stateTax;
  62. float min_fedTax;
  63. float max_fedTax;
  64. float min_netPay;
  65. float max_netPay;
  66. };
  67.  
  68. // Function prototypes
  69. void printHeader(void);
  70. void printEmp(char[], char[], char[], long int, float, float, float, float, float, float, float);
  71. void printEmpStatistics(struct totals, struct min_max, int);
  72. void updateTotals(struct totals *, struct employee);
  73. void updateMinMax(struct min_max *, struct employee);
  74.  
  75. int main() {
  76. struct employee empList[SIZE];
  77. struct totals totalStats = {0};
  78. struct min_max minMaxStats = {0};
  79. int i;
  80.  
  81. // Sample input for demonstration
  82. char firstNames[SIZE][FIRST_NAME_SIZE] = {"John", "Alice", "Mark", "Laura", "James"};
  83. char lastNames[SIZE][LAST_NAME_SIZE] = {"Smith", "Brown", "Taylor", "Wilson", "Kirk"};
  84. char states[SIZE][STATE_SIZE] = {"IA","CA","NY","TX","FL"};
  85. long clocks[SIZE] = {100001, 100002, 100003, 100004, 100005};
  86. float wages[SIZE] = {20.0, 25.0, 22.5, 30.0, 28.0};
  87. float hoursWorked[SIZE] = {40.0, 45.0, 38.0, 50.0, 42.5};
  88.  
  89. // Input loop and calculations
  90. for(i=0; i<SIZE; i++) {
  91. strcpy(empList[i].firstName, firstNames[i]);
  92. strcpy(empList[i].lastName, lastNames[i]);
  93. strcpy(empList[i].state, states[i]);
  94. empList[i].clockNumber = clocks[i];
  95. empList[i].wageRate = wages[i];
  96. empList[i].hours = hoursWorked[i];
  97. empList[i].overtimeHrs = (hoursWorked[i] > 40) ? hoursWorked[i] - 40 : 0;
  98. empList[i].grossPay = (hoursWorked[i] <= 40) ? wages[i] * hoursWorked[i] : wages[i]*40 + wages[i]*1.5*empList[i].overtimeHrs;
  99. empList[i].stateTax = empList[i].grossPay * 0.05f; // 5% state tax
  100. empList[i].fedTax = empList[i].grossPay * 0.15f; // 15% federal tax
  101. empList[i].netPay = empList[i].grossPay - empList[i].stateTax - empList[i].fedTax;
  102.  
  103. // Update totals and min/max
  104. updateTotals(&totalStats, empList[i]);
  105. updateMinMax(&minMaxStats, empList[i]);
  106. }
  107.  
  108. // Print
  109. printHeader();
  110. for(i=0; i<SIZE; i++)
  111. printEmp(empList[i].firstName, empList[i].lastName, empList[i].state, empList[i].clockNumber,
  112. empList[i].wageRate, empList[i].hours, empList[i].overtimeHrs, empList[i].grossPay,
  113. empList[i].stateTax, empList[i].fedTax, empList[i].netPay);
  114.  
  115. printEmpStatistics(totalStats, minMaxStats, SIZE);
  116.  
  117. return 0;
  118. }
  119.  
  120. // Function definitions
  121. void printHeader(void) {
  122. printf("\n\n*** Pay Calculator ***\n");
  123. printf("--------------------------------------------------------------------\n");
  124. printf("Name Tax Clock# Wage Hours OT Gross State Fed Net\n");
  125. printf("--------------------------------------------------------------------\n");
  126. }
  127.  
  128. void printEmp(char firstName[], char lastName[], char taxState[], long int clockNumber, float wageRate,
  129. float hours, float overtimeHrs, float grossPay, float stateTax, float fedTax, float netPay) {
  130.  
  131. char name[FIRST_NAME_SIZE + LAST_NAME_SIZE + 2];
  132. strcpy(name, firstName);
  133. strcat(name, " ");
  134. strcat(name, lastName);
  135.  
  136. printf("%-20.20s %-2.2s %06li %6.2f %5.1f %4.1f %7.2f %6.2f %7.2f %8.2f\n",
  137. name, taxState, clockNumber, wageRate, hours, overtimeHrs, grossPay, stateTax, fedTax, netPay);
  138. }
  139.  
  140. void updateTotals(struct totals *totalsPtr, struct employee emp) {
  141. totalsPtr->total_wageRate += emp.wageRate;
  142. totalsPtr->total_hours += emp.hours;
  143. totalsPtr->total_overtimeHrs += emp.overtimeHrs;
  144. totalsPtr->total_grossPay += emp.grossPay;
  145. totalsPtr->total_stateTax += emp.stateTax;
  146. totalsPtr->total_fedTax += emp.fedTax;
  147. totalsPtr->total_netPay += emp.netPay;
  148. }
  149.  
  150. void updateMinMax(struct min_max *minMaxPtr, struct employee emp) {
  151. static int firstCall = 1;
  152.  
  153. if(firstCall) {
  154. minMaxPtr->min_wageRate = minMaxPtr->max_wageRate = emp.wageRate;
  155. minMaxPtr->min_hours = minMaxPtr->max_hours = emp.hours;
  156. minMaxPtr->min_overtimeHrs = minMaxPtr->max_overtimeHrs = emp.overtimeHrs;
  157. minMaxPtr->min_grossPay = minMaxPtr->max_grossPay = emp.grossPay;
  158. minMaxPtr->min_stateTax = minMaxPtr->max_stateTax = emp.stateTax;
  159. minMaxPtr->min_fedTax = minMaxPtr->max_fedTax = emp.fedTax;
  160. minMaxPtr->min_netPay = minMaxPtr->max_netPay = emp.netPay;
  161. firstCall = 0;
  162. return;
  163. }
  164.  
  165. if(emp.wageRate < minMaxPtr->min_wageRate) minMaxPtr->min_wageRate = emp.wageRate;
  166. if(emp.wageRate > minMaxPtr->max_wageRate) minMaxPtr->max_wageRate = emp.wageRate;
  167.  
  168. if(emp.hours < minMaxPtr->min_hours) minMaxPtr->min_hours = emp.hours;
  169. if(emp.hours > minMaxPtr->max_hours) minMaxPtr->max_hours = emp.hours;
  170.  
  171. if(emp.overtimeHrs < minMaxPtr->min_overtimeHrs) minMaxPtr->min_overtimeHrs = emp.overtimeHrs;
  172. if(emp.overtimeHrs > minMaxPtr->max_overtimeHrs) minMaxPtr->max_overtimeHrs = emp.overtimeHrs;
  173.  
  174. if(emp.grossPay < minMaxPtr->min_grossPay) minMaxPtr->min_grossPay = emp.grossPay;
  175. if(emp.grossPay > minMaxPtr->max_grossPay) minMaxPtr->max_grossPay = emp.grossPay;
  176.  
  177. if(emp.stateTax < minMaxPtr->min_stateTax) minMaxPtr->min_stateTax = emp.stateTax;
  178. if(emp.stateTax > minMaxPtr->max_stateTax) minMaxPtr->max_stateTax = emp.stateTax;
  179.  
  180. if(emp.fedTax < minMaxPtr->min_fedTax) minMaxPtr->min_fedTax = emp.fedTax;
  181. if(emp.fedTax > minMaxPtr->max_fedTax) minMaxPtr->max_fedTax = emp.fedTax;
  182.  
  183. if(emp.netPay < minMaxPtr->min_netPay) minMaxPtr->min_netPay = emp.netPay;
  184. if(emp.netPay > minMaxPtr->max_netPay) minMaxPtr->max_netPay = emp.netPay;
  185. }
  186.  
  187. void printEmpStatistics(struct totals totalsData, struct min_max minMaxData, int theSize) {
  188. printf("--------------------------------------------------------------------\n");
  189.  
  190. // Totals
  191. printf("%-20s %6s %6.2f %5.1f %4.1f %7.2f %6.2f %7.2f %8.2f\n",
  192. "Totals:", "",
  193. totalsData.total_wageRate,
  194. totalsData.total_hours,
  195. totalsData.total_overtimeHrs,
  196. totalsData.total_grossPay,
  197. totalsData.total_stateTax,
  198. totalsData.total_fedTax,
  199. totalsData.total_netPay);
  200.  
  201. // Averages
  202. if(theSize > 0) {
  203. printf("%-20s %6s %6.2f %5.1f %4.1f %7.2f %6.2f %7.2f %8.2f\n",
  204. "Averages:", "",
  205. totalsData.total_wageRate/theSize,
  206. totalsData.total_hours/theSize,
  207. totalsData.total_overtimeHrs/theSize,
  208. totalsData.total_grossPay/theSize,
  209. totalsData.total_stateTax/theSize,
  210. totalsData.total_fedTax/theSize,
  211. totalsData.total_netPay/theSize);
  212. }
  213.  
  214. // Minimums
  215. printf("%-20s %6s %6.2f %5.1f %4.1f %7.2f %6.2f %7.2f %8.2f\n",
  216. "Minimum:", "",
  217. minMaxData.min_wageRate,
  218. minMaxData.min_hours,
  219. minMaxData.min_overtimeHrs,
  220. minMaxData.min_grossPay,
  221. minMaxData.min_stateTax,
  222. minMaxData.min_fedTax,
  223. minMaxData.min_netPay);
  224.  
  225. // Maximums
  226. printf("%-20s %6s %6.2f %5.1f %4.1f %7.2f %6.2f %7.2f %8.2f\n",
  227. "Maximum:", "",
  228. minMaxData.max_wageRate,
  229. minMaxData.max_hours,
  230. minMaxData.max_overtimeHrs,
  231. minMaxData.max_grossPay,
  232. minMaxData.max_stateTax,
  233. minMaxData.max_fedTax,
  234. minMaxData.max_netPay);
  235.  
  236. printf("--------------------------------------------------------------------\n");
  237. }
Success #stdin #stdout 0s 5324KB
stdin
 51.0   
 42.5
 37.0
 45.0
 40.0
stdout

*** Pay Calculator ***
--------------------------------------------------------------------
Name                 Tax  Clock#  Wage   Hours   OT    Gross   State   Fed     Net
--------------------------------------------------------------------
John Smith           IA  100001  20.00   40.0   0.0  800.00  40.00  120.00   640.00
Alice Brown          CA  100002  25.00   45.0   5.0 1187.50  59.38  178.12   950.00
Mark Taylor          NY  100003  22.50   38.0   0.0  855.00  42.75  128.25   684.00
Laura Wilson         TX  100004  30.00   50.0  10.0 1650.00  82.50  247.50  1320.00
James Kirk           FL  100005  28.00   42.5   2.5 1225.00  61.25  183.75   980.00
--------------------------------------------------------------------
Totals:                           125.50 215.5 17.5 5717.50 285.88  857.62  4574.00
Averages:                          25.10  43.1  3.5 1143.50  57.17  171.52   914.80
Minimum:                           20.00  38.0  0.0  800.00  40.00  120.00   640.00
Maximum:                           30.00  50.0 10.0 1650.00  82.50  247.50  1320.00
--------------------------------------------------------------------