fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Carlos Dominguez
  6. //
  7. // Class: C Programming,spring 2026
  8. //
  9. // Date: 03/08/2026 ------------- Spring is almost here!
  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. #include <stdio.h>
  20.  
  21. // Define Constants
  22. #define SIZE 5
  23. #define STD_HOURS 40.0
  24. #define OT_RATE 1.5
  25.  
  26. // Structure definition
  27. struct employee
  28. {
  29. long int clockNumber;
  30. float wageRate;
  31. float hours;
  32. float overtimeHrs;
  33. float grossPay;
  34. };
  35.  
  36. // Function Prototypes
  37. float getHours(long int clockNumber);
  38. void printHeader(void);
  39. void printEmp(long int clockNumber, float wageRate, float hours,
  40. float overtimeHrs, float grossPay);
  41.  
  42. // Added prototypes
  43. float calcOvertime(float hours);
  44. float calcGross(float hours, float wageRate, float overtimeHrs);
  45.  
  46. // --- Summary function prototype ---
  47. // Prints totals and averages for Wage, Hours, OT, and Gross
  48. void printSummary(const float wageRate[], const float hours[],
  49. const float overtimeHrs[], const float grossPay[], int n);
  50.  
  51. int main()
  52. {
  53. struct employee employeeData[SIZE] = {
  54. { 98401, 10.60 },
  55. { 526488, 9.75 },
  56. { 765349, 10.50 },
  57. { 34645, 12.25 },
  58. { 127615, 8.35 }
  59. };
  60.  
  61. int i;
  62.  
  63. // Input and calculations
  64. for (i = 0; i < SIZE; ++i)
  65. {
  66. employeeData[i].hours = getHours(employeeData[i].clockNumber);
  67.  
  68. employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
  69.  
  70. employeeData[i].grossPay = calcGross(
  71. employeeData[i].hours,
  72. employeeData[i].wageRate,
  73. employeeData[i].overtimeHrs
  74. );
  75. }
  76.  
  77. // Print table header
  78. printHeader();
  79.  
  80. // Print 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. // --- Call summary function ---
  91. printSummary(
  92. &employeeData[0].wageRate,
  93. &employeeData[0].hours,
  94. &employeeData[0].overtimeHrs,
  95. &employeeData[0].grossPay,
  96. SIZE
  97. );
  98.  
  99. return 0;
  100. }
  101.  
  102. //**************************************************************
  103. float getHours(long int clockNumber)
  104. {
  105. float hoursWorked;
  106.  
  107. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  108. scanf("%f", &hoursWorked);
  109.  
  110. return hoursWorked;
  111. }
  112.  
  113. //**************************************************************
  114. void printHeader(void)
  115. {
  116. printf("\n\n*** Pay Calculator ***\n");
  117.  
  118. printf("\nClock# Wage Hours OT Gross\n");
  119. printf("------------------------------------------------\n");
  120. }
  121.  
  122. //**************************************************************
  123. void printEmp(long int clockNumber, float wageRate, float hours,
  124. float overtimeHrs, float grossPay)
  125. {
  126. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  127. clockNumber, wageRate, hours,
  128. overtimeHrs, grossPay);
  129. }
  130.  
  131. //**************************************************************
  132. float calcOvertime(float hours)
  133. {
  134. if (hours > STD_HOURS)
  135. return hours - STD_HOURS;
  136. else
  137. return 0.0;
  138. }
  139.  
  140. //**************************************************************
  141. float calcGross(float hours, float wageRate, float overtimeHrs)
  142. {
  143. float normalPay;
  144. float overtimePay;
  145.  
  146. if (overtimeHrs > 0)
  147. {
  148. normalPay = STD_HOURS * wageRate;
  149. overtimePay = overtimeHrs * wageRate * OT_RATE;
  150. }
  151. else
  152. {
  153. normalPay = hours * wageRate;
  154. overtimePay = 0.0;
  155. }
  156.  
  157. return normalPay + overtimePay;
  158. }
  159.  
  160. //**************************************************************
  161. // Function: printSummary
  162. //
  163. // Purpose:
  164. // Prints totals and averages for wage rate, hours,
  165. // overtime hours, and gross pay.
  166. //
  167. // Parameters:
  168. // wageRate[] - array of wage rates
  169. // hours[] - array of hours worked
  170. // overtimeHrs[]- array of overtime hours
  171. // grossPay[] - array of gross pay values
  172. // n - number of employees
  173. //
  174. // Returns: void
  175. //**************************************************************
  176. void printSummary(const float wageRate[], const float hours[],
  177. const float overtimeHrs[], const float grossPay[], int n)
  178. {
  179. float totalWage = 0.0;
  180. float totalHours = 0.0;
  181. float totalOT = 0.0;
  182. float totalGross = 0.0;
  183.  
  184. for (int i = 0; i < n; i++)
  185. {
  186. totalWage += wageRate[i];
  187. totalHours += hours[i];
  188. totalOT += overtimeHrs[i];
  189. totalGross += grossPay[i];
  190. }
  191.  
  192. printf("\n\n------------------------------------------------");
  193. printf("\nTOTALS %5.2f %5.1f %4.1f %8.2f",
  194. totalWage, totalHours, totalOT, totalGross);
  195.  
  196. printf("\nAVERAGES %5.2f %5.1f %4.1f %8.2f\n",
  197. totalWage / n, totalHours / n, totalOT / n, totalGross / n);
  198. }
Success #stdin #stdout 0.01s 5272KB
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

------------------------------------------------
TOTALS    671.50 660.9 619.7   651.15
AVERAGES  134.30 132.2 123.9   130.23