fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: <Neftalia Cruz>
  6. //
  7. // Class: C Programming, <Fall, 2026>
  8. //
  9. // Date: <October 17, 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. // Call by Value 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 int 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 printHeader (void);
  45. void printEmp (struct employee emp);
  46.  
  47. float getHours (long int clockNumber);
  48. float getOvertimeHours(float hours);
  49. float getGrossPay(float hours, float overtimeHrs, float wageRate);
  50.  
  51. void updateEmployee(struct employee *emp);
  52.  
  53. int main ()
  54. {
  55. // Set up a local variable to store the employee information
  56. struct employee employeeData[SIZE] = {
  57. { 98401, 10.60 },
  58. { 526488, 9.75 },
  59. { 765349, 10.50 }, // initialize clock and wage values
  60. { 34645, 12.25 },
  61. { 127615, 8.35 }
  62. };
  63.  
  64. int i; // loop and array index
  65.  
  66. // Call functions as needed to read and calculate information
  67. for (i = 0; i < SIZE; ++i)
  68. {
  69. updateEmployee(&employeeData[i]);
  70.  
  71. } // for
  72.  
  73. // Print the column headers
  74. printHeader();
  75.  
  76. // print out each employee
  77. for (i = 0; i < SIZE; ++i)
  78. {
  79. printEmp (employeeData[i]);
  80. }
  81.  
  82. return(0); // success
  83.  
  84. } // main
  85.  
  86. //**************************************************************
  87. // Function: getHours
  88. //
  89. // Purpose: Obtains input from user, the number of hours worked
  90. // per employee and stores the result in a local variable
  91. // that is passed back to the calling function.
  92. //
  93. // Parameters: clockNumber - The unique employee ID
  94. //
  95. // Returns: hoursWorked - hours worked in a given week
  96. //
  97. //**************************************************************
  98.  
  99. float getHours (long int clockNumber)
  100. {
  101.  
  102. float hoursWorked; // hours worked in a given week
  103.  
  104. // Read in hours for employee
  105. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  106. scanf("%f", &hoursWorked);
  107.  
  108. // return hours back to the calling function
  109. return (hoursWorked);
  110.  
  111. } // getHours
  112.  
  113. //**************************************************************
  114. // Function: printHeader
  115. //
  116. // Purpose: Prints the initial table header information.
  117. //
  118. // Parameters: none
  119. //
  120. // Returns: void
  121. //
  122. //**************************************************************
  123.  
  124. void printHeader (void)
  125. {
  126.  
  127. printf ("\n\n*** Pay Calculator ***\n");
  128.  
  129. // print the table header
  130. printf("\nClock# Wage Hours OT Gross\n");
  131. printf("------------------------------------------------\n");
  132.  
  133. } // printHeader
  134.  
  135.  
  136. //*************************************************************
  137. // Function: printEmp
  138. //
  139. // Purpose: Prints out all the information for an employee
  140. // in a nice and orderly table format.
  141. //
  142. // Parameters:
  143. //
  144. // clockNumber - unique employee ID
  145. // wageRate - hourly wage rate
  146. // hours - Hours worked for the week
  147. // overtimeHrs - overtime hours worked in a week
  148. // grossPay - gross pay for the week
  149. //
  150. // Returns: void
  151. //
  152. //**************************************************************
  153.  
  154. void printEmp (struct employee emp)
  155. {
  156.  
  157. // Print out a single employee
  158. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  159. emp.clockNumber, emp.wageRate, emp.hours,
  160. emp.overtimeHrs, emp.grossPay);
  161.  
  162. } // printEmp
  163.  
  164.  
  165.  
  166. //**************************************************************
  167. // Function: getOvertimeHours
  168. //
  169. // Purpose: Calculates overtime hours worked by an employee.
  170. //
  171. // Parameters: hours - hours worked in a week
  172. //
  173. // Returns: overtime hours
  174. //
  175. //**************************************************************
  176.  
  177. float getOvertimeHours(float hours)
  178. {
  179. if (hours > STD_HOURS)
  180. {
  181. return hours - STD_HOURS;
  182. }
  183.  
  184. return 0;
  185.  
  186. } // getOvertimeHours
  187.  
  188.  
  189. //**************************************************************
  190. // Function: getGrossPay
  191. //
  192. // Purpose: Calculates gross pay using regular and overtime pay.
  193. //
  194. // Parameters:
  195. // hours - total hours worked
  196. // overtimeHrs - overtime hours worked
  197. // wageRate - hourly wage rate
  198. //
  199. // Returns: gross pay
  200. //
  201. //**************************************************************
  202.  
  203. float getGrossPay(float hours, float overtimeHrs, float wageRate)
  204. {
  205. float normalPay;
  206. float overtimePay;
  207.  
  208. normalPay = (hours - overtimeHrs) * wageRate;
  209.  
  210. overtimePay = overtimeHrs * wageRate * OT_RATE;
  211.  
  212. return normalPay + overtimePay;
  213.  
  214. } // getGrossPay
  215.  
  216.  
  217. //**************************************************************
  218. // Function: updateEmployee
  219. //
  220. // Purpose: Updates the employee with their hours, overtime hours and gross pay
  221. //
  222. // Parameters:
  223. // employee - employee structure
  224. // Returns: void
  225. //
  226. //**************************************************************
  227. void updateEmployee(struct employee *emp)
  228. {
  229. // Prompt for the number of hours worked by the employee
  230. emp->hours = getHours(emp->clockNumber);
  231.  
  232. // Calculate overtime hours
  233. emp->overtimeHrs = getOvertimeHours(emp->hours);
  234.  
  235. // Calculate gross pay
  236. emp->grossPay = getGrossPay(emp->hours, emp->overtimeHrs, emp->wageRate);
  237.  
  238. } // updateEmployee
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   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