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

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