fork(1) 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. //**************************************************************
  46. // Function: main
  47. //
  48. // Purpose:
  49. // Controls the overall flow of the program. It gathers
  50. // employee hours, calculates overtime and gross pay,
  51. // and prints the results in table format.
  52. //
  53. // Parameters:
  54. // none
  55. //
  56. // Returns:
  57. // int - program success status
  58. //**************************************************************
  59.  
  60. int main()
  61. {
  62.  
  63. struct employee employeeData[SIZE] =
  64. {
  65. {98401, 10.60},
  66. {526488, 9.75},
  67. {765349, 10.50},
  68. {34645, 12.25},
  69. {127615, 8.35}
  70. };
  71.  
  72. int i;
  73.  
  74. // Input and calculations
  75. for (i = 0; i < SIZE; i++)
  76. {
  77.  
  78. employeeData[i].hours =
  79. getHours(employeeData[i].clockNumber);
  80.  
  81. employeeData[i].overtimeHrs =
  82. calcOvertime(employeeData[i].hours);
  83.  
  84. employeeData[i].grossPay =
  85. calcGross(employeeData[i].wageRate,
  86. employeeData[i].hours,
  87. employeeData[i].overtimeHrs);
  88. }
  89.  
  90. printHeader();
  91.  
  92. for (i = 0; i < SIZE; i++)
  93. {
  94.  
  95. printEmp(employeeData[i].clockNumber,
  96. employeeData[i].wageRate,
  97. employeeData[i].hours,
  98. employeeData[i].overtimeHrs,
  99. employeeData[i].grossPay);
  100. }
  101.  
  102. return 0;
  103.  
  104. }
  105.  
  106.  
  107. //**************************************************************
  108. // Function: getHours
  109. //
  110. // Purpose:
  111. // Prompts the user to enter the number of hours worked
  112. // by an employee and returns that value.
  113. //
  114. // Parameters:
  115. // clockNumber - unique employee identification number
  116. //
  117. // Returns:
  118. // float - number of hours worked by the employee
  119. //**************************************************************
  120.  
  121. float getHours(long int clockNumber)
  122. {
  123.  
  124. float hoursWorked;
  125.  
  126. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  127. scanf("%f", &hoursWorked);
  128.  
  129. return hoursWorked;
  130.  
  131. }
  132.  
  133.  
  134. //**************************************************************
  135. // Function: calcOvertime
  136. //
  137. // Purpose:
  138. // Determines how many overtime hours an employee worked.
  139. // Overtime is any time greater than the standard work week.
  140. //
  141. // Parameters:
  142. // hours - total hours worked by employee
  143. //
  144. // Returns:
  145. // float - overtime hours worked
  146. //**************************************************************
  147.  
  148. float calcOvertime(float hours)
  149. {
  150.  
  151. float overtime;
  152.  
  153. if (hours > STD_HOURS)
  154. overtime = hours - STD_HOURS;
  155. else
  156. overtime = 0.0;
  157.  
  158. return overtime;
  159.  
  160. }
  161.  
  162.  
  163. //**************************************************************
  164. // Function: calcGross
  165. //
  166. // Purpose:
  167. // Calculates the gross pay for an employee using the
  168. // employee wage rate, total hours worked, and overtime.
  169. //
  170. // Parameters:
  171. // wageRate - employee hourly wage
  172. // hours - total hours worked
  173. // overtimeHrs - overtime hours worked
  174. //
  175. // Returns:
  176. // float - total gross pay for the week
  177. //**************************************************************
  178.  
  179. float calcGross(float wageRate, float hours, float overtimeHrs)
  180. {
  181.  
  182. float normalPay;
  183. float overtimePay;
  184. float grossPay;
  185.  
  186. if (hours > STD_HOURS)
  187. normalPay = STD_HOURS * wageRate;
  188. else
  189. normalPay = hours * wageRate;
  190.  
  191. overtimePay = overtimeHrs * wageRate * OT_RATE;
  192.  
  193. grossPay = normalPay + overtimePay;
  194.  
  195. return grossPay;
  196.  
  197. }
  198.  
  199.  
  200. //**************************************************************
  201. // Function: printHeader
  202. //
  203. // Purpose:
  204. // Prints the column headings for the employee pay table.
  205. //
  206. // Parameters:
  207. // none
  208. //
  209. // Returns:
  210. // void
  211. //**************************************************************
  212.  
  213. void printHeader(void)
  214. {
  215.  
  216. printf("\n\n----------------------------------------------------------");
  217. printf("\n Clock# Wage Hours OT Gross");
  218. printf("\n----------------------------------------------------------");
  219.  
  220. }
  221.  
  222.  
  223. //**************************************************************
  224. // Function: printEmp
  225. //
  226. // Purpose:
  227. // Displays a single employee's payroll information.
  228. //
  229. // Parameters:
  230. // clockNumber - employee ID
  231. // wageRate - hourly wage
  232. // hours - total hours worked
  233. // overtimeHrs - overtime hours worked
  234. // grossPay - total weekly gross pay
  235. //
  236. // Returns:
  237. // void
  238. //**************************************************************
  239.  
  240. void printEmp(long int clockNumber, float wageRate, float hours,
  241. float overtimeHrs, float grossPay)
  242. {
  243.  
  244. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  245. clockNumber, wageRate, hours,
  246. overtimeHrs, grossPay);
  247.  
  248. }
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