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

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