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. // Call by Value 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 int 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. float getHours (long int clockNumber);
  44. void printHeader (void);
  45. void printEmp (long int clockNumber, float wageRate, float hours,
  46. float overtimeHrs, float grossPay);
  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. // print out each employee
  78. for (i = 0; i < NUM_EMPL; ++i)
  79. {
  80. printEmp (employeeData[i].clockNumber,
  81. employeeData[i].wageRate,
  82. employeeData[i].hours,
  83. employeeData[i].overtimeHrs,
  84. employeeData[i].grossPay);
  85. }
  86.  
  87. return(0); // success
  88.  
  89. } // main
  90.  
  91. //**************************************************************
  92. // Function: getHours
  93. //
  94. // Purpose: Obtains input from user, the number of hours worked
  95. // per employee and stores the result in a local variable
  96. // that is passed back to the calling function.
  97. //
  98. // Parameters: clockNumber - The unique employee ID
  99. //
  100. // Returns: hoursWorked - hours worked in a given week
  101. //
  102. //**************************************************************
  103.  
  104. float getHours (long int clockNumber)
  105. {
  106.  
  107. float hoursWorked; // hours worked in a given week
  108.  
  109. // Read in hours for employee
  110. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  111. scanf ("%f", &hoursWorked);
  112.  
  113. // return hours back to the calling function
  114. return (hoursWorked);
  115.  
  116. } // getHours
  117.  
  118. //**************************************************************
  119. // Function: printHeader
  120. //
  121. // Purpose: Prints the initial table header information.
  122. //
  123. // Parameters: none
  124. //
  125. // Returns: void
  126. //
  127. //**************************************************************
  128.  
  129. void printHeader (void)
  130. {
  131.  
  132. printf ("\n\n*** Pay Calculator ***\n");
  133.  
  134. // print the table header
  135. printf("\nClock# Wage Hours OT Gross\n");
  136. printf("------------------------------------------------\n");
  137.  
  138. } // printHeader
  139.  
  140.  
  141. //*************************************************************
  142. // Function: printEmp
  143. //
  144. // Purpose: Prints out all the information for an employee
  145. // in a nice and orderly table format.
  146. //
  147. // Parameters:
  148. //
  149. // clockNumber - unique employee ID
  150. // wageRate - hourly wage rate
  151. // hours - Hours worked for the week
  152. // overtimeHrs - overtime hours worked in a week
  153. // grossPay - gross pay for the week
  154. //
  155. // Returns: void
  156. //
  157. //**************************************************************
  158.  
  159. void printEmp (long int clockNumber, float wageRate, float hours,
  160. float overtimeHrs, float grossPay)
  161. {
  162.  
  163. // Print out a single employee
  164. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  165. clockNumber, wageRate, hours,
  166. overtimeHrs, grossPay);
  167.  
  168. } // printEmp
  169.  
  170. // TODO: Add your functions here
Success #stdin #stdout 0s 5436KB
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