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 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.  
  46. // process each employee
  47. for (i = 0; i < NUM_EMPL; ++i)
  48. {
  49.  
  50. // Read in hours for employee
  51. hours[i] = getHours (clockNumber[i]);
  52.  
  53. // TODO: Function call to calculate overtime hours
  54.  
  55. // TODO: Function call to calculate gross pay
  56.  
  57. }
  58.  
  59. // print the header info
  60. printHeader();
  61.  
  62. // print out each employee
  63. for (i = 0; i < NUM_EMPL; ++i)
  64. {
  65.  
  66. // Print all the employees - call by value
  67. printEmp (clockNumber[i], wageRate[i], hours[i],
  68. overtimeHrs[i], grossPay[i]);
  69.  
  70. } // for
  71.  
  72. return (0);
  73.  
  74. } // main
  75.  
  76. //**************************************************************
  77. // Function: getHours
  78. //
  79. // Purpose: Obtains input from user, the number of hours worked
  80. // per employee and stores the result in a local variable
  81. // that is passed back to the calling function.
  82. //
  83. // Parameters: clockNumber - The unique employee ID
  84. //
  85. // Returns: hoursWorked - hours worked in a given week
  86. //
  87. //**************************************************************
  88.  
  89. float getHours (long int clockNumber)
  90. {
  91.  
  92. float hoursWorked; // hours worked in a given week
  93.  
  94. // Read in hours for employee
  95. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  96. scanf ("%f", &hoursWorked);
  97.  
  98. // return hours back to the calling function
  99. return (hoursWorked);
  100.  
  101. } // getHours
  102.  
  103. //**************************************************************
  104. // Function: printHeader
  105. //
  106. // Purpose: Prints the initial table header information.
  107. //
  108. // Parameters: none
  109. //
  110. // Returns: void
  111. //
  112. //**************************************************************
  113.  
  114. void printHeader (void)
  115. {
  116.  
  117. printf ("\n\n*** Pay Calculator ***\n");
  118.  
  119. // print the table header
  120. printf("\nClock# Wage Hours OT Gross\n");
  121. printf("------------------------------------------------\n");
  122.  
  123. } // printHeader
  124.  
  125. //*************************************************************
  126. // Function: printEmp
  127. //
  128. // Purpose: Prints out all the information for an employee
  129. // in a nice and orderly table format.
  130. //
  131. // Parameters:
  132. //
  133. // clockNumber - unique employee ID
  134. // wageRate - hourly wage rate
  135. // hours - Hours worked for the week
  136. // overtimeHrs - overtime hours worked in a week
  137. // grossPay - gross pay for the week
  138. //
  139. // Returns: void
  140. //
  141. //**************************************************************
  142.  
  143. void printEmp (long int clockNumber, float wageRate, float hours,
  144. float overtimeHrs, float grossPay)
  145. {
  146.  
  147. // print the employee
  148.  
  149. // TODO: add code to print out a single employee
  150. }
Success #stdin #stdout 0.01s 5376KB
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
------------------------------------------------