fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Christopher J. Golebiowski
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 08-Mar-2026
  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. // Functions called by a combination of by value and by
  16. // reference.
  17. //
  18. //********************************************************
  19.  
  20. #include <stdio.h>
  21.  
  22. // constants
  23. #define SIZE 5
  24. #define OVERTIME_RATE 1.5f
  25. #define STD_WORK_WEEK 40.0f
  26.  
  27. // function prototypes
  28. float getHours (long int clockNumber);
  29. void printHeader (void);
  30. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  31. float overtimeHrs[], float grossPay[], int theSize);
  32. float calculateOvertimeHours (float hours, float standardWorkWeekHours);
  33. float calculateGrossPay (float hours, float overtimeHours, float wage, float otWageRate);
  34.  
  35. int main()
  36. {
  37.  
  38. // Variable Declarations
  39.  
  40. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  41. float grossPay[SIZE]; // gross pay
  42. float hours[SIZE]; // hours worked in a given week
  43. int i; // loop and array index
  44. float overtimeHrs[SIZE]; // overtime hours
  45. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  46.  
  47. // process each employee
  48. for (i = 0; i < SIZE; ++i)
  49. {
  50.  
  51. // read in hours for the current employee
  52. hours[i] = getHours (clockNumber[i]);
  53.  
  54. // calculate overtime hours
  55. overtimeHrs[i] = calculateOvertimeHours (hours[i], STD_WORK_WEEK);
  56.  
  57. // calculate gross pay
  58. grossPay[i] = calculateGrossPay (hours[i], overtimeHrs[i], wageRate[i], OVERTIME_RATE);
  59.  
  60. }
  61.  
  62. // Print the header info
  63. printHeader();
  64.  
  65. // Print all the employees - call by reference
  66. printEmp (clockNumber, wageRate, hours,
  67. overtimeHrs, grossPay, SIZE);
  68.  
  69. return (0);
  70.  
  71. } // main
  72.  
  73. //**************************************************************
  74. // Function: getHours
  75. //
  76. // Purpose: Obtains input from user, the number of hours worked
  77. // per employee and stores the result in a local variable
  78. // that is passed back to the calling function.
  79. //
  80. // Parameters: clockNumber - The unique employee ID
  81. //
  82. // Returns: hoursWorked - hours worked in a given week
  83. //
  84. //**************************************************************
  85.  
  86. float getHours (long int clockNumber)
  87. {
  88.  
  89. float hoursWorked; // hours worked in a given week
  90.  
  91. // Read in hours for employee
  92. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  93. scanf ("%f", &hoursWorked);
  94.  
  95. // return hours back to the calling function
  96. return (hoursWorked);
  97.  
  98. } // getHours
  99.  
  100. //**************************************************************
  101. // Function: printHeader
  102. //
  103. // Purpose: Prints the initial table header information.
  104. //
  105. // Parameters: none
  106. //
  107. // Returns: void
  108. //
  109. //**************************************************************
  110.  
  111. void printHeader (void)
  112. {
  113.  
  114. printf ("\n\n*** Pay Calculator ***\n");
  115.  
  116. // print the table header
  117. printf("\nClock# Wage Hours OT Gross\n");
  118. printf("------------------------------------------------\n");
  119.  
  120. } // printHeader
  121.  
  122. //*************************************************************
  123. // Function: printEmp
  124. //
  125. // Purpose: Prints out all the employee information in a
  126. // nice and orderly table format.
  127. //
  128. // Parameters:
  129. //
  130. // clockNumber - Array of employee clock numbers
  131. // wageRate - Array of employee wages per hour
  132. // hours - Array of number of hours worked by an employee
  133. // overtimeHrs - Array of overtime hours for each employee
  134. // grossPay - Array of gross pay calculations for each employee
  135. // theSize - Number of employees to process
  136. //
  137. // Returns: Nothing (call by reference)
  138. //
  139. //**************************************************************
  140.  
  141. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  142. float overtimeHrs[], float grossPay[], int theSize)
  143. {
  144.  
  145. int i; // loop index
  146.  
  147. // access and print each employee
  148. for (i = 0; i < theSize; ++i)
  149. {
  150. printf("\n %06li %5.2f %4.1f %4.1f %8.2f", clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  151. }
  152. }
  153.  
  154.  
  155. //**************************************************************
  156. // Function: calculateOvertimeHours
  157. //
  158. // Purpose: Calculates the number of overtime hours worked
  159. // based on total hours worked by the employee and the number
  160. // of hours in a standard work week. The result is
  161. // passed back to the calling function.
  162. //
  163. // Parameters:
  164. // hours - number of hours worked by employee
  165. // standardWorkWeekHours - number of hours in a standard work week
  166. //
  167. // Returns: overtimeHours - overtime hours worked in a given week
  168. //
  169. //**************************************************************
  170.  
  171. float calculateOvertimeHours (float hours, float standardWorkWeekHours)
  172. {
  173.  
  174. float overtimeHours; // overtime hours worked in a given week
  175.  
  176. // Calculate overtime for employee
  177. if (hours >= standardWorkWeekHours)
  178. {
  179. overtimeHours = hours - standardWorkWeekHours;
  180. }
  181. else // no OT
  182. {
  183. overtimeHours = 0;
  184. }
  185.  
  186. // return overtime hours back to the calling function
  187. return (overtimeHours);
  188.  
  189. } // calculateOvertimeHours
  190.  
  191.  
  192. //**************************************************************
  193. // Function: calculateGrossPay
  194. //
  195. // Purpose: Calculates the total gross pay for an employee
  196. // based on hours worked by the employee wage rate. Includes
  197. // overtime rate calculated via a wage rate multiplier. The result is
  198. // passed back to the calling function.
  199. //
  200. // Parameters:
  201. // hours - number of hours worked by employee
  202. // overtimeHours - number of overtime hours worked by employee
  203. // wage - individual wage rate for the employee
  204. // otWageRate - wage rate multiplier for overtime calculation
  205. //
  206. // Returns: overtimeHours - overtime hours worked in a given week
  207. //
  208. //**************************************************************
  209.  
  210. float calculateGrossPay (float hours, float overtimeHours, float wage, float otWageRate)
  211. {
  212.  
  213. float grossPay; // gross pay for employee in given week
  214.  
  215. // Calculate gross pay for employee
  216. grossPay = ((hours - overtimeHours) * wage) + (overtimeHours * (wage * otWageRate));
  217.  
  218. // return gross pay back to the calling function
  219. return (grossPay);
  220.  
  221. } // calculateGrossPay
Success #stdin #stdout 0.01s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
Enter hours worked by emp # 098401: 
Enter hours worked by emp # 526488: 
Enter hours worked by emp # 765349: 
Enter hours worked by emp # 034645: 
Enter hours worked by emp # 127615: 

*** Pay Calculator ***

Clock# Wage  Hours  OT      Gross
------------------------------------------------

 098401 10.60 51.0 11.0   598.90
 526488  9.75 42.5  2.5   426.56
 765349 10.50 37.0  0.0   388.50
 034645 12.25 45.0  5.0   581.88
 127615  8.35  0.0  0.0     0.00