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