fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Alexander Aguilar
  6. //
  7. // Class: C Programming, Summer 2026
  8. //
  9. // Date: 07/01/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. // Functions called by a combination of by value and by
  16. // reference.
  17. //
  18. //********************************************************
  19.  
  20. // Define and Includes
  21.  
  22. #include <stdio.h>
  23.  
  24. // Define Constants
  25. #define SIZE 5
  26. #define STD_HOURS 40.0
  27. #define OT_RATE 1.5
  28.  
  29. // Define a global structure to pass employee data between functions
  30. // Note that the structure type is global, but you don't want a variable
  31. // of that type to be global. Best to declare a variable of that type
  32. // in a function like main or another function and pass as needed.
  33.  
  34. struct employee
  35. {
  36. long int clockNumber;
  37. float wageRate;
  38. float hours;
  39. float overtimeHrs;
  40. float grossPay;
  41. };
  42.  
  43. // define prototypes here for each function except main
  44. float getHours (long int clockNumber);
  45. void printHeader (void);
  46. void printEmp (struct employee employeeData [ ], int theSize);
  47. void calcOT(struct employee employeeData [ ], int theSize);
  48. void calcGrossPay(struct employee employeeData [ ], int theSize);
  49. // TODO: Add your other function prototypes here
  50.  
  51. int main ()
  52. {
  53. // Set up a local variable to store the employee information
  54. struct employee employeeData[SIZE] = {
  55. { 98401, 10.60 },
  56. { 526488, 9.75 },
  57. { 765349, 10.50 }, // initialize clock and wage values
  58. { 34645, 12.25 },
  59. { 127615, 8.35 }
  60. };
  61.  
  62. int i; // loop and array index
  63.  
  64. // Call functions as needed to read and calculate information
  65. for (i = 0; i < SIZE; ++i)
  66. {
  67.  
  68. // Prompt for the number of hours worked by the employee
  69. employeeData[i].hours = getHours (employeeData[i].clockNumber);
  70.  
  71. // TODO: Add other function calls as needed to calculate overtime and gross
  72. calcOT (employeeData, SIZE);
  73. calcGrossPay (employeeData, SIZE);
  74.  
  75.  
  76. } // for
  77.  
  78. // Print the column headers
  79. printHeader();
  80.  
  81. // Function call to output results to the screen in table format.
  82. printEmp (employeeData, SIZE);
  83.  
  84. return(0); // success
  85.  
  86. } // main
  87.  
  88. //**************************************************************
  89. // Function: getHours
  90. //
  91. // Purpose: Obtains input from user, the number of hours worked
  92. // per employee and stores the result in a local variable
  93. // that is passed back to the calling function.
  94. //
  95. // Parameters: clockNumber - The unique employee ID
  96. //
  97. // Returns: hoursWorked - hours worked in a given week
  98. //
  99. //**************************************************************
  100.  
  101. float getHours (long int clockNumber)
  102. {
  103.  
  104. float hoursWorked; // hours worked in a given week
  105.  
  106. // Read in hours for employee
  107. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  108. scanf ("%f", &hoursWorked);
  109.  
  110. // return hours back to the calling function
  111. return (hoursWorked);
  112.  
  113. } // getHours
  114.  
  115. //**************************************************************
  116. // Function: printHeader
  117. //
  118. // Purpose: Prints the initial table header information.
  119. //
  120. // Parameters: none
  121. //
  122. // Returns: void
  123. //
  124. //**************************************************************
  125.  
  126. void printHeader (void)
  127. {
  128.  
  129. printf ("\n\n*** Pay Calculator ***\n");
  130.  
  131. // print the table header
  132. printf("\nClock# Wage Hours OT Gross\n");
  133. printf("------------------------------------------------\n");
  134.  
  135. } // printHeader
  136.  
  137. // ******************************************************************
  138. // Function: printEmp
  139. //
  140. // Purpose: Outputs to screen in a table format the following
  141. // information about an employee: Clock, Wage,
  142. // Hours, Overtime, and Gross Pay.
  143. //
  144. // Parameters:
  145. //
  146. // employeeData - an array of structures containing
  147. // employee information
  148. // theSize - number of employees to process
  149. //
  150. // Returns: Nothing (void)
  151. //
  152. // *******************************************************************
  153.  
  154. void printEmp ( struct employee employeeData [], int theSize )
  155. {
  156. int i; // loop index
  157.  
  158. // print information about each employee
  159. for (i = 0; i < theSize ; ++i)
  160. {
  161. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  162. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  163. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  164. } // for
  165.  
  166. } // printEmp
  167.  
  168. // TODO: Add your functions here
  169.  
  170. // ******************************************************************
  171. // Function: calcOT
  172. //
  173. // Purpose: Calculates the overtime hours worked by subtracting the total hours
  174. // from STD_HOURS
  175. //
  176. //
  177. // Parameters:
  178. //
  179. // employeeData - an array of structures containing
  180. // employee information
  181. // theSize - number of employees to process
  182. //
  183. // Returns: void
  184. //
  185. // *******************************************************************
  186. void calcOT (struct employee employeeData[], int theSize)
  187. {
  188.  
  189. int i; //loop index
  190.  
  191.  
  192. for(i = 0; i < theSize ; ++i)
  193. {
  194.  
  195. if (employeeData[i].hours > STD_HOURS){
  196.  
  197. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  198.  
  199.  
  200. }//if
  201.  
  202. else{
  203.  
  204. employeeData[i].overtimeHrs = 0;
  205.  
  206. }//else
  207.  
  208. }//for
  209.  
  210.  
  211.  
  212. }// calcOT
  213.  
  214.  
  215. // ******************************************************************
  216. // Function: calcGrossPay
  217. //
  218. // Purpose: Calculates the employees gross pay by multiplying wage rate and
  219. // and hours worked.
  220. //
  221. //
  222. // Parameters:
  223. //
  224. // employeeData - an array of structures containing
  225. // employee information
  226. // theSize - number of employees to process
  227. //
  228. // Returns: void
  229. // *******************************************************************
  230.  
  231.  
  232. void calcGrossPay( struct employee employeeData[], int theSize)
  233. {
  234.  
  235. int i; //loop index
  236.  
  237. for(i = 0; i < theSize; ++i)
  238. {
  239.  
  240. employeeData[i].grossPay = employeeData[i].hours * employeeData[i].wageRate
  241. + employeeData[i].overtimeHrs * OT_RATE;
  242.  
  243. }//For loop
  244.  
  245.  
  246. }//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   557.10
 526488  9.75 42.5  2.5   418.12
 765349 10.50 37.0  0.0   388.50
 034645 12.25 45.0  5.0   558.75
 127615  8.35  0.0  0.0     0.00