fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Anthony Principe
  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 Value design
  16. //
  17. //********************************************************
  18.  
  19. // Define and Includes
  20. #include <stdio.h>
  21.  
  22. // Define Constants
  23. #define SIZE 5
  24. #define STD_HOURS 40.0
  25. #define OT_RATE 1.5
  26.  
  27. // Define a global structure to pass employee data between functions
  28. struct employee
  29. {
  30. long int clockNumber;
  31. float wageRate;
  32. float hours;
  33. float overtimeHrs;
  34. float grossPay;
  35. };
  36.  
  37. // define prototypes here for each function except main
  38. float getHours (long int clockNumber);
  39. void printHeader (void);
  40. void printEmp (long int clockNumber, float wageRate, float hours,
  41. float overtimeHrs, float grossPay);
  42. float calcOvertime (float hours);
  43. float calcGross (float wageRate, float hours, float overtimeHrs);
  44.  
  45. int main ()
  46. {
  47. // Set up a local variable to store the employee information
  48. struct employee employeeData[SIZE] = {
  49. { 98401, 10.60 },
  50. { 526488, 9.75 },
  51. { 765349, 10.50 }, // initialize clock and wage values
  52. { 34645, 12.25 },
  53. { 127615, 8.35 }
  54. };
  55.  
  56. int i; // loop and array index
  57.  
  58. // Call functions as needed to read and calculate information
  59. for (i = 0; i < SIZE; ++i)
  60. {
  61. // Prompt for the number of hours worked by the employee
  62. employeeData[i].hours = getHours (employeeData[i].clockNumber);
  63.  
  64. // Calculate overtime hours
  65. employeeData[i].overtimeHrs = calcOvertime (employeeData[i].hours);
  66.  
  67. // Calculate gross pay
  68. employeeData[i].grossPay = calcGross (employeeData[i].wageRate,
  69. employeeData[i].hours,
  70. employeeData[i].overtimeHrs);
  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].clockNumber,
  80. employeeData[i].wageRate,
  81. employeeData[i].hours,
  82. employeeData[i].overtimeHrs,
  83. employeeData[i].grossPay);
  84. }
  85.  
  86. printf("\n\n");
  87.  
  88. return(0); // success
  89. } // main
  90.  
  91.  
  92. //**************************************************************
  93. // Function: getHours
  94. //
  95. // Purpose: Obtains input from user, the number of hours worked
  96. // per employee and stores the result in a local variable
  97. // that is passed back to the calling function.
  98. //
  99. // Parameters: clockNumber - The unique employee ID
  100. //
  101. // Returns: hoursWorked - hours worked in a given week
  102. //
  103. //**************************************************************
  104.  
  105. float getHours (long int clockNumber)
  106. {
  107. float hoursWorked; // hours worked in a given week
  108.  
  109. // Read in hours for employee
  110. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  111. scanf ("%f", &hoursWorked);
  112.  
  113. // return hours back to the calling function
  114. return (hoursWorked);
  115. } // getHours
  116.  
  117.  
  118. //**************************************************************
  119. // Function: calcOvertime
  120. //
  121. // Purpose: Calculates overtime hours based on hours worked
  122. //
  123. // Parameters: hours - hours worked in the week
  124. //
  125. // Returns: overtimeHrs - hours worked over 40
  126. //
  127. //**************************************************************
  128.  
  129. float calcOvertime (float hours)
  130. {
  131. float overtimeHrs;
  132.  
  133. if (hours > STD_HOURS)
  134. overtimeHrs = hours - STD_HOURS;
  135. else
  136. overtimeHrs = 0.0;
  137.  
  138. return overtimeHrs;
  139. } // calcOvertime
  140.  
  141.  
  142. //**************************************************************
  143. // Function: calcGross
  144. //
  145. // Purpose: Calculates the gross pay for an employee
  146. //
  147. // Parameters: wageRate - hourly pay rate
  148. // hours - total hours worked
  149. // overtimeHrs - hours worked over 40
  150. //
  151. // Returns: grossPay - total pay for the week
  152. //
  153. //**************************************************************
  154.  
  155. float calcGross (float wageRate, float hours, float overtimeHrs)
  156. {
  157. float grossPay;
  158.  
  159. if (hours <= STD_HOURS)
  160. grossPay = hours * wageRate;
  161. else
  162. grossPay = (STD_HOURS * wageRate) + (overtimeHrs * wageRate * OT_RATE);
  163.  
  164. return grossPay;
  165. } // calcGross
  166.  
  167.  
  168. //**************************************************************
  169. // Function: printHeader
  170. //
  171. // Purpose: Prints the initial table header information.
  172. //
  173. // Parameters: none
  174. //
  175. // Returns: void
  176. //
  177. //**************************************************************
  178.  
  179. void printHeader (void)
  180. {
  181. printf ("\n\n*** Pay Calculator ***\n");
  182. printf("\nClock# Wage Hours OT Gross\n");
  183. printf("-------------------------------------------\n");
  184. } // printHeader
  185.  
  186.  
  187. //*************************************************************
  188. // Function: printEmp
  189. //
  190. // Purpose: Prints out all the information for an employee
  191. // in a nice and orderly table format.
  192. //
  193. // Parameters:
  194. //
  195. // clockNumber - unique employee ID
  196. // wageRate - hourly wage rate
  197. // hours - Hours worked for the week
  198. // overtimeHrs - overtime hours worked in a week
  199. // grossPay - gross pay for the week
  200. //
  201. // Returns: void
  202. //
  203. //**************************************************************
  204.  
  205. void printEmp (long int clockNumber, float wageRate, float hours,
  206. float overtimeHrs, float grossPay)
  207. {
  208. // Print out a single employee
  209. printf("%06li %5.2f %5.1f %5.1f %8.2f\n",
  210. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  211. } // printEmp
  212.  
Success #stdin #stdout 0s 5312KB
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