fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Natelle Lewis
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: 03/02/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. // process each employee
  51. for (i = 0; i < SIZE; ++i)
  52. {
  53.  
  54. // Read in hours for employee
  55. hours[i] = getHours (clockNumber[i]);
  56.  
  57. // TODO: Function call to calculate overtime hours
  58. overtimeHrs[i] = calcOT (hours[i]);
  59.  
  60. // TODO: Function call to calculate gross pay
  61. grossPay[i] = calcGross(wageRate[i], hours[i], overtimeHrs[i]);
  62.  
  63. }
  64.  
  65. // print the header info
  66. printHeader();
  67.  
  68. // print out each employee
  69. for (i = 0; i < SIZE; ++i)
  70. {
  71.  
  72. // Print all the employees - call by value
  73. printEmp (clockNumber[i], wageRate[i], hours[i],
  74. overtimeHrs[i], grossPay[i]);
  75.  
  76. } // for
  77.  
  78. return (0);
  79.  
  80. } // main
  81.  
  82. //**************************************************************
  83. // Function: getHours
  84. //
  85. // Purpose: Obtains input from user, the number of hours worked
  86. // per employee and stores the result in a local variable
  87. // that is passed back to the calling function.
  88. //
  89. // Parameters: clockNumber - The unique employee ID
  90. //
  91. // Returns: hoursWorked - hours worked in a given week
  92. //
  93. //**************************************************************
  94.  
  95. float getHours (long int clockNumber)
  96. {
  97.  
  98. float hoursWorked; // hours worked in a given week
  99.  
  100. // Read in hours for employee
  101. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  102. scanf ("%f", &hoursWorked);
  103.  
  104. // return hours back to the calling function
  105. return (hoursWorked);
  106.  
  107. } // getHours
  108.  
  109. //**************************************************************
  110. // Function: printHeader
  111. //
  112. // Purpose: Prints the initial table header information.
  113. //
  114. // Parameters: none
  115. //
  116. // Returns: void
  117. //
  118. //**************************************************************
  119.  
  120. void printHeader (void)
  121. {
  122.  
  123. printf ("\n\n*** Pay Calculator ***\n");
  124.  
  125. // print the table header
  126. printf("\nClock# Wage Hours OT Gross\n");
  127. printf("------------------------------------------------\n");
  128.  
  129. } // printHeader
  130.  
  131. //*************************************************************
  132. // Function: printEmp
  133. //
  134. // Purpose: Prints out all the information for an employee
  135. // in a nice and orderly table format.
  136. //
  137. // Parameters:
  138. //
  139. // clockNumber - unique employee ID
  140. // wageRate - hourly wage rate
  141. // hours - Hours worked for the week
  142. // overtimeHrs - overtime hours worked in a week
  143. // grossPay - gross pay for the week
  144. //
  145. // Returns: void
  146. //
  147. //**************************************************************
  148. void printEmp(long int clockNumber, float wageRate, float hours,
  149. float overtimeHrs, float grossPay)
  150. {
  151. // print the employee information in a table format
  152. printf("%06li %.2f %.2f %.2f %.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
  153. } // printEmp
  154.  
  155.  
  156.  
  157. // TODO: Add other functions here as needed
  158. // ... remember your comment block headers for each function
  159.  
  160. //*************************************************************
  161. // Function: calGross
  162. //
  163. // Purpose: Calculates gross pay
  164. //
  165. // Parameters:
  166. // hours - Hours worked for the week
  167. // STD_WORK_WEEK - standard hours of the work week
  168. //
  169. //
  170. // Returns: void
  171. //
  172. //**************************************************************
  173.  
  174. // function stub definition for calcOT
  175. float calcOT(float hours) {
  176. if (hours > STD_WORK_WEEK) {
  177. // Overtime is the number of hours worked beyond 40
  178. return hours - STD_WORK_WEEK;
  179. } else {
  180. // No overtime if hours worked are 40 or less
  181. return 0;
  182. }
  183. } //calcOT
  184.  
  185. //*************************************************************
  186. // Function: calcGross
  187. //
  188. // Purpose: Calculates gross pay
  189. //
  190. // Parameters:
  191. // wageRate - hourly wage rate
  192. // hours - Hours worked for the week
  193. // overtimeHrs - overtime hours worked in a week
  194. // STD_WORK_WEEK - Standard hours for the work week
  195. // Returns: void
  196. //
  197. //**************************************************************
  198.  
  199. // function definition for calcGross
  200. float calcGross(float wageRate, float hours, float overtimeHrs) {
  201. if (hours > STD_WORK_WEEK) {
  202. return (STD_WORK_WEEK * wageRate) + (overtimeHrs * wageRate * OVERTIME_RATE);
  203. } else {
  204. return hours * wageRate;
  205. }
  206. } //calcGross
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.00  11.00  598.90
526488  9.75  42.50  2.50  426.56
765349  10.50  37.00  0.00  388.50
034645  12.25  45.00  5.00  581.88
127615  8.35  0.00  0.00  0.00