fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: <Sean Turke>
  6. //
  7. // Class: C Programming, <Fall 2026>
  8. //
  9. // Date: <10/14/26>
  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. void calcOvertime(struct employee employeeData[], int theSize);
  48. void calcGrossPay(struct employee employeeData[], int theSize);
  49.  
  50. // TODO: add your function prototypes here
  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. // Calculate overtime hours
  68. calcOvertime(employeeData, SIZE);
  69.  
  70. // Calculate gross pay
  71. calcGrossPay(employeeData, SIZE);
  72.  
  73. // TODO: Call function to print the table column headers
  74.  
  75. // Print a table header
  76. printHeader();
  77.  
  78. // Function call to output results to the screen in table format
  79. printEmp (employeeData, SIZE);
  80.  
  81. return(0); // success
  82.  
  83. } // main
  84.  
  85. //**************************************************************
  86. // Function: getHours
  87. //
  88. // Purpose: Obtains input from user, the number of hours worked
  89. // per employee and stores the result in an array of structures
  90. // that is passed back to the calling function by reference.
  91. //
  92. // Parameters:
  93. //
  94. // employeeData - an array of structures containing Employees
  95. // theSize - number of employees to process
  96. //
  97. // Returns: Nothing (void)
  98. //
  99. //**************************************************************
  100.  
  101. void getHours (struct employee employeeData[], int theSize )
  102. {
  103.  
  104. int i; // loop and array index
  105.  
  106. // read hours in for each employee
  107. for (i = 0; i < theSize ; ++i)
  108. {
  109. printf("\nEnter hours worked by emp # %06li: ",
  110. employeeData[i].clockNumber);
  111. scanf ("%f", &employeeData[i].hours);
  112. } // for
  113.  
  114. } // getHours
  115.  
  116. //**************************************************************
  117. // Function: printHeader
  118. //
  119. // Purpose: Prints the initial table header information.
  120. //
  121. // Parameters: none
  122. //
  123. // Returns: void
  124. //
  125. //**************************************************************
  126.  
  127. void printHeader (void)
  128. {
  129.  
  130. printf ("\n\n*** Pay Calculator ***\n");
  131.  
  132. // print the table header
  133.  
  134. printf("%-10s %6s %7s %7s %10s\n",
  135. "Clock#", "Wage", "Hours", "OT", "Gross");
  136. printf("------------------------------------------------\n");
  137.  
  138. } // printHeader
  139.  
  140. // ********************************************************************
  141. // Function: printEmp
  142. //
  143. // Purpose: Outputs to screen in a table format the following
  144. // information about an employee: Clock, Wage,
  145. // Hours, Overtime Hours, and Gross Pay.
  146. //
  147. // Parameters:
  148. //
  149. // employeeData - an array of structures containing Employees
  150. // theSize - number of employees to process
  151. //
  152. // Returns: Nothing (void)
  153. //
  154. // *********************************************************************
  155.  
  156. void printEmp ( struct employee employeeData[], int theSize )
  157. {
  158. int i; // loop and array index
  159.  
  160. // print information about each employee
  161. for (i = 0; i < theSize ; ++i)
  162. {
  163. printf("%06ld %9.2f %7.1f %7.1f %10.2f\n",
  164. employeeData[i].clockNumber,
  165. employeeData[i].wageRate,
  166. employeeData[i].hours,
  167. employeeData[i].overtimeHrs,
  168. employeeData[i].grossPay);
  169. } /* for */
  170.  
  171. } // printEmp
  172.  
  173. // TODO: add your functions here
  174. //**************************************************************
  175. // Function: calcOvertime
  176. //
  177. // Purpose: Calculates overtime hours for each employee.
  178. //
  179. // Parameters:
  180. // employeeData - array of employee structures
  181. // theSize - number of employees
  182. //
  183. // Returns: Nothing (void)
  184. //**************************************************************
  185.  
  186. void calcOvertime(struct employee employeeData[], int theSize)
  187. {
  188. int i;
  189.  
  190. for (i = 0; i < theSize; i++)
  191. {
  192. if (employeeData[i].hours > STD_HOURS)
  193. {
  194. employeeData[i].overtimeHrs =
  195. employeeData[i].hours - STD_HOURS;
  196. }
  197. else
  198. {
  199. employeeData[i].overtimeHrs = 0;
  200. }
  201. }
  202. }
  203.  
  204. //**************************************************************
  205. // Function: calcGrossPay
  206. //
  207. // Purpose: Calculates gross pay including overtime.
  208. //
  209. // Parameters:
  210. // employeeData - array of employee structures
  211. // theSize - number of employees
  212. //
  213. // Returns: Nothing (void)
  214. //**************************************************************
  215.  
  216. void calcGrossPay(struct employee employeeData[], int theSize)
  217. {
  218. int i;
  219.  
  220. for (i = 0; i < theSize; i++)
  221. {
  222. if (employeeData[i].hours > STD_HOURS)
  223. {
  224. employeeData[i].grossPay =
  225. (STD_HOURS * employeeData[i].wageRate) +
  226. (employeeData[i].overtimeHrs *
  227. employeeData[i].wageRate * OT_RATE);
  228. }
  229. else
  230. {
  231. employeeData[i].grossPay =
  232. employeeData[i].hours * employeeData[i].wageRate;
  233. }
  234. }
  235.  
  236. } // calcGrossPay
Success #stdin #stdout 0s 5320KB
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