fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Robert Liszka
  6. //
  7. // Class: C Programming, Spring, 2025
  8. //
  9. // Date: March 3rd, 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,
  35. float hours,
  36. float overtimeHrs);
  37.  
  38. int main()
  39. {
  40.  
  41. /* Variable Declarations */
  42.  
  43. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  44. float grossPay[SIZE]; // gross pay
  45. float hours[SIZE]; // hours worked in a given week
  46. int i; // loop and array index
  47. float overtimeHrs[SIZE]; // overtime hours
  48. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  49.  
  50.  
  51.  
  52. // process each employee
  53. for (i = 0; i < SIZE; ++i)
  54. {
  55.  
  56. // Read in hours for employee
  57. hours[i] = getHours (clockNumber[i]);
  58.  
  59. // TODO: Function call to calculate overtime hours
  60. overtimeHrs[i] = calcOT (hours[i]);
  61.  
  62. // TODO: Function call to calculate gross pay
  63. grossPay[i] = calcGross (wageRate[i], hours[i], overtimeHrs[i]);
  64.  
  65. }
  66.  
  67. // print the header info
  68. printHeader();
  69.  
  70. // print out each employee
  71. for (i = 0; i < SIZE; ++i)
  72. {
  73.  
  74. // Print all the employees - call by value
  75. printEmp (clockNumber[i], wageRate[i], hours[i],
  76. overtimeHrs[i], grossPay[i]);
  77.  
  78. } // for
  79.  
  80. return (0);
  81.  
  82. } // main
  83.  
  84. //**************************************************************
  85. //Function: CalcOT
  86. //
  87. //Description: uses hours from employee input and subtracts from
  88. //standard work week hours to get number of overtime hours worked.
  89. //
  90. //Parameters: hours - number of hours worked
  91. //
  92. //Return: overtimeHrs - numbers of hours worked past 40
  93. //
  94. //**************************************************************
  95. float calcOT (float hours)
  96. {
  97. float overtimeHrs;
  98.  
  99. overtimeHrs = hours - STD_WORK_WEEK;
  100.  
  101. return (overtimeHrs);
  102.  
  103. }// calcOT
  104.  
  105. //**************************************************************
  106. //Function: calcGross
  107. //
  108. //Description: uses if statment to check if employee has worked
  109. // overtime or not, then adds normal pay to overtime pay to get
  110. // gross pay which is called back to the calling function.
  111. //
  112. //Parameters: wageRate - amount paid per hour
  113. // hours - number of hours worked
  114. // overtimeHrs - hours of overtime
  115. //
  116. //Returns: grossPay - nomrmal pay and overtime pay added together
  117. //
  118. //**************************************************************
  119. float calcGross (float wageRate, float hours, float overtimeHrs)
  120. {
  121. float grossPay; // gross pay to be calculated
  122. float normalPay; // normal pay earned
  123. float overtimePay; // overtime pay earned
  124.  
  125. // calulates gross pay, normal pay, and overtime pay
  126. if (hours > STD_WORK_WEEK)
  127. {
  128. // calculate overtime hours
  129. overtimeHrs = hours - STD_WORK_WEEK;
  130.  
  131. // calculate normal pay
  132. normalPay = STD_WORK_WEEK * wageRate;
  133.  
  134. // calculate overtime pay
  135. overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
  136.  
  137. }
  138. else
  139. {
  140. //they have no overtime hours
  141. overtimeHrs = 0;
  142. overtimePay = 0;
  143.  
  144. // calculate normal pay
  145. normalPay = hours * wageRate;
  146.  
  147. }// for if
  148.  
  149.  
  150. grossPay = normalPay + overtimePay;
  151.  
  152.  
  153. return(grossPay);
  154.  
  155. }// calcgross
  156.  
  157. //**************************************************************
  158. // Function: getHours
  159. //
  160. // Purpose: Obtains input from user, the number of hours worked
  161. // per employee and stores the result in a local variable
  162. // that is passed back to the calling function.
  163. //
  164. // Parameters: clockNumber - The unique employee ID
  165. //
  166. // Returns: hoursWorked - hours worked in a given week
  167. //
  168. //**************************************************************
  169.  
  170. float getHours (long int clockNumber)
  171. {
  172.  
  173. float hoursWorked; // hours worked in a given week
  174.  
  175. // Read in hours for employee
  176. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  177. scanf ("%f", &hoursWorked);
  178.  
  179. // return hours back to the calling function
  180. return (hoursWorked);
  181.  
  182. } // getHours
  183.  
  184. //**************************************************************
  185. // Function: printHeader
  186. //
  187. // Purpose: Prints the initial table header information.
  188. //
  189. // Parameters: none
  190. //
  191. // Returns: void
  192. //
  193. //**************************************************************
  194.  
  195. void printHeader (void)
  196. {
  197.  
  198. printf ("\n\n*** Pay Calculator ***\n");
  199.  
  200. // print the table header
  201. printf("\nClock# Wage Hours OT Gross\n");
  202. printf("------------------------------------------------\n");
  203.  
  204. } // printHeader
  205.  
  206. //*************************************************************
  207. // Function: printEmp
  208. //
  209. // Purpose: Prints out all the information for an employee
  210. // in a nice and orderly table format.
  211. //
  212. // Parameters:
  213. //
  214. // clockNumber - unique employee ID
  215. // wageRate - hourly wage rate
  216. // hours - Hours worked for the week
  217. // overtimeHrs - overtime hours worked in a week
  218. // grossPay - gross pay for the week
  219. //
  220. // Returns: void
  221. //
  222. //**************************************************************
  223.  
  224. void printEmp (long int clockNumber, float wageRate, float hours,
  225. float overtimeHrs, float grossPay)
  226. {
  227.  
  228. // print the employee
  229. printf ("%06ld %5.2f %5.1f %5.1f \t%7.2f\n",
  230. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  231. // TODO: add code to print out a single employee
  232. }
  233.  
  234.  
  235. // TODO: Add other functions here as needed
  236. // ... remember your comment block headers for each function
Success #stdin #stdout 0.01s 5288KB
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  -3.0 	 388.50
034645 12.25  45.0   5.0 	 581.88
127615  8.35   0.0 -40.0 	   0.00