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