fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: John Semenuk
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 8-Mar-2026
  10. //
  11. // Description:
  12. // Program which determines overtime hours and gross pay
  13. // for a set of employees. Employee data is stored using
  14. // an array of structures. The program prompts the user
  15. // for hours worked and calculates overtime and gross pay.
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20.  
  21. // Program Constants
  22. #define SIZE 5
  23. #define STD_HOURS 40.0
  24. #define OT_RATE 1.5
  25.  
  26. // Structure Definition
  27. struct employee
  28. {
  29. long int clockNumber;
  30. float wageRate;
  31. float hours;
  32. float overtimeHrs;
  33. float grossPay;
  34. };
  35.  
  36. // Function Prototypes
  37. float getHours(long int clockNumber);
  38. float calcOvertime(float hours);
  39. float calcGross(float wageRate, float hours, float overtimeHrs);
  40. void printHeader(void);
  41. void printEmp(long int clockNumber, float wageRate, float hours,
  42. float overtimeHrs, float grossPay);
  43.  
  44.  
  45. int main()
  46. {
  47.  
  48. struct employee employeeData[SIZE] =
  49. {
  50. {98401, 10.60},
  51. {526488, 9.75},
  52. {765349, 10.50},
  53. {34645, 12.25},
  54. {127615, 8.35}
  55. };
  56.  
  57. int i;
  58.  
  59. // Input and calculations
  60. for (i = 0; i < SIZE; i++)
  61. {
  62.  
  63. employeeData[i].hours =
  64. getHours(employeeData[i].clockNumber);
  65.  
  66. employeeData[i].overtimeHrs =
  67. calcOvertime(employeeData[i].hours);
  68.  
  69. employeeData[i].grossPay =
  70. calcGross(employeeData[i].wageRate,
  71. employeeData[i].hours,
  72. employeeData[i].overtimeHrs);
  73. }
  74.  
  75. printHeader();
  76.  
  77. for (i = 0; i < SIZE; i++)
  78. {
  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;
  88.  
  89. }
  90.  
  91.  
  92. //**************************************************************
  93. // Function: getHours
  94. //
  95. // Purpose:
  96. // Prompts the user to enter the number of hours worked
  97. // by an employee and returns that value.
  98. //
  99. // Parameters:
  100. // clockNumber - unique employee identification number
  101. //
  102. // Returns:
  103. // float - number of hours worked by the employee
  104. //**************************************************************
  105.  
  106. float getHours(long int clockNumber)
  107. {
  108.  
  109. float hoursWorked;
  110.  
  111. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  112. scanf("%f", &hoursWorked);
  113.  
  114. return hoursWorked;
  115.  
  116. }
  117.  
  118.  
  119. //**************************************************************
  120. // Function: calcOvertime
  121. //
  122. // Purpose:
  123. // Determines how many overtime hours an employee worked.
  124. // Overtime is any time greater than the standard work week.
  125. //
  126. // Parameters:
  127. // hours - total hours worked by employee
  128. //
  129. // Returns:
  130. // float - overtime hours worked
  131. //**************************************************************
  132.  
  133. float calcOvertime(float hours)
  134. {
  135.  
  136. float overtime;
  137.  
  138. if (hours > STD_HOURS)
  139. overtime = hours - STD_HOURS;
  140. else
  141. overtime = 0.0;
  142.  
  143. return overtime;
  144.  
  145. }
  146.  
  147.  
  148. //**************************************************************
  149. // Function: calcGross
  150. //
  151. // Purpose:
  152. // Calculates the gross pay for an employee using the
  153. // employee wage rate, total hours worked, and overtime.
  154. //
  155. // Parameters:
  156. // wageRate - employee hourly wage
  157. // hours - total hours worked
  158. // overtimeHrs - overtime hours worked
  159. //
  160. // Returns:
  161. // float - total gross pay for the week
  162. //**************************************************************
  163.  
  164. float calcGross(float wageRate, float hours, float overtimeHrs)
  165. {
  166.  
  167. float normalPay;
  168. float overtimePay;
  169. float grossPay;
  170.  
  171. if (hours > STD_HOURS)
  172. normalPay = STD_HOURS * wageRate;
  173. else
  174. normalPay = hours * wageRate;
  175.  
  176. overtimePay = overtimeHrs * wageRate * OT_RATE;
  177.  
  178. grossPay = normalPay + overtimePay;
  179.  
  180. return grossPay;
  181.  
  182. }
  183.  
  184.  
  185. //**************************************************************
  186. // Function: printHeader
  187. //
  188. // Purpose:
  189. // Prints the column headings for the employee pay table.
  190. //
  191. // Parameters:
  192. // none
  193. //
  194. // Returns:
  195. // void
  196. //**************************************************************
  197.  
  198. void printHeader(void)
  199. {
  200.  
  201. printf("\n\n----------------------------------------------------------");
  202. printf("\n Clock# Wage Hours OT Gross");
  203. printf("\n----------------------------------------------------------");
  204.  
  205. }
  206.  
  207.  
  208. //**************************************************************
  209. // Function: printEmp
  210. //
  211. // Purpose:
  212. // Displays a single employee's payroll information.
  213. //
  214. // Parameters:
  215. // clockNumber - employee ID
  216. // wageRate - hourly wage
  217. // hours - total hours worked
  218. // overtimeHrs - overtime hours worked
  219. // grossPay - total weekly gross pay
  220. //
  221. // Returns:
  222. // void
  223. //**************************************************************
  224.  
  225. void printEmp(long int clockNumber, float wageRate, float hours,
  226. float overtimeHrs, float grossPay)
  227. {
  228.  
  229. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  230. clockNumber, wageRate, hours,
  231. overtimeHrs, grossPay);
  232.  
  233. }
Success #stdin #stdout 0.01s 5288KB
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: 

----------------------------------------------------------
   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