fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 6/29/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, float overtimeHrs, float grossPay);
  30.  
  31. float calcOvertimeHours(float hours);
  32. float calcGrossPay(float hours, float wageRate);
  33.  
  34.  
  35. // TODO: Add other function prototypes here as needed
  36.  
  37. int main() {
  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. // Read in hours for employee
  52. hours[i] = getHours(clockNumber[i]);
  53.  
  54. // TODO: Function call to calculate overtime hours
  55. overtimeHrs[i] = calcOvertimeHours(hours[i]);
  56.  
  57. // TODO: Function call to calculate gross pay
  58. grossPay[i] = calcGrossPay(hours[i], wageRate[i]);
  59.  
  60.  
  61.  
  62. }
  63. // print the header info
  64. printHeader();{
  65. printf("\n\n*** Pay Calculator ***\n");
  66. printf("\nClock# Wage Hours OT Gross\n");
  67. printf("----------------------------------------\n");
  68. }
  69.  
  70. // print out each employee
  71. for (i = 0; i < SIZE; ++i)
  72. {
  73. // Print all the employees - call by value
  74. printEmp (clockNumber[i], wageRate[i], hours[i],
  75. overtimeHrs[i], grossPay[i]);
  76.  
  77. // for
  78. } // main
  79. return (0);
  80.  
  81.  
  82. }
  83. //**************************************************************
  84. // Function: getHours
  85. //
  86. // Purpose: Obtains input from user, the number of hours worked
  87. // per employee and stores the result in a local variable
  88. // that is passed back to the calling function.
  89. //
  90. // Parameters: clockNumber - The unique employee ID
  91. //
  92. // Returns: hoursWorked - hours worked in a given week
  93. //
  94. //**************************************************************
  95.  
  96. float getHours (long int clockNumber) {
  97. float hoursWorked; // hours worked in a given week
  98. // Read in hours for employee
  99. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  100. scanf("%f", &hoursWorked);
  101. // return hours back to the calling function
  102. return hoursWorked;
  103.  
  104. } // getHours
  105.  
  106. //**************************************************************
  107. // Function: printHeader
  108. //
  109. // Purpose: Prints the initial table header information.
  110. //
  111. // Parameters: none
  112. //
  113. // Returns: void
  114. //
  115. //**************************************************************
  116.  
  117. void printHeader (void)
  118. {
  119.  
  120. printf ("\n\n*** Pay Calculator ***\n");
  121.  
  122. // print the table header
  123. printf("\nClock# Wage Hours OT Gross\n");
  124. printf("------------------------------------------------\n");
  125.  
  126. } // printHeader
  127.  
  128. //*************************************************************
  129. // Function: printEmp
  130. //
  131. // Purpose: Prints out all the information for an employee
  132. // in a nice and orderly table format.
  133. //
  134. // Parameters:
  135. //
  136. // clockNumber - unique employee ID
  137. // wageRate - hourly wage rate
  138. // hours - Hours worked for the week
  139. // overtimeHrs - overtime hours worked in a week
  140. // grossPay - gross pay for the week
  141. //
  142. // Returns: void
  143. //
  144. //**************************************************************
  145.  
  146. void printEmp (long int clockNumber, float wageRate, float hours,
  147. float overtimeHrs, float grossPay)
  148. {
  149.  
  150. // print the employee
  151. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n",
  152. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  153. // TODO: add code to print out a single employee
  154. }
  155.  
  156.  
  157. // TODO: Add other functions here as needed
  158. // ... remember your comment block headers for each function
  159.  
  160.  
  161. float calcOvertimeHours(float hours) {
  162. if (hours > STD_WORK_WEEK)
  163. return hours - STD_WORK_WEEK;
  164. else
  165. return 0.0f;}
  166.  
  167. float calcGrossPay(float hours, float wageRate) {
  168. float overtime = calcOvertimeHours(hours);
  169. float regularHours = (hours > STD_WORK_WEEK) ? STD_WORK_WEEK : hours;
  170. return (regularHours * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  171. }
  172.  
  173.  
  174.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
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
------------------------------------------------


*** Pay Calculator ***

Clock#   Wage   Hours   OT     Gross
----------------------------------------
098401  10.60    0.0    0.0      0.00
526488   9.75    0.0    0.0      0.00
765349  10.50    0.0    0.0      0.00
034645  12.25    0.0    0.0      0.00
127615   8.35    0.0    0.0      0.00