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

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