fork(1) download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Kevin Hernandez
  6. //
  7. // Class: C Programming, Summer 2026
  8. //
  9. // Date: 07/05/2026
  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 SIZE 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 theSize );
  45. void printHeader (void);
  46. void printEmp (struct employee emp [ ], int theSize);
  47.  
  48. // TODO: add your function prototypes here
  49. void calcOT (struct employee employeeData[], int theSize);
  50. void calcGross (struct employee employeeData[], int theSize);
  51.  
  52. int main ()
  53. {
  54. // Set up a local variable and initialize the clock and wages of my employees
  55. struct employee employeeData [SIZE] = {
  56. { 98401, 10.60 },
  57. { 526488, 9.75 },
  58. { 765349, 10.50 },
  59. { 34645, 12.25 },
  60. { 127615, 8.35 }
  61. };
  62.  
  63. // Call function needed to read hours
  64. getHours (employeeData, SIZE);
  65.  
  66. // TODO: Call functions calculate ot hours and gross pay
  67. calcOT (employeeData, SIZE);
  68.  
  69. // TODO: Call function to print the table column headers
  70. calcGross (employeeData, SIZE);
  71.  
  72. // Print a table header
  73. printHeader();
  74.  
  75. // Function call to output results to the screen in table format
  76. printEmp (employeeData, SIZE);
  77.  
  78. return(0); // success
  79.  
  80. } // main
  81.  
  82. //**************************************************************
  83. // Function: getHours
  84. //
  85. // Purpose: Obtains input from user, the number of hours worked
  86. // per employee and stores the result in an array of structures
  87. // that is passed back to the calling function by reference.
  88. //
  89. // Parameters:
  90. //
  91. // employeeData - an array of structures containing Employees
  92. // theSize - number of employees to process
  93. //
  94. // Returns: Nothing (void)
  95. //
  96. //**************************************************************
  97.  
  98. void getHours (struct employee employeeData[], int theSize )
  99. {
  100.  
  101. int i; // loop and array index
  102.  
  103. // read hours in for each employee
  104. for (i = 0; i < theSize ; ++i)
  105. {
  106. printf("\nEnter hours worked by emp # %06li: ",
  107. employeeData[i].clockNumber);
  108. scanf ("%f", &employeeData[i].hours);
  109. } // for
  110.  
  111. } // getHours
  112.  
  113. //**************************************************************
  114. // Function: printHeader
  115. //
  116. // Purpose: Prints the initial table header information.
  117. //
  118. // Parameters: none
  119. //
  120. // Returns: void
  121. //
  122. //**************************************************************
  123.  
  124. void printHeader (void)
  125. {
  126.  
  127. printf ("\n\n*** Pay Calculator ***\n");
  128.  
  129. // print the table header
  130. printf("\nClock# Wage Hours OT Gross\n");
  131. printf("------------------------------------------------\n");
  132.  
  133. } // printHeader
  134.  
  135. // TODO: add your functions here
  136.  
  137. void calcOT (struct employee employeeData[], int theSize)
  138. {
  139. int i;
  140.  
  141. for (i=0; i < theSize; ++i)
  142. {
  143. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  144. }
  145.  
  146. }
  147.  
  148. void calcGross (struct employee employeeData[], int theSize)
  149. {
  150. int i;
  151. float normalPay;
  152. float overtimePay;
  153.  
  154. normalPay = STD_HOURS * employeeData[i].wageRate;
  155. overtimePay = employeeData[i].overtimeHrs * employeeData[i].wageRate * OT_RATE;
  156.  
  157. for (i = 0; i < theSize; ++i)
  158. {
  159. employeeData[i].grossPay = normalPay + overtimePay;
  160. }
  161.  
  162. }
  163.  
  164. // ********************************************************************
  165. // Function: printEmp
  166. //
  167. // Purpose: Outputs to screen in a table format the following
  168. // information about an employee: Clock, Wage,
  169. // Hours, Overtime Hours, and Gross Pay.
  170. //
  171. // Parameters:
  172. //
  173. // employeeData - an array of structures containing Employees
  174. // theSize - number of employees to process
  175. //
  176. // Returns: Nothing (void)
  177. //
  178. // *********************************************************************
  179.  
  180. void printEmp ( struct employee employeeData[], int theSize )
  181. {
  182. int i; // loop and array index
  183.  
  184. // print information about each employee
  185. for (i = 0; i < theSize ; ++i)
  186. {
  187. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  188. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  189. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  190. } /* for */
  191.  
  192. } // printEmp
Success #stdin #stdout 0s 5316KB
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 11.0   598.90
 526488  9.75 42.5  2.5   598.90
 765349 10.50 37.0 -3.0   598.90
 034645 12.25 45.0  5.0   598.90
 127615  8.35  0.0 -40.0   598.90