fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Raissa Almeida Beckenkamp
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 19, 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. // 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.  
  48. // TODO: add your function prototypes here
  49. void calcOT (struct employee employeeData [], int theSize);
  50. void calcGross (struct employee employeeData [], int theSize);
  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.  
  68. //Function call to calculate the overtime hours
  69. calcOT (employeeData, SIZE);
  70.  
  71. //Function call to calculate the gross pay
  72. calcGross (employeeData, SIZE);
  73.  
  74. // TODO: Call function to print the table column headers
  75.  
  76.  
  77. // Print a table header
  78. printHeader();
  79.  
  80. // Function call to output results to the screen in table format
  81. printEmp (employeeData, SIZE);
  82.  
  83. return(0); // success
  84.  
  85. } // main
  86.  
  87. //**************************************************************
  88. // Function: getHours
  89. //
  90. // Purpose: Obtains input from user, the number of hours worked
  91. // per employee and stores the result in an array of structures
  92. // that is passed back to the calling function by reference.
  93. //
  94. // Parameters:
  95. //
  96. // employeeData - an array of structures containing Employees
  97. // theSize - number of employees to process
  98. //
  99. // Returns: Nothing (void)
  100. //
  101. //**************************************************************
  102.  
  103. void getHours (struct employee employeeData[], int theSize )
  104. {
  105.  
  106. int i; // loop and array index
  107.  
  108. // read hours in for each employee
  109. for (i = 0; i < theSize ; ++i)
  110. {
  111. printf("\nEnter hours worked by emp # %06li: ",
  112. employeeData[i].clockNumber);
  113. scanf ("%f", &employeeData[i].hours);
  114. } // for
  115.  
  116. } // getHours
  117.  
  118. //**************************************************************
  119. // Function: printHeader
  120. //
  121. // Purpose: Prints the initial table header information.
  122. //
  123. // Parameters: none
  124. //
  125. // Returns: void
  126. //
  127. //**************************************************************
  128.  
  129. void printHeader (void)
  130. {
  131.  
  132. printf ("\n\n*** Pay Calculator ***\n");
  133.  
  134. // print the table header
  135. printf("\nClock# Wage Hours OT Gross\n");
  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("\n %06li %5.2f %4.1f %4.1f %8.2f",
  164. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  165. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  166. } /* for */
  167.  
  168. } // printEmp
  169.  
  170. // TODO: add your functions here
  171.  
  172. //**************************************************************
  173. // Function: calcOT (Call by Reference)
  174. // Purpose : Computes overtime hours (> 40.0) for each employee.
  175. // Parameters : employeeData (array of structs), theSize (count)
  176. // Returns : Nothing (void)
  177. //**************************************************************
  178. // function definition for calcOT
  179. void calcOT (struct employee employeeData[],
  180. int theSize)
  181. {
  182. //declare local variables
  183. int i;
  184. float overtimeHrs;
  185.  
  186. //add in code
  187. for (i = 0; i < theSize; ++i)
  188. {
  189. overtimeHrs = 0.0;
  190.  
  191. if (employeeData[i].hours > STD_HOURS)
  192. {
  193. overtimeHrs = employeeData[i].hours - STD_HOURS;
  194. }
  195. employeeData[i].overtimeHrs = overtimeHrs;
  196. }
  197. } //calcOT
  198.  
  199. //**************************************************************
  200. // Function: calcGross (Call by Reference)
  201. /// Purpose : Computes gross pay for each employee using
  202. // wage rate, hours worked, and overtime hours.
  203. // Parameters : employeeData (array of structs), theSize (count)
  204. // Returns : Nothing (void)
  205. //**************************************************************
  206. // function definition for calcGross
  207. void calcGross (struct employee employeeData[],
  208. int theSize)
  209. {
  210. //declare local variables
  211. int i;
  212. float grossPay;
  213. float normalPay;
  214. float overtimePay;
  215.  
  216. // add in code
  217. for (i = 0; i < theSize; ++i)
  218. {
  219. if (employeeData[i].hours < employeeData[i].overtimeHrs)
  220. {
  221. normalPay = 0.0;
  222. }
  223. else
  224. {
  225. normalPay = (employeeData[i].hours - employeeData[i].overtimeHrs) * employeeData[i].wageRate;
  226. }
  227.  
  228. overtimePay = employeeData[i].overtimeHrs * employeeData[i].wageRate * OT_RATE;
  229. grossPay = normalPay + overtimePay;
  230.  
  231. employeeData[i].grossPay = grossPay;
  232. }
  233. } //CalcGross
Success #stdin #stdout 0.01s 5316KB
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