fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: <Mario Toribio>
  6. //
  7. // Class: C Programming, <Summer 2025>
  8. //
  9. // Date: <06/25/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 getOThours (float hours, float stdworkweek);
  34. float calculateGrossPay(float hours, float wageRate, float otwageRate, float othours, float stdworkweek);
  35.  
  36. int main()
  37. {
  38.  
  39. /* Variable Declarations */
  40.  
  41. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  42. float grossPay[SIZE]; // gross pay
  43. float hours[SIZE]; // hours worked in a given week
  44. int i; // loop and array index
  45. float overtimeHrs[SIZE]; // overtime hours
  46. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  47.  
  48. // process each employee
  49. for (i = 0; i < SIZE; ++i)
  50. {
  51.  
  52. // Read in hours for employee
  53. hours[i] = getHours (clockNumber[i]);
  54.  
  55. // TODO: Function call to calculate overtime hours
  56. overtimeHrs[i] = getOThours (hours[i], STD_WORK_WEEK);
  57.  
  58. // TODO: Function call to calculate gross pay
  59. grossPay[i] = calculateGrossPay(hours[i], wageRate[i], OVERTIME_RATE, overtimeHrs[i], STD_WORK_WEEK);
  60. }
  61.  
  62. // print the header info
  63. printHeader();
  64.  
  65. // print out each employee
  66. for (i = 0; i < SIZE; ++i)
  67. {
  68.  
  69. // Print all the employees - call by value
  70. printEmp (clockNumber[i], wageRate[i], hours[i],
  71. overtimeHrs[i], grossPay[i]);
  72.  
  73. } // for
  74.  
  75. return (0);
  76.  
  77. } // main
  78.  
  79. //**************************************************************
  80. // Function: getHours
  81. //
  82. // Purpose: Obtains input from user, the number of hours worked
  83. // per employee and stores the result in a local variable
  84. // that is passed back to the calling function.
  85. //
  86. // Parameters: clockNumber - The unique employee ID
  87. //
  88. // Returns: hoursWorked - hours worked in a given week
  89. //
  90. //**************************************************************
  91.  
  92. float getHours (long int clockNumber)
  93. {
  94.  
  95. float hoursWorked; // hours worked in a given week
  96.  
  97. // Read in hours for employee
  98. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  99. scanf ("%f", &hoursWorked);
  100.  
  101. // return hours back to the calling function
  102. return (hoursWorked);
  103.  
  104. } // getHours
  105.  
  106. //**************************************************************
  107. // Function: getOTHours
  108. //
  109. // Purpose: Obtains number of Overtime hours based on the amount of hours worked.
  110. //
  111. // Parameters: hours - numbers of hours worked, stdworkweek - amount of hours worked without overtime
  112. //
  113. // Returns: othoursWorked - overtime hours worked in a given week
  114. //
  115. //**************************************************************
  116.  
  117. float getOThours (float hours, float stdworkweek)
  118. {
  119. float othoursWorked = hours - stdworkweek;
  120. if (othoursWorked > 0.0) { //checks if there is overtime or not.
  121. return (othoursWorked);
  122. }
  123. else {
  124. return (0);
  125. }
  126. } // getOThours
  127.  
  128.  
  129. //**************************************************************
  130. // Function: calculateGrossPay
  131. //
  132. // Purpose: Obtains Gross pay based on wage rates
  133. //
  134. // Parameters: hours - numbers of hours worked, wageRate - normal wage rate, otwageRate - overtime wage rate,
  135. // othours - numbers of overtime hours worked.
  136. //
  137. // Returns: grossPay - total money gained from working.
  138. //
  139. //**************************************************************
  140.  
  141. float calculateGrossPay(float hours, float wageRate, float otwageRate, float othours, float stdworkweek)
  142. {
  143. float grossPay;
  144. if (othours != 0){ // if there is overtime calculate grosspay with overtime
  145. grossPay = stdworkweek*wageRate + otwageRate*wageRate*othours;
  146. }
  147. else { // if there isn't overtime calculate grosspay without overtime
  148. grossPay = hours*wageRate;
  149. }
  150. return (grossPay);
  151.  
  152. } // calculateGrossPay
  153.  
  154. //**************************************************************
  155. // Function: printHeader
  156. //
  157. // Purpose: Prints the initial table header information.
  158. //
  159. // Parameters: none
  160. //
  161. // Returns: void
  162. //
  163. //**************************************************************
  164.  
  165. void printHeader (void)
  166. {
  167.  
  168. printf ("\n\n*** Pay Calculator ***\n");
  169.  
  170. // print the table header
  171. printf("\nClock# Wage Hours OT Gross\n");
  172. printf("------------------------------------------------\n");
  173.  
  174. } // printHeader
  175.  
  176. //*************************************************************
  177. // Function: printEmp
  178. //
  179. // Purpose: Prints out all the information for an employee
  180. // in a nice and orderly table format.
  181. //
  182. // Parameters:
  183. //
  184. // clockNumber - unique employee ID
  185. // wageRate - hourly wage rate
  186. // hours - Hours worked for the week
  187. // overtimeHrs - overtime hours worked in a week
  188. // grossPay - gross pay for the week
  189. //
  190. // Returns: void
  191. //
  192. //**************************************************************
  193.  
  194. void printEmp (long int clockNumber, float wageRate, float hours,
  195. float overtimeHrs, float grossPay)
  196. {
  197.  
  198. // print the employee
  199.  
  200. // TODO: add code to print out a single employee
  201. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
  202. }
  203.  
  204.  
  205. // TODO: Add other functions here as needed
  206. // ... remember your comment block headers for each function
Success #stdin #stdout 0.01s 5320KB
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