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.  
  21. // constants
  22. #define SIZE 5
  23. #define OVERTIME_RATE 1.5f
  24. #define STD_WORK_WEEK 40.0f
  25.  
  26. // function prototypes
  27.  
  28. struct employee {
  29. long int clockNumber;
  30. float wageRate;
  31. float hours;
  32. float overtimeHrs;
  33. float grossPay;
  34. };
  35.  
  36. int main() {
  37.  
  38. float getHours (long int clockNumber);
  39. void printHeader (void);
  40. void printEm(void);
  41. void printEmp(struct employee emp);
  42. float calcOvertimeHours(float hours);
  43. float calcGrossPay(float hours, float wageRate);
  44.  
  45. int i;
  46.  
  47.  
  48. // TODO: Add other function prototypes here as needed
  49.  
  50. struct employee emp[SIZE] = {
  51. {98401, 10.60},
  52. {526488, 9.75},
  53. {765349, 10.50},
  54. {34645, 12.25},
  55. {127615, 8.35}
  56. };
  57. /* Variable Declarations */
  58.  
  59.  
  60. // process each employee
  61. for (i = 0; i < SIZE; ++i) {
  62. // Read in hours for employee
  63. emp[i].hours = getHours(emp[i].clockNumber);
  64.  
  65. // TODO: Function call to calculate gross pay
  66. emp[i].grossPay = calcGrossPay(emp[i].hours, emp[i].wageRate);
  67.  
  68.  
  69. // TODO: Function call to calculate overtime hours
  70. emp[i].overtimeHrs = calcOvertimeHours(emp[i].hours);
  71.  
  72. };
  73.  
  74. // print the header info
  75. printHeader();
  76.  
  77. // print out each employee
  78. for (i = 0; i < SIZE; ++i) {
  79. // Print all the employees - call by value
  80. printEmp(emp[i]);
  81. // for
  82. } // main
  83. return (0);
  84.  
  85. }
  86.  
  87. //**************************************************************
  88. // Function: getHours
  89. //
  90. // Purpose: Obtains input from user, the number of hours worked
  91. // per employee and stores the result in a local variable
  92. // that is passed back to the calling function.
  93. //
  94. // Parameters: clockNumber - The unique employee ID
  95. //
  96. // Returns: hoursWorked - hours worked in a given week
  97. //
  98. //**************************************************************
  99.  
  100. float getHours (long int clockNumber) {
  101. float hoursWorked; // hours worked in a given week
  102. // Read in hours for employee
  103. if (clockNumber == 98401)
  104. hoursWorked = 51.0;
  105. else if (clockNumber == 526488)
  106. hoursWorked = 42.5;
  107. else if (clockNumber == 765349)
  108. hoursWorked = 37.0;
  109. else if (clockNumber == 34645)
  110. hoursWorked = 45.0;
  111. else if (clockNumber == 127615)
  112. hoursWorked = 0;
  113. else
  114. hoursWorked = 0.0;
  115.  
  116. printf("Enter hours worked by emp #%06ld: %.2f\n", clockNumber, hoursWorked);
  117.  
  118. return hoursWorked;
  119.  
  120. } // getHours
  121.  
  122. float calcOvertimeHours(float hours) {
  123. return (hours > STD_WORK_WEEK) ? (hours - STD_WORK_WEEK) : 0.0f;
  124.  
  125.  
  126. }
  127.  
  128. float calcGrossPay(float hours, float wageRate) {
  129. float overtime = calcOvertimeHours(hours);
  130. float regularHours = (hours > STD_WORK_WEEK) ? STD_WORK_WEEK : hours;
  131. return (regularHours * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  132. }
  133.  
  134.  
  135.  
  136.  
  137. //**************************************************************
  138. // Function: printHeader
  139. //
  140. // Purpose: Prints the initial table header information.
  141. //
  142. // Parameters: none
  143. //
  144. // Returns: void
  145. //
  146. //**************************************************************
  147.  
  148. void printHeader (void)
  149. {
  150. printf("\n---------------------------------------------");
  151. printf ("\n\n*** Pay Calculator ***\n");
  152.  
  153. // print the table header
  154. printf("\nClock# Wage Hours OT Gross\n");
  155. printf("----------------------------------------------\n");
  156.  
  157.  
  158. } // printHeader
  159.  
  160. //*************************************************************
  161. // Function: printEmp
  162. //
  163. // Purpose: Prints out all the information for an employee
  164. // in a nice and orderly table format.
  165. //
  166. // Parameters:
  167. //
  168. // clockNumber - unique employee ID
  169. // wageRate - hourly wage rate
  170. // hours - Hours worked for the week
  171. // overtimeHrs - overtime hours worked in a week
  172. // grossPay - gross pay for the week
  173. //
  174. // Returns: void
  175. //
  176. //**************************************************************
  177.  
  178. void printEmp(struct employee emp) {
  179. printf("%06ld %5.2f %5.2f %5.2f %5.2f\n",
  180. emp.clockNumber, emp.wageRate, emp.hours,
  181. emp.overtimeHrs, emp.grossPay);
  182.  
  183.  
  184. }
  185.  
  186. // TODO: Add other functions here as needed
  187. // ... remember your comment block headers for each function
  188.  
  189.  
Success #stdin #stdout 0s 5312KB
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: 0.00

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

*** Pay Calculator ***

Clock#   Wage    Hours   OT   Gross
----------------------------------------------
098401  10.60  51.00  11.00  598.90
526488   9.75  42.50   2.50  426.56
765349  10.50  37.00   0.00  388.50
034645  12.25  45.00   5.00  581.88
127615   8.35   0.00   0.00   0.00