fork(1) download
  1. ///********************************************************
  2. //
  3. // Assignment 6 - Functions
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 7/19/2025
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. // All functions are called by value
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22.  
  23. // constants
  24. #define SIZE 5
  25. #define OVERTIME_RATE 1.5f
  26. #define STD_WORK_WEEK 40.0f
  27.  
  28. // function prototypes
  29. struct name {
  30. char firstName [10];
  31. char lastName [10];
  32. };
  33.  
  34. struct employee {
  35. struct name empName;
  36. char state[3];
  37. long int clockNumber;
  38. float wageRate;
  39. float hours;
  40. float overtimeHrs;
  41. float grossPay;
  42. float stateTax;
  43. float fedTax;
  44. float netPay;
  45. };
  46.  
  47. int main() {
  48.  
  49. float getHours (long int clockNumber);
  50. void printHeader (void);
  51. void printEmp(struct employee emp);
  52. void printSummary(struct employee empArr[], int size);
  53. float calcOvertimeHours(float hours);
  54. float calcGrossPay(float hours, float wageRate);
  55.  
  56. int i;
  57. void calcTaxes(struct employee *emp);
  58.  
  59.  
  60. // TODO: Add other function prototypes here as needed
  61.  
  62. struct employee emp[SIZE] = {
  63. {{"Connie", "Cobol"}, "MA", 98401, 10.60},
  64. {{"Mary", "Apl",}, "NH", 526488, 9.75},
  65. {{"Frank", "Fortran"}, "VT", 765349, 10.5},
  66. {{"Jeff", "Ada"}, "NY", 34645, 12.25},
  67. {{"Anton", "Pascal"}, "CA", 127615, 8.35}
  68. };
  69.  
  70.  
  71. /* Variable Declarations */
  72.  
  73.  
  74. // process each employee
  75. for (i = 0; i < SIZE; ++i) {
  76. // Read in hours for employee
  77. emp[i].hours = getHours(emp[i].clockNumber);
  78.  
  79. // TODO: Function call to calculate gross pay
  80. emp[i].overtimeHrs = calcOvertimeHours(emp[i].hours);
  81.  
  82. // TODO: Function call to calculate overtime hours
  83. emp[i].grossPay = calcGrossPay(emp[i].hours, emp[i].wageRate);
  84.  
  85. //Calculate Taxes
  86. calcTaxes(&emp[i]);
  87. };
  88.  
  89. // print the header info
  90. printHeader();
  91.  
  92. // print out each employee
  93. for (i = 0; i < SIZE; ++i) {
  94. // Print all the employees - call by value
  95. printEmp(emp[i]);
  96. };
  97. printSummary(emp, SIZE);
  98. // main
  99. return (0);
  100. }
  101.  
  102. //**************************************************************
  103. // Function: getHours
  104. //
  105. // Purpose: Obtains input from user, the number of hours worked
  106. // per employee and stores the result in a local variable
  107. // that is passed back to the calling function.
  108. //
  109. // Parameters: clockNumber - The unique employee ID
  110. //
  111. // Returns: hoursWorked - hours worked in a given week
  112. //
  113. //**************************************************************
  114.  
  115. float getHours (long int clockNumber) {
  116. float hoursWorked; // hours worked in a given week
  117. // Read in hours for employee
  118. if (clockNumber == 98401)
  119. hoursWorked = 51.0;
  120. else if (clockNumber == 526488)
  121. hoursWorked = 42.5;
  122. else if (clockNumber == 765349)
  123. hoursWorked = 37.0;
  124. else if (clockNumber == 34645)
  125. hoursWorked = 45.0;
  126. else if (clockNumber == 127615)
  127. hoursWorked = 40.0;
  128. else
  129. hoursWorked = 0.0;
  130.  
  131. printf("Enter hours worked by emp #%06ld: %.2f\n", clockNumber, hoursWorked);
  132.  
  133. return hoursWorked;
  134.  
  135. } // getHours
  136.  
  137. float calcOvertimeHours(float hours) {
  138. return (hours > STD_WORK_WEEK) ? (hours - STD_WORK_WEEK) : 0.0f;
  139.  
  140.  
  141. } // calcOvertimeHours
  142.  
  143. float calcGrossPay(float hours, float wageRate) {
  144. float overtime = calcOvertimeHours(hours);
  145. float regularHours = (hours > STD_WORK_WEEK) ? STD_WORK_WEEK : hours;
  146. return (regularHours * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  147. } // calcGrossPay
  148.  
  149.  
  150. void calcTaxes(struct employee *emp) {
  151. if (strcmp(emp->state, "MA") == 0)
  152. emp->stateTax = emp->grossPay * 0.05f;
  153.  
  154. else if (strcmp(emp->state, "NH") == 0)
  155. emp->stateTax = 0.0f;
  156.  
  157. else if (strcmp(emp->state, "VT") == 0)
  158. emp->stateTax = emp->grossPay * 0.06f;
  159.  
  160. else if (strcmp(emp->state, "NY") == 0)
  161. emp->stateTax = emp->grossPay * 0.08f;
  162.  
  163. else if (strcmp(emp->state, "CA") == 0)
  164. emp->stateTax = emp->grossPay * 0.07f;
  165.  
  166. else
  167. emp->stateTax = 0.8f;
  168.  
  169. emp->fedTax = emp->grossPay * 0.25f;
  170. emp->netPay = emp->grossPay - (emp->stateTax + emp->fedTax);
  171. }; // Calc Taxes
  172.  
  173.  
  174.  
  175.  
  176. //**************************************************************
  177. // Function: printHeader
  178. //
  179. // Purpose: Prints the initial table header information.
  180. //
  181. // Parameters: none
  182. //
  183. // Returns: void
  184. //
  185. //**************************************************************
  186.  
  187. void printHeader (void) {
  188. printf("\n-------------------------------------------------------------------------------------------------");
  189. printf ("\n\n*** Pay Calculator ***\n");
  190.  
  191. // print the table header
  192. printf("\nName St Clock# Wage Hours OT Gross StTax FedTax NetPay \n");
  193. printf("-------------------------------------------------------------------------------------------------\n");
  194.  
  195.  
  196. } // printHeader
  197.  
  198. //*************************************************************
  199. // Function: printEmp
  200. //
  201. // Purpose: Prints out all the information for an employee
  202. // in a nice and orderly table format.
  203. //
  204. // Parameters:
  205. //
  206. // clockNumber - unique employee ID
  207. // wageRate - hourly wage rate
  208. // hours - Hours worked for the week
  209. // overtimeHrs - overtime hours worked in a week
  210. // grossPay - gross pay for the week
  211. //
  212. // Returns: void
  213. //
  214. //**************************************************************
  215.  
  216. void printEmp(struct employee emp) {
  217.  
  218. printf("%-8s %-8s %-3s %06ld %6.2f %6.2f %6.2f %8.2f %7.2f %6.2f %8.2f\n",
  219. emp.empName.firstName, emp.empName.lastName, emp.state,
  220. emp.clockNumber, emp.wageRate, emp.hours,
  221. emp.overtimeHrs, emp.grossPay, emp.stateTax,
  222. emp.fedTax, emp.netPay);
  223. };
  224.  
  225.  
  226. void printSummary(struct employee empArr[], int size) {
  227. float totalWage = 0.0f;
  228. float totalHours = 0.0f;
  229. float totalOT = 0.0f;
  230. float totalGross = 0.0f;
  231. float totalStateTax = 0.0f;
  232. float totalFedTax = 0.0f;
  233. float totalNet = 0.0f;
  234.  
  235. for (int i = 0; i < size; i++) {
  236. totalWage += empArr[i].wageRate;
  237. totalHours += empArr[i].hours;
  238. totalOT += empArr[i].overtimeHrs;
  239. totalGross += empArr[i].grossPay;
  240. totalStateTax += empArr[i].stateTax;
  241. totalFedTax += empArr[i].fedTax;
  242. totalNet += empArr[i].netPay;
  243.  
  244. }
  245.  
  246. printf("\n-------------------------------------------------------------------------------------------------\n");
  247. printf("Total: %6.2f %6.2f %6.2f %8.2f %7.2f %6.2f %8.2f\n",
  248. totalWage, totalHours, totalOT, totalGross, totalStateTax, totalFedTax, totalNet);
  249. printf("Averages: \n");
  250. printf("Minimum: \n");
  251. printf("Maximum: \n");
  252.  
  253. printf("\n-------------------------------------------------------------------------------------------------\n");
  254. }
  255.  
  256.  
  257.  
  258.  
  259.  
  260. // TODO: Add other functions here as needed
  261. // ... remember your comment block headers for each function
  262.  
  263.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
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:                        
Minimum:                         
Maximum:                         

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