fork(1) 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 called by reference
  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. void getHours (long int clockNumber[], float hours[], int size);
  28. void printHeader (void);
  29. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  30. float overtimeHrs[], float grossPay[], int size);
  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. float overtimeHrs[NUM_EMPL]; // overtime hours
  43. float wageRate[NUM_EMPL] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  44.  
  45. // Read in the hours worked for each employee
  46. getHours (clockNumber, hours, NUM_EMPL);
  47.  
  48. // TODO: Function call to calculate overtime hours
  49.  
  50. // TODO: Function call to calculate gross pay
  51.  
  52. // Print the initial table header
  53. printHeader ();
  54.  
  55. // Function call to output results to the screen
  56. printEmp (clockNumber, wageRate, hours,
  57. overtimeHrs, grossPay, NUM_EMPL);
  58.  
  59. return (0);
  60.  
  61. } // main
  62.  
  63. //***************************************************************
  64. // Function: getHours
  65. //
  66. // Purpose: Obtains input from user, the number of hours worked
  67. // per employee and stores the results in an array that is
  68. // passed back to the calling function by reference.
  69. //
  70. // Parameters:
  71. //
  72. // clockNumber - Array of employee clock numbers for each employee
  73. // hours - Array of hours worked by each employee
  74. // size - Number of employees to process
  75. //
  76. // Returns: Nothing (call by reference)
  77. //
  78. //**************************************************************
  79.  
  80. void getHours (long int clockNumber[], float hours[], int size)
  81. {
  82.  
  83. int i; // loop and array index
  84.  
  85. // Read in hours for each employee
  86. for (i= 0; i < size; ++i)
  87. {
  88. printf("\nEnter hours worked by emp # %06li: ", clockNumber[i]);
  89. scanf ("%f", &hours[i]);
  90. }
  91.  
  92. } // getHours
  93.  
  94. //**************************************************************
  95. // Function: printHeader
  96. //
  97. // Purpose: Prints the initial table header information.
  98. //
  99. // Parameters: none
  100. //
  101. // Returns: void
  102. //
  103. //**************************************************************
  104.  
  105. void printHeader (void)
  106. {
  107.  
  108. printf ("\n\n*** Pay Calculator ***\n");
  109.  
  110. // print the table header
  111. printf("\nClock# Wage Hours OT Gross\n");
  112. printf("------------------------------------------------\n");
  113.  
  114. } // printHeader
  115.  
  116. //**************************************************************
  117. // Function: printEmp
  118. //
  119. // Purpose: Prints out all the employee information in a
  120. // nice and orderly table format.
  121. //
  122. // Parameters:
  123. //
  124. // clockNumber - Array of employee clock numbers
  125. // wageRate - Array of employee wages per hour
  126. // hours - Array of number of hours worked by an employee
  127. // overtimeHrs - Array of overtime hours for each employee
  128. // grossPay - Array of gross pay calculations for each employee
  129. // size - Number of employees to process
  130. //
  131. // Returns: Nothing (call by reference)
  132. //
  133. //**************************************************************
  134.  
  135. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  136. float overtimeHrs[], float grossPay[], int size)
  137. {
  138. int i; // loop and array index
  139.  
  140. // access and print each employee
  141. for (i = 0; i < size; ++i)
  142. {
  143. // TODO: add code to print out each employee one at a time
  144. }
  145. }
  146.  
  147. // TODO: Add other functions here as needed
  148. // ... remember your comment block headers for each function
Success #stdin #stdout 0s 5432KB
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
------------------------------------------------