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

*** 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