fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: David Morse
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 3/7/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 reference 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. struct employee
  27. {
  28. long clockNumber;
  29. float wageRate;
  30. float hours;
  31. float overtimeHrs;
  32. float grossPay;
  33. };
  34.  
  35. // Function prototypes
  36. void getHours (struct employee employeeData[], int theSize );
  37. void calcOvertime (struct employee employeeData[], int theSize);
  38. void calcGrossPay (struct employee employeeData[], int theSize);
  39. void printHeader (void);
  40. void printEmp (struct employee emp[], int theSize);
  41.  
  42. int main ()
  43. {
  44. struct employee employeeData [SIZE] = {
  45. { 98401, 10.60 },
  46. { 526488, 9.75 },
  47. { 765349, 10.50 },
  48. { 34645, 12.25 },
  49. { 127615, 8.35 }
  50. };
  51.  
  52. // Get hours worked
  53. getHours(employeeData, SIZE);
  54.  
  55. // Calculate overtime hours
  56. calcOvertime(employeeData, SIZE);
  57.  
  58. // Calculate gross pay
  59. calcGrossPay(employeeData, SIZE);
  60.  
  61. // Print table header
  62. printHeader();
  63.  
  64. // Print employee data
  65. printEmp(employeeData, SIZE);
  66.  
  67. return 0;
  68.  
  69. } // main
  70.  
  71. //**************************************************************
  72. // Function: getHours
  73. //**************************************************************
  74.  
  75. void getHours (struct employee employeeData[], int theSize )
  76. {
  77. int i;
  78.  
  79. for (i = 0; i < theSize; ++i)
  80. {
  81. printf("\nEnter hours worked by emp # %06li: ",
  82. employeeData[i].clockNumber);
  83. scanf("%f", &employeeData[i].hours);
  84. }
  85.  
  86. }
  87.  
  88. //**************************************************************
  89. // Function: calcOvertime
  90. //**************************************************************
  91.  
  92. void calcOvertime (struct employee employeeData[], int theSize)
  93. {
  94. int i;
  95.  
  96. for (i = 0; i < theSize; ++i)
  97. {
  98. if (employeeData[i].hours > STD_HOURS)
  99. employeeData[i].overtimeHrs =
  100. employeeData[i].hours - STD_HOURS;
  101. else
  102. employeeData[i].overtimeHrs = 0;
  103. }
  104. }
  105.  
  106.  
  107. //**************************************************************
  108. // Function: calcGrossPay
  109. //**************************************************************
  110.  
  111. void calcGrossPay (struct employee employeeData[], int theSize)
  112. {
  113. int i;
  114.  
  115. for (i = 0; i < theSize; ++i)
  116. {
  117. if (employeeData[i].hours > STD_HOURS)
  118. {
  119. employeeData[i].grossPay =
  120. (STD_HOURS * employeeData[i].wageRate) +
  121. (employeeData[i].overtimeHrs *
  122. employeeData[i].wageRate * OT_RATE);
  123. }
  124. else
  125. {
  126. employeeData[i].grossPay =
  127. employeeData[i].hours *
  128. employeeData[i].wageRate;
  129. }
  130. }
  131. }
  132.  
  133.  
  134. //**************************************************************
  135. // Function: printHeader
  136. //**************************************************************
  137.  
  138. void printHeader (void)
  139. {
  140. printf ("\n\n*** Pay Calculator ***\n");
  141.  
  142. printf("\nClock# Wage Hours OT Gross\n");
  143. printf("------------------------------------------------\n");
  144.  
  145. }
  146.  
  147.  
  148. //**************************************************************
  149. // Function: printEmp
  150. //**************************************************************
  151.  
  152. void printEmp ( struct employee employeeData[], int theSize )
  153. {
  154. int i;
  155.  
  156. for (i = 0; i < theSize ; ++i)
  157. {
  158. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  159. employeeData[i].clockNumber,
  160. employeeData[i].wageRate,
  161. employeeData[i].hours,
  162. employeeData[i].overtimeHrs,
  163. employeeData[i].grossPay);
  164. }
  165.  
  166. }
Success #stdin #stdout 0.01s 5320KB
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