fork 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. // ********************************************************************
  136. // Function: printEmp
  137. //
  138. // Purpose: Outputs to screen in a table format the following
  139. // information about an employee: Clock, Wage,
  140. // Hours, Overtime Hours, and Gross Pay.
  141. //
  142. // Parameters:
  143. //
  144. // employeeData - an array of structures containing Employees
  145. // theSize - number of employees to process
  146. //
  147. // Returns: Nothing (void)
  148. //
  149. // *********************************************************************
  150.  
  151. void printEmp ( struct employee employeeData[], int theSize )
  152. {
  153. int i; // loop and array index
  154.  
  155. // print information about each employee
  156. for (i = 0; i < theSize ; ++i)
  157. {
  158. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  159. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  160. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  161. } /* for */
  162.  
  163. } // printEmp
  164.  
  165. // TODO: add your functions here
  166.  
  167. void calcOT (struct employee employeeData[], int theSize)
  168. {
  169. int i;
  170.  
  171. for (i=0; i < theSize; ++i)
  172. {
  173. if (employeeData[i].hours > STD_HOURS)
  174. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  175. else
  176. employeeData[i].overtimeHrs = 0;
  177. }
  178.  
  179. }
  180.  
  181. void calcGross (struct employee employeeData[], int theSize)
  182. {
  183. int i;
  184. float normalPay;
  185. float overtimePay;
  186.  
  187. for (i = 0; i < theSize; ++i)
  188. {
  189. if (employeeData[i].hours > STD_HOURS)
  190. normalPay = STD_HOURS * employeeData[i].wageRate;
  191. else
  192. normalPay = employeeData[i].hours * employeeData[i].wageRate;
  193.  
  194. overtimePay = employeeData[i].overtimeHrs * employeeData[i].wageRate * OT_RATE;
  195. employeeData[i].grossPay = normalPay + overtimePay;
  196. }
  197.  
  198. }
Success #stdin #stdout 0s 5312KB
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   426.56
 765349 10.50 37.0  0.0   388.50
 034645 12.25 45.0  5.0   581.88
 127615  8.35  0.0  0.0     0.00