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