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