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