fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Raissa Almeida Beckenkamp
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 8, 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. // Functions called by a combination of by value and by
  16. // reference.
  17. //
  18. //********************************************************
  19.  
  20. #include <stdio.h>
  21.  
  22. // constants
  23. #define SIZE 5
  24. #define OVERTIME_RATE 1.5f
  25. #define STD_WORK_WEEK 40.0f
  26.  
  27. // function prototypes
  28. float getHours (long int clockNumber);
  29. void printHeader (void);
  30. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  31. float overtimeHrs[], float grossPay[], int theSize);
  32.  
  33. // TODO: Add other function prototypes here as needed
  34. float calcOT(float hours);
  35. float calcGross(float hours, float wage);
  36.  
  37. int main()
  38. {
  39.  
  40. // Variable Declarations
  41.  
  42. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  43. float grossPay[SIZE]; // gross pay
  44. float hours[SIZE]; // hours worked in a given week
  45. int i; // loop and array index
  46. float overtimeHrs[SIZE]; // overtime hours
  47. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  48.  
  49. // process each employee
  50. for (i = 0; i < SIZE; ++i)
  51. {
  52.  
  53. // read in hours for the current employee
  54. hours[i] = getHours (clockNumber[i]);
  55.  
  56. // TODO: Function call to calculate overtime hours
  57.  
  58. // TODO: Function call to calculate gross pay
  59.  
  60. }
  61.  
  62. // Print the header info
  63. printHeader();
  64.  
  65. // Print all the employees - call by reference
  66. printEmp (clockNumber, wageRate, hours,
  67. overtimeHrs, grossPay, SIZE);
  68.  
  69. return (0);
  70.  
  71. } // main
  72.  
  73. //**************************************************************
  74. // Function: getHours
  75. //
  76. // Purpose: Obtains input from user, the number of hours worked
  77. // per employee and stores the result in a local variable
  78. // that is passed back to the calling function.
  79. //
  80. // Parameters: clockNumber - The unique employee ID
  81. //
  82. // Returns: hoursWorked - hours worked in a given week
  83. //
  84. //**************************************************************
  85.  
  86. float getHours (long int clockNumber)
  87. {
  88.  
  89. float hoursWorked; // hours worked in a given week
  90.  
  91. // Read in hours for employee
  92. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  93. scanf ("%f", &hoursWorked);
  94.  
  95. // return hours back to the calling function
  96. return (hoursWorked);
  97.  
  98. } // getHours
  99.  
  100. //**************************************************************
  101. // Function: printHeader
  102. //
  103. // Purpose: Prints the initial table header information.
  104. //
  105. // Parameters: none
  106. //
  107. // Returns: void
  108. //
  109. //**************************************************************
  110.  
  111. void printHeader (void)
  112. {
  113.  
  114. printf ("\n\n*** Pay Calculator ***\n");
  115.  
  116. // print the table header
  117. printf("\nClock# Wage Hours OT Gross\n");
  118. printf("------------------------------------------------\n");
  119.  
  120. } // printHeader
  121.  
  122. //*************************************************************
  123. // Function: printEmp
  124. //
  125. // Purpose: Prints out all the employee information in a
  126. // nice and orderly table format.
  127. //
  128. // Parameters:
  129. //
  130. // clockNumber - Array of employee clock numbers
  131. // wageRate - Array of employee wages per hour
  132. // hours - Array of number of hours worked by an employee
  133. // overtimeHrs - Array of overtime hours for each employee
  134. // grossPay - Array of gross pay calculations for each employee
  135. // theSize - Number of employees to process
  136. //
  137. // Returns: Nothing (call by reference)
  138. //
  139. //**************************************************************
  140.  
  141. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  142. float overtimeHrs[], float grossPay[], int theSize)
  143. {
  144.  
  145. int i; // loop index
  146.  
  147. // access and print each employee
  148. for (i = 0; i < theSize; ++i)
  149. {
  150. // TODO: add code to print out each employee one at a time
  151. printf ("\t%06ld %5.2f %5.1f %5.1f %7.2f\n",
  152. clockNumber[i], wageRate[i], hours[i],
  153. overtimeHrs[i], grossPay[i]);
  154. }
  155. }
  156.  
  157.  
  158. // TODO: Add other functions here as needed
  159. // ... remember your comment block headers for each function
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   0.0    -nan
	526488  9.75  42.5   0.0    0.00
	765349 10.50  37.0   0.0    0.00
	034645 12.25  45.0   0.0    0.00
	127615  8.35   0.0   0.0   -0.00