fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Andrea Huskey
  6. //
  7. // Class: C Programming, Summer 2026
  8. //
  9. // Date: June 29, 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 Value design
  16. //
  17. //********************************************************
  18.  
  19. // Define and Includes
  20. #include <stdio.h>
  21.  
  22. // Define Constants
  23. #define SIZE 5
  24. #define STD_HOURS 40.0
  25. #define OT_RATE 1.5
  26.  
  27. // Define a global structure to pass employee data between functions
  28. // Note that the structure type is global, but you don't want a variable
  29. // of that type to be global. Best to declare a variable of that type
  30. // in a function like main or another function and pass as needed.
  31. struct employee
  32. {
  33. long clockNumber;
  34. float wageRate;
  35. float hours;
  36. float overtimeHrs;
  37. float grossPay;
  38. };
  39.  
  40. // define prototypes here for each function except main
  41. void getHours (struct employee employeeData[], int theSize );
  42. void printHeader (void);
  43. void printEmp (struct employee emp [ ], int theSize);
  44.  
  45. // TODO: add your function prototypes here
  46. void calcOvertime (struct employee employeeData[], int theSize);
  47. void calcGrossPay (struct employee employeeData[], int theSize);
  48.  
  49. int main ()
  50. {
  51. // Set up a local variable and initialize the clock and wages of my employees
  52. struct employee employeeData [SIZE] = {
  53. { 98401, 10.60 },
  54. { 526488, 9.75 },
  55. { 765349, 10.50 },
  56. { 34645, 12.25 },
  57. { 127615, 8.35 }
  58. };
  59.  
  60. // Call function needed to read hours
  61. getHours (employeeData, SIZE);
  62.  
  63. // TODO: Call functions calculate ot hours and gross pay
  64. calcOvertime (employeeData, SIZE);
  65. calcGrossPay (employeeData, SIZE);
  66.  
  67. // TODO: Call function to print the table column headers
  68. // Print a table header
  69. printHeader();
  70.  
  71. // Function call to output results to the screen in table format
  72. printEmp (employeeData, SIZE);
  73.  
  74. return(0); // success
  75.  
  76. } // main
  77.  
  78. //**************************************************************
  79. // Function: getHours
  80. //
  81. // Purpose: Input for the total hours worked
  82. // per employee and used for
  83. // calling function by reference.
  84. //
  85. // Parameters:
  86. //
  87. // employeeData - an array of structures containing Employees
  88. // theSize - number of employees to process
  89. //
  90. // Returns: Nothing (void)
  91. //
  92. //**************************************************************
  93. void getHours (struct employee employeeData[], int theSize )
  94. {
  95. int i; // loop and array index
  96.  
  97. // read hours in for each employee
  98. for (i = 0; i < theSize ; ++i)
  99. {
  100. printf("\nEnter hours worked by emp # %06li: ",
  101. employeeData[i].clockNumber);
  102. scanf ("%f", &employeeData[i].hours);
  103. } // for
  104.  
  105. } // getHours
  106.  
  107. //**************************************************************
  108. // Function: printHeader
  109. //
  110. // Purpose: Prints the initial table header information.
  111. //
  112. // Parameters: none
  113. //
  114. // Returns: void
  115. //
  116. //**************************************************************
  117. void printHeader (void)
  118. {
  119. printf ("\n\n*** Pay Calculator ***\n");
  120.  
  121. // print the table header
  122. printf("\nClock# Wage Hours OT Gross\n");
  123. printf("------------------------------------------------\n");
  124.  
  125. } // printHeader
  126.  
  127. // ********************************************************************
  128. // Function: printEmp
  129. //
  130. // Purpose: Prints in a table format .
  131. // Clock, Wage, Hours, Overtime Hours, and Gross Pay.
  132. //
  133. //
  134. // Parameters:
  135. //
  136. // employeeData - an array of structures containing Employees
  137. // theSize - number of employees to process
  138. //
  139. // Returns: Nothing (void)
  140. //
  141. // *********************************************************************
  142. void printEmp ( struct employee employeeData[], int theSize )
  143. {
  144. int i; // loop and array index
  145.  
  146. // print information about each employee
  147. for (i = 0; i < theSize ; ++i)
  148. {
  149. // print header column alignments
  150. printf("\n %06li %6.2f %5.1f %6.1f %10.2f",
  151. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  152. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  153. } /* for */
  154. printf("\n");
  155.  
  156. } // printEmp
  157.  
  158. // TODO: add your functions here
  159. //**************************************************************
  160. // Function: calcOvertime
  161. //
  162. // Purpose: Using the reference to
  163. // calculate overtime hours for any time worked over 40 hours.
  164. //
  165. // Parameters: employeeData - array of employee structures
  166. // theSize - total number of employees
  167. //
  168. // Returns: void
  169. //**************************************************************
  170.  
  171. void calcOvertime (struct employee employeeData[], int theSize)
  172. {
  173. int i;
  174. for (i = 0; i < theSize; ++i)
  175. {
  176. if (employeeData[i].hours > STD_HOURS)
  177. {
  178.  
  179. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  180. }
  181. else
  182. {
  183. employeeData[i].overtimeHrs = 0.0;
  184. }
  185. }
  186. }
  187.  
  188. //**************************************************************
  189. // Function: calcGrossPay
  190. //
  191. // Purpose: Pushes by reference through structure
  192. // to calculate the total weekly gross earnings including OT.
  193. //
  194. // Parameters: employeeData - from employee structures
  195. // theSize - total number of employees
  196. //
  197. // Returns: void
  198. //**************************************************************
  199. void calcGrossPay (struct employee employeeData[], int theSize)
  200. {
  201. int i;
  202. for (i = 0; i < theSize; ++i)
  203. {
  204. if (employeeData[i].overtimeHrs > 0.0)
  205. {
  206.  
  207. employeeData[i].grossPay = (STD_HOURS * employeeData[i].wageRate) +
  208. (employeeData[i].overtimeHrs * (employeeData[i].wageRate * OT_RATE));
  209. }
  210. else
  211. {
  212. employeeData[i].grossPay = employeeData[i].hours * employeeData[i].wageRate;
  213. }
  214. }
  215. } // end complete code
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