fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name:Katie Sandoval
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 10/10/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. float calcOT (float hours);
  32. float calcGross (float wageRate, float hours, float overtimeHRs);
  33. // TODO: Add other function prototypes here as needed
  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 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. // print the header info
  61. printHeader();
  62.  
  63. // print out each employee
  64. for (i = 0; i < SIZE; ++i)
  65. {
  66.  
  67. // Print all the employees - call by value
  68. printEmp (clockNumber[i], wageRate[i], hours[i],
  69. overtimeHrs[i], grossPay[i]);
  70.  
  71. } // for
  72.  
  73. return (0);
  74.  
  75. } // main
  76.  
  77. //**************************************************************
  78. // Function: getHours
  79. //
  80. // Purpose: Obtains input from user, the number of hours worked
  81. // per employee and stores the result in a local variable
  82. // that is passed back to the calling function.
  83. //
  84. // Parameters: clockNumber - The unique employee ID
  85. //
  86. // Returns: hoursWorked - hours worked in a given week
  87. //
  88. //**************************************************************
  89.  
  90. float getHours (long int clockNumber)
  91. {
  92.  
  93. float hoursWorked; // hours worked in a given week
  94.  
  95. // Read in hours for employee
  96. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  97. scanf ("%f", &hoursWorked);
  98.  
  99. // return hours back to the calling function
  100. return (hoursWorked);
  101.  
  102. } // getHours
  103.  
  104. //**************************************************************
  105. // Function: printHeader
  106. //
  107. // Purpose: Prints the initial table header information.
  108. //
  109. // Parameters: none
  110. //
  111. // Returns: void
  112. //
  113. //**************************************************************
  114.  
  115. void printHeader (void)
  116. {
  117.  
  118. printf ("\n\n*** Pay Calculator ***\n");
  119.  
  120. // print the table header
  121. printf("\nClock# Wage Hours OT Gross\n");
  122. printf("------------------------------------------------\n");
  123.  
  124. } // printHeader
  125.  
  126. //*************************************************************
  127. // Function: printEmp
  128. //
  129. // Purpose: Prints out all the information for an employee
  130. // in a nice and orderly table format.
  131. //
  132. // Parameters:
  133. //
  134. // clockNumber - unique employee ID
  135. // wageRate - hourly wage rate
  136. // hours - Hours worked for the week
  137. // overtimeHrs - overtime hours worked in a week
  138. // grossPay - gross pay for the week
  139. //
  140. // Returns: void
  141. //
  142. //**************************************************************
  143.  
  144. void printEmp (long int clockNumber, float wageRate, float hours,
  145. float overtimeHrs, float grossPay)
  146. {
  147.  
  148. // print the employee
  149.  
  150. // TODO: add code to print out a single employee
  151. printf ("\t%06ld %5.2f %5.1f %5.1f %7.2f\n",
  152. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  153.  
  154. } //printEmp
  155.  
  156.  
  157. // TODO: Add other functions here as needed
  158. // ... remember your comment block headers for each function
  159.  
  160.  
  161. //*************************************************************
  162. // Function: calcOT
  163. //
  164. // Purpose: Calulates Overtime.
  165. //
  166. // Parameters: float hours
  167. //
  168. //
  169. // Returns: value
  170. //*************************************************************
  171. //Funcation Definition for calOT(Call by Value)
  172. float calcOT(float hours)
  173. {
  174. float overtimeHrs; //calculated overtime hours worked
  175.  
  176. //code to compute overtimeHRs
  177. if(hours > STD_WORK_WEEK)
  178. {
  179. overtimeHrs = hours - STD_WORK_WEEK;
  180. }
  181.  
  182. else
  183. {
  184. overtimeHrs=0;
  185.  
  186. }
  187. //return the calculatd overtime hours value
  188. return(overtimeHrs);
  189. }//calcOT
  190.  
  191.  
  192. //*************************************************************
  193. // Function: calcGross
  194. //
  195. // Purpose: Calulates Grosspay.
  196. //
  197. // Parameters: float wageRate, float hours, floar overtimeHRs
  198. //
  199. //
  200. // Returns: value
  201. //*************************************************************
  202. //Funcation Definition for calGross(Call by Value)
  203. float calcGross(float wageRate, float hours, float overtimeHrs)
  204. {
  205. float grossPay; //gross pay to be calucated
  206. float normalPay; //normal pay earned
  207. float overtimePay; //overtime pay earned
  208.  
  209. //code to compute grossPay
  210.  
  211. if (hours > STD_WORK_WEEK)
  212.  
  213. {
  214. normalPay = wageRate * STD_WORK_WEEK;
  215.  
  216.  
  217. overtimePay = overtimeHrs* wageRate * OVERTIME_RATE;
  218.  
  219.  
  220. grossPay = normalPay + overtimePay;
  221. }
  222. else
  223. {
  224. overtimePay=0;
  225. grossPay = wageRate * hours;
  226.  
  227. }// return the calculated gross pay value
  228.  
  229. return(grossPay);
  230. }// calcGross
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
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