fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Cooper Lefevra
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: March 1 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. float getHours (long int clockNumber);
  28. void printHeader (void);
  29. void printEmp (long int clockNumber, float wageRate, float hours,
  30. float overtimeHrs, float grossPay);
  31.  
  32. // TODO: Add other function prototypes here as needed
  33. float calcOT (float hours);
  34. float calcGross (float wageRate, float hours, float overtimeHrs);
  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 employee
  52. hours[i] = getHours (clockNumber[i]);
  53.  
  54. // TODO: Function call to calculate overtime hours
  55. overtimeHrs[i] = calcOT (hours[i]);
  56. // TODO: Function call to calculate gross pay
  57. grossPay[i] = calcGross (wageRate[i], hours[i], overtimeHrs[i]);
  58.  
  59. }
  60.  
  61. // print the header info
  62. printHeader();
  63.  
  64. // print out each employee
  65. for (i = 0; i < SIZE; ++i)
  66. {
  67.  
  68. // Print all the employees - call by value
  69. printEmp (clockNumber[i], wageRate[i], hours[i],
  70. overtimeHrs[i], grossPay[i]);
  71.  
  72. } // for
  73.  
  74. return (0);
  75.  
  76. } // main
  77.  
  78. //**************************************************************
  79. // Function: getHours
  80. //
  81. // Purpose: Obtains input from user, the number of hours worked
  82. // per employee and stores the result in a local variable
  83. // that is passed back to the calling function.
  84. //
  85. // Parameters: clockNumber - The unique employee ID
  86. //
  87. // Returns: hoursWorked - hours worked in a given week
  88. //
  89. //**************************************************************
  90.  
  91. float getHours (long int clockNumber)
  92. {
  93.  
  94. float hoursWorked; // hours worked in a given week
  95.  
  96. // Read in hours for employee
  97. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  98. scanf ("%f", &hoursWorked);
  99.  
  100. // return hours back to the calling function
  101. return (hoursWorked);
  102.  
  103. } // getHours
  104.  
  105. //**************************************************************
  106. // Function: printHeader
  107. //
  108. // Purpose: Prints the initial table header information.
  109. //
  110. // Parameters: none
  111. //
  112. // Returns: void
  113. //
  114. //**************************************************************
  115.  
  116. void printHeader (void)
  117. {
  118.  
  119. printf ("\n\n*** Pay Calculator ***\n");
  120.  
  121. // print the table header
  122. printf("\nClock# Wage Hours OT Gross\n");
  123. printf("------------------------------------------------\n");
  124.  
  125. } // printHeader
  126.  
  127. //*************************************************************
  128. // Function: printEmp
  129. //
  130. // Purpose: Prints out all the information for an employee
  131. // in a nice and orderly table format.
  132. //
  133. // Parameters:
  134. //
  135. // clockNumber - unique employee ID
  136. // wageRate - hourly wage rate
  137. // hours - Hours worked for the week
  138. // overtimeHrs - overtime hours worked in a week
  139. // grossPay - gross pay for the week
  140. //
  141. // Returns: void
  142. //
  143. //**************************************************************
  144.  
  145. void printEmp (long int clockNumber, float wageRate, float hours,
  146. float overtimeHrs, float grossPay)
  147. {
  148.  
  149. // print the employee
  150.  
  151. // TODO: add code to print out a single employee
  152. printf ("%6li %5.2f %5.1f %5.1f %8.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
  153. }//employee printout
  154.  
  155.  
  156. // TODO: Add other functions here as needed
  157. // Function CalcOT
  158. // Purpose : Calculates total hours over 40 during a standard work week
  159. // Parameters :
  160. //
  161. // overtimeHrs = Hours over 40 worked by employee
  162. // hours = Total hours worked in a week by employee
  163. // STD_WORK_WEEK = Determines the amount of standard hours in a work week default 40
  164. //
  165. // Returns: Amount of hours over 40 in a work week
  166.  
  167. float calcOT(float hours) // function start
  168. {
  169. float overtimeHrs = 0.0f; //initialize OT hrs
  170.  
  171. if (hours > STD_WORK_WEEK) {
  172. overtimeHrs = hours - STD_WORK_WEEK; //calculate OT hours
  173. } else { //else statement making OT hours 0 if none
  174. overtimeHrs = 0.0f;
  175. }
  176. return overtimeHrs; //return value of overtime hours
  177. }//calcOT
  178.  
  179. // Function : calcGross
  180. //
  181. // Purpose : Calculates the total gross pay of overtime and standard hrs for the week
  182. //
  183. // Parameters:
  184. //
  185. // grossPay = gross pay to be calculated
  186. // normalPay = Normal pay earned in a week
  187. // overtimePay = Overtime pay earned in a week
  188. // wageRate = The amount of $ per hour employees are making
  189. // STD_WORK_WEEK = Determines the amount of standard hours in a work week default 40
  190. // OVERTIME_RATE = The rate at which employees above 40 hours are payed default 1.5
  191. //
  192. // Returns: grossPay
  193.  
  194. //function for calcGross
  195. float calcGross(float wageRate, float hours, float overtimeHrs) {
  196. float grossPay; //declare grosspay
  197. float normalPay; //declare normalpay
  198. float overtimePay; //declare overtimepay
  199.  
  200. if (hours > STD_WORK_WEEK) {
  201. normalPay = (wageRate * STD_WORK_WEEK); //normal pay calculation for OT
  202. } else {
  203. normalPay = wageRate * hours; //normal pay calculation for no OT
  204. }
  205. //overtime pay calculation
  206. overtimePay = overtimeHrs * (wageRate * OVERTIME_RATE);
  207.  
  208. //gross pay calculation
  209. grossPay = normalPay + overtimePay;
  210.  
  211. return grossPay; //return value of grosspay
  212. }//calcGross
  213.  
  214. // ... remember your comment block headers for each function
Success #stdin #stdout 0.01s 5276KB
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
------------------------------------------------
 98401 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
 34645 12.25  45.0   5.0   581.88
127615  8.35   0.0   0.0     0.00