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

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