fork download
  1. /* Homework: 4 */
  2. /* */
  3. /* Name: Susie Smith */
  4. /* */
  5. /* Class: C Programming, Fall 2019 */
  6. /* */
  7. /* Date: 10/06/19 */
  8. /* */
  9. /* Description: Program which determines gross pay including hours worked, */
  10. /*overtime and wage using function. */
  11. /*This version does not use file pointers. */
  12.  
  13. #include <stdio.h>
  14.  
  15. /* constants */
  16. #define SIZE 5
  17. #define OVERTIME_RATE 1.5f
  18. #define STD_WORK_WEEK 40.0f
  19.  
  20. /* function prototypes */
  21. float getHours (long clockNumber);
  22. void printData (long int clockNumber[], float wageRate[], float hours[],
  23. float overtime[], float gross[], int size);
  24. float overtimeCalc (float hours);
  25. float grossWage (float hours, float wageRate, float overtime);
  26.  
  27.  
  28. int main()
  29. {
  30.  
  31. /* Variable Declarations */
  32.  
  33. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; /* ID */
  34. float gross[SIZE]; /* gross pay */
  35. float hours[SIZE]; /* hours worked in a given week */
  36. int i; /* loop and array index */
  37. float overtime[SIZE]; /* overtime hours */
  38. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; /* hourly wage rate */
  39.  
  40.  
  41. for (i = 0; i < SIZE; i++)
  42. {
  43.  
  44. /* Function call to get input from user. */
  45. hours[i] = getHours (clockNumber[i]);
  46.  
  47. /* Function call to calculate overtime */
  48. overtime[i] = overtimeCalc (hours[i]);
  49.  
  50. printf("\nHours is %5.1f, wage is %5.2f, and overtime is %5.1f\n",
  51. hours[i], wageRate[i], overtime[i]);
  52.  
  53. /* Function call to calculate gross pay */
  54. gross[i] = grossWage (hours[i], wageRate[i], overtime[i]);
  55.  
  56. printf("\nGross is %8.2f\n", gross[i]);
  57.  
  58. }
  59.  
  60.  
  61.  
  62. /* Print all the employees - call by reference */
  63. printData (clockNumber, wageRate, hours,
  64. overtime, gross, SIZE);
  65.  
  66. return (0);
  67.  
  68. }
  69.  
  70.  
  71.  
  72. //**************************************************************/
  73. // Function: getHours
  74. //
  75. // Purpose: Obtains input from user, the number of hours worked
  76. // per employee and stores the result in a local variable
  77. // that is passed back to the calling function.
  78. //
  79. // Parameters: clockNumber - The clock number of the employee
  80. //
  81. // Returns: hoursWorked - hours worked by the employee in a given week
  82. //
  83. //**************************************************************/
  84.  
  85. float getHours (long int clockNumber)
  86. {
  87.  
  88. float hoursWorked; /* hours worked in a given week */
  89.  
  90. /* Get Hours for each employee */
  91. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  92. scanf ("%f", &hoursWorked);
  93.  
  94. return (hoursWorked);
  95. }
  96.  
  97. //**************************************************************/
  98. // Function: printData
  99. //
  100. // Purpose: Prints out all the employee information in a
  101. // nice and orderly table format.
  102. //
  103. // Parameters:
  104. //
  105. // clockNumber - Array of employee clock numbers
  106. // wageRate - Array of employee wages per hour
  107. // hrs - Array of number of hours worked by an employee
  108. // overtime - Array of overtime hours for each employee
  109. // gross - Array of gross pay calculations for each employee
  110. // size - Number of employees to process
  111. //
  112. // Returns: Nothing (call by reference)
  113. //
  114. //**************************************************************/
  115.  
  116. void printData (long int clockNumber[], float wageRate[], float hours[],
  117. float overtime[], float gross[], int size)
  118. {
  119. int count;
  120. printf ("\n\n\tSusie Smith, C Programming, Fouth Homework Assignment\n");
  121. printf ("\t----------------------------------------------------------\n");
  122. printf ("\tClock# Wage Hours Overtime Gross\n");
  123. printf ("\t----------------------------------------------------------\n");
  124. for(count = 0; count < SIZE; count++)
  125. {
  126. printf ("\t%06li %10.2f %10.1f %10.1f %10.2f\n",clockNumber[count], wageRate[count], hours[count], overtime[count], gross[count]);
  127. }
  128. }
  129.  
  130. //**************************************************************/
  131. // Function: overtimeCalc
  132. //
  133. // Purpose: Calculates the amount of overtime hours an
  134. // an employee has worked in the week.
  135. //
  136. // Parameters: hours - The amount of hours an emloyees has worked
  137. //
  138. // Returns: overtime - The amount of hours worked exceeded STD_WORK_WEEK
  139. //
  140. //**************************************************************/
  141. float overtimeCalc (float hours)
  142. {
  143. float overtime; /* overtime hours */
  144.  
  145. /* check for overtime */
  146. if (hours > STD_WORK_WEEK)
  147. overtime = (hours - STD_WORK_WEEK);
  148. else
  149. overtime = 0;
  150.  
  151.  
  152. return (overtime);
  153.  
  154. }
  155. //**************************************************************/
  156. // Function: grossWage
  157. //
  158. // Purpose: Calculates the gross wages of an employee
  159. // for the week
  160. //
  161. // Parameters: hours - The amount of hours a the emloyee has worked
  162. // overtime - the amount of overtime hours worked
  163. // wageRate - hourly wage of the employee
  164. //
  165. // Returns: gross[] - gross pay for the week
  166. //
  167. //**************************************************************/
  168.  
  169. float grossWage (float hours, float wageRate, float overtime )
  170. {
  171.  
  172. float otPay;
  173.  
  174.  
  175. if (hours > STD_WORK_WEEK)
  176. {
  177. // Calculate overtime and gross pay for employee
  178. otPay = ((OVERTIME_RATE * wageRate) * overtime);
  179. otPay += (wageRate * STD_WORK_WEEK);
  180.  
  181. }
  182. else
  183. {
  184. otPay = (wageRate * hours);
  185. printf ("\nelse\n");
  186. }
  187.  
  188. printf ("\n\notpay is %8.2f\n", otPay);
  189.  
  190. return (otPay);
  191.  
  192. }
  193.  
Success #stdin #stdout 0s 4264KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
Enter hours worked by emp # 098401: 
Hours is  51.0, wage is 10.60, and overtime is  11.0


otpay is   598.90

Gross is   598.90

Enter hours worked by emp # 526488: 
Hours is  42.5, wage is  9.75, and overtime is   2.5


otpay is   426.56

Gross is   426.56

Enter hours worked by emp # 765349: 
Hours is  37.0, wage is 10.50, and overtime is   0.0

else


otpay is   388.50

Gross is   388.50

Enter hours worked by emp # 034645: 
Hours is  45.0, wage is 12.25, and overtime is   5.0


otpay is   581.88

Gross is   581.88

Enter hours worked by emp # 127615: 
Hours is   0.0, wage is  8.35, and overtime is   0.0

else


otpay is     0.00

Gross is     0.00


	Susie Smith, C Programming, Fouth Homework Assignment
	----------------------------------------------------------
	Clock#      Wage       Hours      Overtime    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