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