fork(1) download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Functions
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 6/29/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. // constants
  23. #define SIZE 5
  24. #define OVERTIME_RATE 1.5f
  25. #define STD_WORK_WEEK 40.0f
  26. #define FED_TAX_RATE 0.12f
  27.  
  28. // function prototypes
  29.  
  30.  
  31. struct employee {
  32. char firstName [10];
  33. char lastName [10];
  34. char state[3];
  35. float stateTax;
  36. float fedTax;
  37. float netPay;
  38. long int clockNumber;
  39. float wageRate;
  40. float hours;
  41. float overtimeHrs;
  42. float grossPay;
  43.  
  44. };
  45.  
  46.  
  47. float getHours(long int clockNumber);
  48. float calcOvertimeHours(float hours);
  49. float calcGrossPay(float hours, float wageRate);
  50. void printHeader(void);
  51. void printEmp(struct employee emp);
  52. void calcTaxes(struct employee *emp);
  53.  
  54. // TODO: Add other function prototypes here as needed
  55.  
  56.  
  57. /* Variable Declarations */
  58. int main() {
  59. struct employee employeeData[SIZE] = {
  60. {"Connie", "Cobol", "MA", 0, 0, 98401, 10.60, 0, 0, 0},
  61. {"Mary", "Apl", "NH", 0, 0, 526488, 9.75, 0, 0, 0},
  62. {"Frank", "Fortran", "VT", 0, 0, 765349, 10.50, 0, 0, 0},
  63. {"Jeff", "Ada", "NY", 0, 0, 34645, 12.25, 0, 0, 0},
  64. {"Anton", "Pascal", "CA", 0, 0, 127615, 8.35, 0, 0, 0}
  65. };
  66.  
  67.  
  68. int i;
  69. // function prototypes
  70.  
  71.  
  72. // process each employee
  73. for (i = 0; i < SIZE; ++i)
  74. {
  75. // Read in hours for employee
  76.  
  77. // employeeData[i].hours = getHours(employeeData[i].clockNumber);
  78. // The code above didn't work
  79. float testHours[] = {51, 42.5, 37.0, 45, 40};
  80. employeeData[i].hours = testHours[i];
  81.  
  82.  
  83. // TODO: Function call to calculate overtime hours
  84. employeeData[i].overtimeHrs = calcOvertimeHours(employeeData[i].hours);
  85.  
  86. // TODO: Function call to calculate gross pay
  87. employeeData[i].grossPay = calcGrossPay(employeeData[i].hours, employeeData[i].wageRate);
  88.  
  89. calcTaxes(&employeeData[i]);
  90.  
  91. }
  92. // print the header info
  93. printHeader(); {
  94.  
  95. printf ("\n\n*** Pay Calculator ***\n");
  96.  
  97. printf("\nName TaxS Clock# Wage Hours OT Gross Fed Net \n");
  98. printf("----------------------------------------------------------------\n");
  99. }
  100.  
  101. // Print employee data
  102. for (i = 0; i < SIZE; ++i) {
  103. printEmp(employeeData[i]);
  104. }
  105. return 0;
  106.  
  107. }
  108.  
  109. //**************************************************************
  110. // Function: getHours
  111. //
  112. // Purpose: Obtains input from user, the number of hours worked
  113. // per employee and stores the result in a local variable
  114. // that is passed back to the calling function.
  115. //
  116. // Parameters: clockNumber - The unique employee ID
  117. //
  118. // Returns: hoursWorked - hours worked in a given week
  119. //
  120. //**************************************************************
  121.  
  122. float getHours (long int clockNumber) {
  123. float hoursWorked; // hours worked in a given week
  124. // Read in hours for employee
  125.  
  126. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  127. scanf("%f", &hoursWorked);
  128.  
  129.  
  130. // return hours back to the calling function
  131. return hoursWorked;
  132.  
  133. } // getHours
  134.  
  135. float calcOvertimeHours(float hours) {
  136. if (hours > STD_WORK_WEEK)
  137. return hours - STD_WORK_WEEK;
  138. else
  139. return 0.0f;
  140. }
  141.  
  142. float calcGrossPay(float hours, float wageRate) {
  143. float overtime = calcOvertimeHours(hours);
  144. if (hours > STD_WORK_WEEK) {
  145. return (STD_WORK_WEEK * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  146. } else {
  147. return hours * wageRate;
  148. }}
  149.  
  150. // overtime pay
  151.  
  152.  
  153. void calcTaxes(struct employee *emp) {
  154.  
  155. if (strcmp(emp->state, "MA") == 0)
  156. emp->stateTax = emp->grossPay * 0.05f;
  157. else if (strcmp(emp->state, "NH") == 0)
  158. emp->stateTax = 0.0f;
  159. else if (strcmp(emp->state, "VT") == 0)
  160. emp->stateTax = emp->grossPay * 0.065f;
  161. else if (strcmp(emp->state, "NY") == 0)
  162. emp->stateTax = emp->grossPay * 0.04f;
  163. else if (strcmp(emp->state, "CA") == 0)
  164. emp->stateTax = emp->grossPay * 0.06f;
  165. else
  166. emp->stateTax = 0.0f;
  167.  
  168. emp->fedTax = emp->grossPay * FED_TAX_RATE;
  169. emp->netPay = emp->grossPay - (emp->stateTax + emp->fedTax);
  170. }
  171.  
  172.  
  173. //**************************************************************
  174. // Function: printHeader
  175. //
  176. // Purpose: Prints the initial table header information.
  177. //
  178. // Parameters: none
  179. //
  180. // Returns: void
  181. //
  182. //**************************************************************
  183.  
  184. void printHeader(void) {
  185. printf("\n----------------------------------------");
  186. }
  187.  
  188. //*************************************************************
  189. // Function: printEmp
  190. //
  191. // Purpose: Prints out all the information for an employee
  192. // in a nice and orderly table format.
  193. //
  194. // Parameters:
  195. //
  196. // clockNumber - unique employee ID
  197. // wageRate - hourly wage rate
  198. // hours - Hours worked for the week
  199. // overtimeHrs - overtime hours worked in a week
  200. // grossPay - gross pay for the week
  201. //
  202. // Returns: void
  203. //
  204. //**************************************************************
  205.  
  206. void printEmp(struct employee emp) {
  207. printf("%-6s %-8s %-3s %06d %6.2f %6.1f %6.1f %9.2f %8.2f %8.2f\n",
  208. emp.firstName, emp.lastName, emp.state, emp.clockNumber,
  209. emp.wageRate, emp.hours, emp.overtimeHrs, emp.grossPay,
  210. emp.fedTax, emp.netPay);
  211. }
  212.  
  213.  
  214. // TODO: Add other functions here as needed
  215. // ... remember your comment block headers for each function
  216.  
  217.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
----------------------------------------

*** Pay Calculator ***

Name  	 	   TaxS Clock#   Wage   Hours   OT       Gross    Fed      Net 
----------------------------------------------------------------
Connie Cobol    MA  000010   0.00   51.0   11.0      0.00     0.00     0.00
Mary   Apl      NH  000009   0.00   42.5    2.5      0.00     0.00     0.00
Frank  Fortran  VT  000010   0.00   37.0    0.0      0.00     0.00     0.00
Jeff   Ada      NY  000012   0.00   45.0    5.0      0.00     0.00     0.00
Anton  Pascal   CA  000008   0.00   40.0    0.0      0.00     0.00     0.00