fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: <replace with your name>
  6. //
  7. // Class: C Programming, <replace with Semester and Year>
  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 are called by value
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20.  
  21. // constants
  22. #define NUM_EMPL 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.  
  34. int main ()
  35. {
  36.  
  37. /* Variable Declarations */
  38.  
  39. long int clockNumber[NUM_EMPL] = {98401,526488,765349,34645,127615}; // ID
  40. float grossPay[NUM_EMPL]; // gross pay
  41. float hours[NUM_EMPL]; // hours worked in a given week
  42. int i; // loop and array index
  43. float overtimeHrs[NUM_EMPL]; // overtime hours
  44. float wageRate[NUM_EMPL] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  45. float overtimeRate [NUM_EMPL]; // normal wage rate * OT_RATE
  46. float overtimePay [NUM_EMPL];
  47. float normalPay [NUM_EMPL];
  48.  
  49. // process each employee
  50. for (i = 0; i < NUM_EMPL; ++i)
  51. {
  52.  
  53. // Read in hours for employee
  54. hours[i] = getHours (clockNumber[i]);
  55.  
  56. // Calculate overtime and gross pay for employee
  57. if (hours[i] >= STD_WORK_WEEK)
  58. {
  59. overtimeHrs[i] = hours[i] - STD_WORK_WEEK;
  60. normalPay[i] = wageRate[i] * STD_WORK_WEEK;
  61. overtimeRate[i] = wageRate[i] * OVERTIME_RATE;
  62. overtimePay[i] = overtimeRate[i] * overtimeHrs[i];
  63. }
  64. else // no OT
  65. {
  66. overtimeHrs[i] = 0;
  67. overtimePay[i] = 0;
  68. normalPay[i] = wageRate[i] * hours[i];
  69. }
  70.  
  71. // Calculate Gross Pay
  72. grossPay[i] = normalPay[i] + overtimePay[i];
  73.  
  74. }
  75.  
  76. // print the header info
  77. printHeader();
  78.  
  79. // print out each employee
  80. for (i = 0; i < NUM_EMPL; ++i)
  81. {
  82.  
  83. // Print all the employees - call by value
  84. printEmp (clockNumber[i], wageRate[i], hours[i],
  85. overtimeHrs[i], grossPay[i]);
  86.  
  87. } // for
  88.  
  89. return (0);
  90.  
  91. } // main
  92.  
  93. //**************************************************************
  94. // Function: getHours
  95. //
  96. // Purpose: Obtains input from user, the number of hours worked
  97. // per employee and stores the result in a local variable
  98. // that is passed back to the calling function.
  99. //
  100. // Parameters: clockNumber - The unique employee ID
  101. //
  102. // Returns: hoursWorked - hours worked in a given week
  103. //
  104. //**************************************************************
  105.  
  106. float getHours (long int clockNumber)
  107. {
  108.  
  109. float hoursWorked; // hours worked in a given week
  110.  
  111. // Read in hours for employee
  112. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  113. scanf ("%f", &hoursWorked);
  114.  
  115. // return hours back to the calling function
  116. return (hoursWorked);
  117.  
  118. } // getHours
  119.  
  120. //**************************************************************
  121. // Function: printHeader
  122. //
  123. // Purpose: Prints the initial table header information.
  124. //
  125. // Parameters: none
  126. //
  127. // Returns: void
  128. //
  129. //**************************************************************
  130.  
  131. void printHeader (void)
  132. {
  133.  
  134. printf ("\n\n*** Pay Calculator ***\n");
  135.  
  136. // print the table header
  137. printf("\nClock# Wage Hours OT Gross\n");
  138. printf("------------------------------------------------\n");
  139.  
  140. } // printHeader
  141.  
  142. //*************************************************************
  143. // Function: printEmp
  144. //
  145. // Purpose: Prints out all the information for an employee
  146. // in a nice and orderly table format.
  147. //
  148. // Parameters:
  149. //
  150. // clockNumber - unique employee ID
  151. // wageRate - hourly wage rate
  152. // hours - Hours worked for the week
  153. // overtimeHrs - overtime hours worked in a week
  154. // grossPay - gross pay for the week
  155. //
  156. // Returns: void
  157. //
  158. //**************************************************************
  159.  
  160. void printEmp (long int clockNumber, float wageRate, float hours,
  161. float overtimeHrs, float grossPay)
  162. {
  163.  
  164. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  165. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  166.  
  167. }
  168.  
  169. // TODO: Add other functions here as needed
  170. // ... remember your comment block headers for each function
Success #stdin #stdout 0s 5312KB
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