fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Timothy Stockton
  6. //
  7. // Class: C Programming, Summer 2025
  8. //
  9. // Date: July 3rd, 2025
  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. // Functions are called by reference
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20.  
  21. // constants
  22. #define SIZE 5 // number of employees to process
  23. #define OVERTIME_RATE 1.5f // time and half overtime setting
  24. #define STD_WORK_WEEK 40.0f // normal work week hours before overtime
  25.  
  26. // global structure to pass employee data between functions
  27. struct employee
  28. {
  29. long int clockNumber;
  30. float wageRate;
  31. float hours;
  32. float overtimeHrs;
  33. float normalPay;
  34. float overtimePay;
  35. float grossPay;
  36. };
  37.  
  38. // function prototypes
  39. void getHours (struct employee employeeData[], int theSize);
  40. void calcOvertime (struct employee employeeData[], int theSize,
  41. float overtimeRate, float standardWeek);
  42. void calcGrossPay (struct employee employeeData[], int theSize);
  43. void printHeader (void);
  44. void printEmps (struct employee employeeData[], int theSize);
  45.  
  46. int main()
  47. {
  48.  
  49. // Variable Declarations
  50. // array of employee structures, initialized with clockNumber and wageRate
  51. struct employee employeeData[SIZE] = {
  52. {98401, 10.60},
  53. {526488, 9.75},
  54. {765349, 10.50},
  55. {34645, 12.25},
  56. {127615, 8.35}
  57. };
  58.  
  59. // Read in the hours worked for each employee
  60. getHours (employeeData, SIZE);
  61.  
  62. // Calculate overtime hours and pay (as well as normal pay)
  63. calcOvertime (employeeData, SIZE, OVERTIME_RATE, STD_WORK_WEEK);
  64.  
  65. // Calculate gross pay
  66. calcGrossPay (employeeData, SIZE);
  67.  
  68. // Print the initial table header
  69. printHeader ();
  70.  
  71. // Function call to output results to the screen
  72. printEmps (employeeData, SIZE);
  73.  
  74. return (0);
  75.  
  76. } // main
  77.  
  78. //***************************************************************
  79. // Function: getHours
  80. //
  81. // Purpose: Obtains input from user, the number of hours worked
  82. // per employee, and stores the results in the referenced array
  83. // of employee structures.
  84. //
  85. // Parameters:
  86. //
  87. // employeeData - Array of employee structures
  88. // theSize - Number of employees to process
  89. //
  90. // Returns: Nothing (call by reference)
  91. //
  92. //**************************************************************
  93.  
  94. void getHours (struct employee employeeData[], int theSize)
  95. {
  96.  
  97. int i; // loop and array index
  98.  
  99. // Read in hours for each employee
  100. for (i= 0; i < theSize; ++i)
  101. {
  102. printf("\nEnter hours worked by emp # %06li: ", employeeData[i].clockNumber);
  103. scanf ("%f", &employeeData[i].hours);
  104. }
  105.  
  106. } // getHours
  107.  
  108. //***************************************************************
  109. // Function: calcOvertime
  110. //
  111. // Purpose: Calculates the normal pay and overtime pay of all employees
  112. // based on the hours worked, wage rate, overtime rate, and standard
  113. // week hours. Stores the results in the referenced array
  114. // of employee structures.
  115. //
  116. // Parameters:
  117. //
  118. // employeeData - Array of employee structures
  119. // theSize - Number of employees to process
  120. // overtimeRate - The multiplier to wages for overtime hours
  121. // standardWeek - Number of hours in a standard work week, no overtime
  122. //
  123. // Returns: Nothing (call by reference)
  124. //
  125. //**************************************************************
  126.  
  127. void calcOvertime (struct employee employeeData[], int theSize,
  128. float overtimeRate, float standardWeek)
  129. {
  130.  
  131. int i; // loop and array index
  132.  
  133. // Process each employee one at a time
  134. for (i = 0; i < theSize; i++)
  135. {
  136.  
  137. // Calculate overtime and gross pay for employee
  138. if (employeeData[i].hours > standardWeek)
  139. {
  140. employeeData[i].overtimeHrs = employeeData[i].hours - standardWeek;
  141. employeeData[i].overtimePay = employeeData[i].overtimeHrs *
  142. (employeeData[i].wageRate * overtimeRate);
  143. employeeData[i].normalPay = standardWeek * employeeData[i].wageRate;
  144. }
  145. else // no OT
  146. {
  147. employeeData[i].overtimeHrs = 0;
  148. employeeData[i].overtimePay = 0;
  149. employeeData[i].normalPay = employeeData[i].hours * employeeData[i].wageRate;
  150. }
  151.  
  152. } // end for
  153.  
  154. } // calcOvertime
  155.  
  156. //***************************************************************
  157. // Function: calcGrossPay
  158. //
  159. // Purpose: Calculates the gross pay fr each employee, the total pay for the week
  160. // including normal and overtime pay. Stores the results in the referenced array
  161. // of employee structures.
  162. //
  163. // Parameters:
  164. //
  165. // employeeData - Array of employee structures
  166. // theSize - Number of employees to process
  167. //
  168. // Returns: Nothing (call by reference)
  169. //
  170. //**************************************************************
  171.  
  172. void calcGrossPay (struct employee employeeData[], int theSize)
  173. {
  174.  
  175. int i; // loop and array index
  176.  
  177. // Process each employee one at a time
  178. for (i = 0; i < theSize; i++)
  179. {
  180. // Calculate Gross Pay
  181. employeeData[i].grossPay = employeeData[i].normalPay + employeeData[i].overtimePay;
  182. } // end for
  183.  
  184. } // calcGrossPay
  185.  
  186. //**************************************************************
  187. // Function: printHeader
  188. //
  189. // Purpose: Prints the initial table header information.
  190. //
  191. // Parameters: none
  192. //
  193. // Returns: void
  194. //
  195. //**************************************************************
  196.  
  197. void printHeader (void)
  198. {
  199.  
  200. printf ("\n\n*** Pay Calculator ***\n");
  201.  
  202. // print the table header
  203. printf("\nClock# Wage Hours OT Gross\n");
  204. printf("------------------------------------------------\n");
  205.  
  206. } // printHeader
  207.  
  208. //**************************************************************
  209. // Function: printEmps
  210. //
  211. // Purpose: Prints out all the employee information in a
  212. // nice and orderly table format.
  213. //
  214. // Parameters:
  215. //
  216. // employeeData - Array of employee structures
  217. // theSize - Number of employees to process
  218. //
  219. // Returns: Nothing (call by reference)
  220. //
  221. //**************************************************************
  222.  
  223. void printEmps (struct employee employeeData[], int theSize)
  224. {
  225. int i; // loop and array index
  226.  
  227. // access and print each employee
  228. for (i = 0; i < theSize; ++i)
  229. {
  230. printf("%06li %5.2f %5.1f %5.1f %8.2f\n",
  231. employeeData[i].clockNumber, employeeData[i].wageRate,
  232. employeeData[i].hours, employeeData[i].overtimeHrs,
  233. employeeData[i].grossPay);
  234. }
  235. } // printEmps
  236.  
Success #stdin #stdout 0.01s 5264KB
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