fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Hamza Naseer
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: <replace with the current date>
  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 called by reference
  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. void getHours (long int clockNumber[], float hours[], int theSize);
  28. void printHeader (void);
  29. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  30. float overtimeHrs[], float grossPay[], int theSize);
  31.  
  32. void calcOvertime (float hours[], float overtimeHrs[], int theSize);
  33. void calcGrossPay (float wageRate[], float hours[], float overtimeHrs[],
  34. float grossPay[], int theSize);
  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. float overtimeHrs[SIZE]; // overtime hours
  45. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  46.  
  47. // Read in the hours worked for each employee
  48. getHours (clockNumber, hours, SIZE);
  49.  
  50. calcOvertime(hours, overtimeHrs, SIZE);
  51.  
  52. calcGrossPay(wageRate, hours, overtimeHrs, grossPay, SIZE);
  53.  
  54. // Print the initial table header
  55. printHeader ();
  56.  
  57. // Function call to output results to the screen
  58. printEmp (clockNumber, wageRate, hours,
  59. overtimeHrs, grossPay, SIZE);
  60.  
  61. return (0);
  62.  
  63. } // main
  64.  
  65. //***************************************************************
  66. // Function: getHours
  67. //
  68. // Purpose: Obtains input from user, the number of hours worked
  69. // per employee and stores the results in an array that is
  70. // passed back to the calling function by reference.
  71. //
  72. // Parameters:
  73. //
  74. // clockNumber - Array of employee clock numbers for each employee
  75. // hours - Array of hours worked by each employee
  76. // theSize - Number of employees to process
  77. //
  78. // Returns: Nothing (call by reference)
  79. //
  80. //**************************************************************
  81.  
  82. void getHours (long int clockNumber[], float hours[], int theSize)
  83. {
  84.  
  85. int i; // loop and array index
  86.  
  87. // Read in hours for each employee
  88. for (i= 0; i < theSize; ++i)
  89. {
  90. printf("\nEnter hours worked by emp # %06li: ", clockNumber[i]);
  91. scanf ("%f", &hours[i]);
  92. }
  93.  
  94. } // getHours
  95.  
  96. //**************************************************************
  97. // Function: printHeader
  98. //
  99. // Purpose: Prints the initial table header information.
  100. //
  101. // Parameters: none
  102. //
  103. // Returns: void
  104. //
  105. //**************************************************************
  106.  
  107. void printHeader (void)
  108. {
  109.  
  110. printf ("\n\n*** Pay Calculator ***\n");
  111.  
  112. // print the table header
  113. printf("\nClock# Wage Hours OT Gross\n");
  114. printf("------------------------------------------------\n");
  115.  
  116. } // printHeader
  117.  
  118. //**************************************************************
  119. // Function: printEmp
  120. //
  121. // Purpose: Prints out all the employee information in a
  122. // nice and orderly table format.
  123. //
  124. // Parameters:
  125. //
  126. // clockNumber - Array of employee clock numbers
  127. // wageRate - Array of employee wages per hour
  128. // hours - Array of number of hours worked by an employee
  129. // overtimeHrs - Array of overtime hours for each employee
  130. // grossPay - Array of gross pay calculations for each employee
  131. // theSize - Number of employees to process
  132. //
  133. // Returns: Nothing (call by reference)
  134. //
  135. //**************************************************************
  136.  
  137. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  138. float overtimeHrs[], float grossPay[], int theSize)
  139. {
  140. int i; // loop and array index
  141.  
  142. // access and print each employee
  143. for (i = 0; i < theSize; ++i)
  144. {
  145. printf("%06li %.2f %.2f %.2f %.2f\n", clockNumber[i], wageRate[i],
  146. hours[i], overtimeHrs[i], grossPay[i]);
  147. }
  148. }
  149.  
  150. void calcOvertime (float hours[], float overtimeHrs[], int theSize)
  151. {
  152. int i;
  153. for (i = 0; i < theSize; ++i)
  154. {
  155. if (hours[i] > STD_WORK_WEEK)
  156. {
  157. overtimeHrs[i] = hours[i] - STD_WORK_WEEK;
  158. }
  159. else
  160. {
  161. overtimeHrs[i] = 0.0f;
  162. }
  163. }
  164. }
  165.  
  166. void calcGrossPay (float wageRate[], float hours[], float overtimeHrs[],
  167. float grossPay[], int theSize)
  168. {
  169. int i;
  170. for (i = 0; i < theSize; ++i)
  171. {
  172. if (hours[i] > STD_WORK_WEEK)
  173. {
  174. grossPay[i] = (wageRate[i] * STD_WORK_WEEK) +
  175. (overtimeHrs[i] * wageRate[i] * OVERTIME_RATE);
  176. }
  177. else
  178. {
  179. grossPay[i] = wageRate[i] * hours[i];
  180. }
  181. }
  182. }
Success #stdin #stdout 0.01s 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.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