fork(2) download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  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. // Call by reference design
  16. //
  17. //********************************************************
  18.  
  19. // Define and Includes
  20.  
  21. #include <stdio.h>
  22.  
  23. // Define Constants
  24. #define NUM_EMPL 5
  25. #define STD_HOURS 40.0
  26. #define OT_RATE 1.5
  27.  
  28. // Define a global structure to pass employee data between functions
  29. // Note that the structure type is global, but you don't want a variable
  30. // of that type to be global. Best to declare a variable of that type
  31. // in a function like main or another function and pass as needed.
  32.  
  33. struct employee
  34. {
  35. long clockNumber;
  36. float wageRate;
  37. float hours;
  38. float overtimeHrs;
  39. float grossPay;
  40. };
  41.  
  42. // define prototypes here for each function except main
  43.  
  44. void getHours (struct employee employeeData[], int size );
  45. void printHeader (void);
  46. void printEmp (struct employee emp [ ], int size);
  47.  
  48. // TODO: add your function prototypes here
  49.  
  50. int main ()
  51. {
  52. // Set up a local variable and initialize the clock and wages of my employees
  53. struct employee employeeData [NUM_EMPL] = {
  54. { 98401, 10.60 },
  55. { 526488, 9.75 },
  56. { 765349, 10.50 },
  57. { 34645, 12.25 },
  58. { 127615, 8.35 }
  59. };
  60.  
  61. // Call function needed to read hours
  62. getHours (employeeData, NUM_EMPL);
  63.  
  64. // TODO: Call functions calculate ot hours and gross pay
  65.  
  66. // TODO: Call function to print the table column headers
  67.  
  68. // Print a table header
  69. printHeader();
  70.  
  71. // Function call to output results to the screen in table format
  72. printEmp (employeeData, NUM_EMPL);
  73.  
  74. return(0); // success
  75.  
  76. } // main
  77.  
  78. //**************************************************************
  79. // Function: getHours
  80. //
  81. // Purpose: Obtains input from user, the number of hours worked
  82. // per employee and stores the result in an array of structures
  83. // that is passed back to the calling function by reference.
  84. //
  85. // Parameters:
  86. //
  87. // employeeData - an array of structures containing Employees
  88. // size - number of employees to process
  89. //
  90. // Returns: Nothing (void)
  91. //
  92. //**************************************************************
  93.  
  94. void getHours (struct employee employeeData[], int size )
  95. {
  96.  
  97. int i; // loop and array index
  98.  
  99. // read hours in for each employee
  100. for (i = 0; i < size ; ++i)
  101. {
  102. printf("\nEnter hours worked by emp # %06li: ",
  103. employeeData[i].clockNumber);
  104. scanf ("%f", &employeeData[i].hours);
  105. } // for
  106.  
  107. } // getHours
  108.  
  109. //**************************************************************
  110. // Function: printHeader
  111. //
  112. // Purpose: Prints the initial table header information.
  113. //
  114. // Parameters: none
  115. //
  116. // Returns: void
  117. //
  118. //**************************************************************
  119.  
  120. void printHeader (void)
  121. {
  122.  
  123. printf ("\n\n*** Pay Calculator ***\n");
  124.  
  125. // print the table header
  126. printf("\nClock# Wage Hours OT Gross\n");
  127. printf("------------------------------------------------\n");
  128.  
  129. } // printHeader
  130.  
  131. // ********************************************************************
  132. // Function: printEmp
  133. //
  134. // Purpose: Outputs to screen in a table format the following
  135. // information about an employee: Clock, Wage,
  136. // Hours, Overtime Hours, and Gross Pay.
  137. //
  138. // Parameters:
  139. //
  140. // employeeData - an array of structures containing Employees
  141. // size - number of employees to process
  142. //
  143. // Returns: Nothing (void)
  144. //
  145. // *********************************************************************
  146.  
  147. void printEmp ( struct employee employeeData[], int size )
  148. {
  149. int i; // loop and array index
  150.  
  151. // print information about each employee
  152. for (i = 0; i < size ; ++i)
  153. {
  154. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  155. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  156. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  157. } /* for */
  158.  
  159. } // printEmp
  160.  
  161. // TODO: add your functions here
Success #stdin #stdout 0.01s 5392KB
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  0.0     0.00
 526488  9.75 42.5  0.0     0.00
 765349 10.50 37.0  0.0     0.00
 034645 12.25 45.0  0.0     0.00
 127615  8.35  0.0  0.0     0.00