fork download
  1. //********************************************************
  2. //
  3. // Assignment 9 - Linked Lists
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 7/27/2025
  10. //
  11. // Description: // Assignment 9 - Dynamically Allocated Linked Lists.
  12. //
  13. //
  14. // All functions are called by value
  15. //
  16. //********************************************************
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20.  
  21. // constants
  22. #define SIZE 5
  23. #define OVERTIME_RATE 1.5f
  24. #define STD_WORK_WEEK 40.0f
  25. #define TAX_STATE_SIZE 3
  26. #define FIRST_NAME_SIZE 10
  27. #define LAST_NAME_SIZE 10
  28.  
  29. // function prototypes
  30. struct name {
  31. char firstName[FIRST_NAME_SIZE];
  32. char lastName [LAST_NAME_SIZE];
  33. };
  34. struct employee {
  35. struct name empName;
  36. char taxState [TAX_STATE_SIZE];
  37. char include;
  38. long int clockNumber;
  39. float wageRate;
  40. float hours;
  41. float overtimeHrs;
  42. float grossPay;
  43. float stateTax;
  44. float fedTax;
  45. float netPay;
  46.  
  47. };
  48. struct totals {
  49. float total_wageRate;
  50. float total_hours;
  51. float total_overtimeHrs;
  52. float total_grossPay;
  53. float total_stateTax;
  54. float total_fedTax;
  55. float total_netPay;
  56. };
  57.  
  58. struct min_max {
  59. float min_wageRate;
  60. float min_hours;
  61. float min_overtimeHrs;
  62. float min_grossPay;
  63. float min_stateTax;
  64. float min_fedTax;
  65. float min_netPay;
  66. float max_wageRate;
  67. float max_hours;
  68. float max_overtimeHrs;
  69. float max_grossPay;
  70. float max_stateTax;
  71. float max_fedTax;
  72. float max_netPay;
  73. float stateTax;
  74. };
  75.  
  76. float getHours (long int clockNumber);
  77. void printHeader (void);
  78. void printEm(void);
  79. void printEmp(struct employee emp);
  80. void calcTaxes(struct employee *emp);
  81. void printSummary(struct employee empArr[], int size);
  82. float calcOvertimeHours(float hours);
  83. float calcGrossPay(float hours, float wageRate);
  84.  
  85. void calcEmployeeTotals (struct employee * emp_ptr, struct totals * emp_totals_ptr, int theSize);
  86. void calcEmployeeMinMax (struct employee * emp_ptr, struct min_max * emp_minMax_ptr, int theSize);
  87. void printEmpStatistics (struct totals * emp_totals_ptr, struct min_max * emp_minMax_ptr, int theSize);
  88.  
  89. int main() {
  90. int i;
  91. struct employee employeeData[SIZE];
  92. struct employee *emp_ptr = employeeData; // set the pointer to point to the array of employees
  93.  
  94.  
  95. // TODO: Add other function prototypes here as needed
  96.  
  97. struct totals employeeTotals = {0,0,0,0,0,0,0};
  98. struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  99. //struct totals * emp_totals_ptr = &employeeTotals;
  100. //struct min_max * emp_minMax_ptr = &employeeMinMax;
  101.  
  102. /* Variable Declarations */
  103. for (i = 0; i < SIZE; ++i) {
  104. scanf("%s", employeeData[i].empName.firstName);
  105. scanf("%s", employeeData[i].empName.lastName);
  106. scanf("%s", employeeData[i].taxState);
  107. scanf("%ld", &employeeData[i].clockNumber);
  108. scanf("%f", &employeeData[i].wageRate);
  109. scanf("%f", &employeeData[i].hours);
  110. scanf(" %c", &employeeData[i].include);
  111.  
  112. if (employeeData[i].include == 'N' || employeeData[i].include == 'n') {
  113. printf("Skipping Employee #%d as per input.\n", i + 1);
  114. employeeData[i].hours = 0.0f;
  115. }
  116. }
  117.  
  118.  
  119. // process each employee
  120. for (i = 0; i < SIZE; ++i) {
  121. // Read in hours for employee
  122. employeeData[i].hours = getHours(employeeData[i].clockNumber);
  123.  
  124.  
  125. // TODO: Function call to calculate gross pay
  126. employeeData[i].grossPay = calcGrossPay(employeeData[i].hours, employeeData[i].wageRate);
  127.  
  128.  
  129. // TODO: Function call to calculate overtime hours
  130. employeeData[i].overtimeHrs = calcOvertimeHours(employeeData[i].hours);
  131. calcTaxes(&employeeData[i]);
  132.  
  133. }
  134.  
  135. // print the header info
  136. printHeader();
  137.  
  138. // print out each employee
  139. for (i = 0; i < SIZE; ++i) {
  140. // Print all the employees - call by value
  141. printEmp(employeeData[i]);
  142. // for
  143. } // main
  144. printSummary(employeeData, SIZE);
  145. return (0);
  146.  
  147. }
  148.  
  149. //**************************************************************
  150. // Function: getHours
  151. //
  152. // Purpose: Obtains input from user, the number of hours worked
  153. // per employee and stores the result in a local variable
  154. // that is passed back to the calling function.
  155. //
  156. // Parameters: clockNumber - The unique employee ID
  157. //
  158. // Returns: hoursWorked - hours worked in a given week
  159. //
  160. //**************************************************************
  161.  
  162. float getHours (long int clockNumber) {
  163. float hoursWorked; // hours worked in a given week
  164. // Read in hours for employee
  165. if (clockNumber == 98401)
  166. hoursWorked = 51.0;
  167. else if (clockNumber == 526488)
  168. hoursWorked = 42.5;
  169. else if (clockNumber == 765349)
  170. hoursWorked = 37.0;
  171. else if (clockNumber == 34645)
  172. hoursWorked = 45.0;
  173. else if (clockNumber == 127615)
  174. hoursWorked = 40.0;
  175. else
  176. hoursWorked = 0.0;
  177.  
  178. printf("Enter hours worked by emp #%06ld: %.2f\n", clockNumber, hoursWorked);
  179.  
  180. return hoursWorked;
  181.  
  182. } // getHours
  183.  
  184. float calcOvertimeHours(float hours) {
  185. return (hours > STD_WORK_WEEK) ? (hours - STD_WORK_WEEK) : 0.0f;
  186.  
  187.  
  188. } // calcOvertimeHours
  189.  
  190. float calcGrossPay(float hours, float wageRate) {
  191. float overtime = calcOvertimeHours(hours);
  192. float regularHours = (hours > STD_WORK_WEEK) ? STD_WORK_WEEK : hours;
  193. return (regularHours * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  194. } // calcGrossPay
  195.  
  196.  
  197.  
  198. void calcTaxes(struct employee *emp) {
  199. if (strcmp(emp->taxState, "MA") == 0)
  200. emp->stateTax = emp->grossPay * 0.05f;
  201.  
  202. else if (strcmp(emp->taxState, "NH") == 0)
  203. emp->stateTax = 0.0f;
  204.  
  205. else if (strcmp(emp->taxState, "VT") == 0)
  206. emp->stateTax = emp->grossPay * 0.06f;
  207.  
  208. else if (strcmp(emp->taxState, "NY") == 0)
  209. emp->stateTax = emp->grossPay * 0.08f;
  210.  
  211. else if (strcmp(emp->taxState, "CA") == 0)
  212. emp->stateTax = emp->grossPay * 0.07f;
  213.  
  214. else
  215. emp->stateTax = 0.8f;
  216.  
  217. emp->fedTax = emp->grossPay * 0.25f;
  218. emp->netPay = emp->grossPay - (emp->stateTax + emp->fedTax);
  219. } // Calc Taxes
  220.  
  221.  
  222.  
  223.  
  224. //**************************************************************
  225. // Function: printHeader
  226. //
  227. // Purpose: Prints the initial table header information.
  228. //
  229. // Parameters: none
  230. //
  231. // Returns: void
  232. //
  233. //**************************************************************
  234.  
  235. void printHeader (void)
  236. {
  237. printf("\n-------------------------------------------------------------------------------------------------");
  238. printf ("\n\n*** Pay Calculator ***\n");
  239.  
  240. // print the table header
  241. printf("\nName St Clock# Wage Hours OT Gross StTax FedTax NetPay \n");
  242. printf("-------------------------------------------------------------------------------------------------\n");
  243.  
  244.  
  245.  
  246.  
  247.  
  248. } // printHeader
  249.  
  250. //*************************************************************
  251. // Function: printEmp
  252. //
  253. // Purpose: Prints out all the information for an employee
  254. // in a nice and orderly table format.
  255. //
  256. // Parameters:
  257. //
  258. // clockNumber - unique employee ID
  259. // wageRate - hourly wage rate
  260. // hours - Hours worked for the week
  261. // overtimeHrs - overtime hours worked in a week
  262. // grossPay - gross pay for the week
  263. //
  264. // Returns: void
  265. //
  266. //**************************************************************
  267.  
  268. void printEmp(struct employee emp) {
  269.  
  270.  
  271. printf("%-8s %-8s %-8s %06ld %6.2f %6.2f %6.2f %8.2f %7.2f %6.2f %8.2f\n",
  272. emp.empName.firstName, emp.empName.lastName, emp.taxState,
  273. emp.clockNumber, emp.wageRate, emp.hours,
  274. emp.overtimeHrs, emp.grossPay, emp.stateTax,
  275. emp.fedTax, emp.netPay);
  276.  
  277. }
  278. // TODO: Add other functions here as needed
  279. // ... remember your comment block headers for each function
  280.  
  281.  
  282.  
  283. void printSummary(struct employee empArr[], int size) {
  284. float totalWage = 0.0f;
  285. float totalHours = 0.0f;
  286. float totalOT = 0.0f;
  287. float totalGross = 0.0f;
  288. float totalStateTax = 0.0f;
  289. float totalFedTax = 0.0f;
  290. float totalNet = 0.0f;
  291.  
  292.  
  293. // Total Wage, Hours, OT, Groos, State tax, Fed Tax, Net
  294.  
  295. float minWage = empArr[0].wageRate;
  296. float maxWage = empArr[0].wageRate;
  297. float minHours = empArr[0].hours;
  298. float maxHours = empArr[0].hours;
  299. float minOT = empArr[0].overtimeHrs;
  300. float maxOT = empArr[0].overtimeHrs;
  301. float minGross = empArr[0].grossPay;
  302. float maxGross = empArr[0].grossPay;
  303. float minState = empArr[0].stateTax;
  304. float maxState = empArr[0].stateTax;
  305. float minFed = empArr[0].fedTax;
  306. float maxFed = empArr[0].fedTax;
  307. float minNet = empArr[0].netPay;
  308. float maxNet = empArr[0].netPay;
  309. //Min and Max of Wage, Hours, OT, Groos, State tax, Fed Tax, Net
  310.  
  311. for (int i = 0; i < size; i++) {
  312.  
  313. totalWage += empArr[i].wageRate;
  314. totalHours += empArr[i].hours;
  315. totalOT += empArr[i].overtimeHrs;
  316. totalGross += empArr[i].grossPay;
  317. totalStateTax += empArr[i].stateTax;
  318. totalFedTax += empArr[i].fedTax;
  319. totalNet += empArr[i].netPay;
  320.  
  321. // Calc total of Taxes of Wage, Hours, OT, Groos, State tax, Fed Tax, Net
  322.  
  323. if (empArr[i].wageRate < minWage)
  324. minWage = empArr[i].wageRate;
  325.  
  326. if (empArr[i].wageRate > maxWage)
  327. maxWage = empArr[i].wageRate;
  328.  
  329. if (empArr[i].hours < minHours)
  330. minHours = empArr[i].hours;
  331. if (empArr[i].hours > maxHours)
  332. maxHours = empArr[i].hours;
  333.  
  334. if (empArr[i].overtimeHrs < minOT)
  335. minOT = empArr[i].overtimeHrs;
  336. if (empArr[i].overtimeHrs > maxOT)
  337. maxOT = empArr[i].overtimeHrs;
  338.  
  339. if (empArr[i].grossPay < minGross)
  340. minGross = empArr[i].grossPay;
  341. if (empArr[i].grossPay > maxGross)
  342. maxGross = empArr[i].grossPay;
  343.  
  344. if (empArr[i].stateTax < minState)
  345. minState = empArr[i].stateTax;
  346. if (empArr[i].stateTax > maxState)
  347. maxState = empArr[i].stateTax;
  348.  
  349. if (empArr[i].fedTax < minFed)
  350. minFed = empArr[i].fedTax;
  351. if (empArr[i].fedTax > maxFed)
  352. maxFed = empArr[i].fedTax;
  353.  
  354. if (empArr[i].netPay < minNet)
  355. minNet = empArr[i].netPay;
  356. if (empArr[i].netPay > maxNet)
  357. maxNet = empArr[i].netPay;
  358.  
  359.  
  360. // Calc min and max Net Wage, Hours, OT, Groos, State tax, Fed Tax, Net
  361.  
  362.  
  363. }
  364.  
  365.  
  366. printf("\n-------------------------------------------------------------------------------------------------\n");
  367. printf("Total: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
  368. totalWage, totalHours, totalOT, totalGross, totalStateTax, totalFedTax, totalNet);
  369.  
  370. printf("Averages: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
  371. totalWage / size, totalHours / size, totalOT / size, totalGross / size,
  372. totalStateTax / size, totalFedTax / size, totalNet / size);
  373.  
  374. printf("Minimum: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
  375. minWage, minHours, minOT, minGross, minState, minFed, minNet);
  376. printf("Maximum: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
  377. maxWage, maxHours, maxOT, maxGross, maxState, maxFed, maxNet);
  378.  
  379. printf("\n-------------------------------------------------------------------------------------------------\n");
  380. }
  381.  
  382.  
  383.  
  384.  
  385.  
Success #stdin #stdout 0.01s 5288KB
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
Skipping Employee #5 as per input.
Enter hours worked by emp #098401: 51.00
Enter hours worked by emp #526488: 42.50
Enter hours worked by emp #765349: 37.00
Enter hours worked by emp #034645: 45.00
Enter hours worked by emp #127615: 40.00

-------------------------------------------------------------------------------------------------

*** Pay Calculator ***

Name 	          St	   Clock#   Wage    Hours    OT      Gross     StTax  FedTax    NetPay   
-------------------------------------------------------------------------------------------------
Connie   Cobol    MA       098401   10.60   51.00   11.00    598.90    29.95  149.73    419.23
Mary     Apl      NH       526488    9.75   42.50    2.50    426.56     0.00  106.64    319.92
Frank    Fortran  VT       765349   10.50   37.00    0.00    388.50    23.31   97.12    268.07
Jeff     Ada      NY       034645   12.25   45.00    5.00    581.88    46.55  145.47    389.86
Anton    Pascal   CA       127615    8.35   40.00    0.00    334.00    23.38   83.50    227.12

-------------------------------------------------------------------------------------------------
Total:                  		    51.45  215.50   18.50   2329.84   123.18  582.46   1624.19
Averages:               		    10.29   43.10    3.70    465.97    24.64  116.49    324.84
Minimum:                		     8.35   37.00    0.00    334.00     0.00   83.50    227.12
Maximum:                      	    12.25   51.00   11.00    598.90    46.55  149.73    419.23

-------------------------------------------------------------------------------------------------