fork download
  1.  
  2. //********************************************************
  3. //
  4. // Assignment 6 - Structures
  5. //
  6. // Name: Jalen Tam
  7. //
  8. // Class: C Programming, Fall 2025
  9. //
  10. // Date: October 17, 2025
  11. //
  12. // Description: Program which determines overtime and
  13. // gross pay for a set of employees with outputs sent
  14. // to standard output (the screen).
  15. //
  16. // Call by Value design
  17. //
  18. //********************************************************
  19.  
  20. #include <stdio.h>
  21.  
  22. //constants
  23. #define SIZE 5
  24. #define OVT_RATE 1.5
  25. #define STD_HOURS 40
  26.  
  27. //struct format
  28. struct employee {
  29. long int number;
  30. float wage;
  31. float totalHours;
  32. float regHours;
  33. float ovtHours;
  34. float regPay;
  35. float ovtPay;
  36. float grossPay;
  37. };
  38.  
  39. //function prototypes
  40. float getHours (int clockNumber);
  41. float getRegularHours (float totalHours);
  42. float calculateOvtHours (float hours);
  43. float calculateRegPay (float regHours, float wage);
  44. float calculateOvtPay (float ovtHours, float wage);
  45. float calculateGrossPay (float regPay, float overtimePay);
  46.  
  47. // FUNCTION getHours
  48. // Prompt for hours worked
  49. // Parameters: clockNumber - Employee clock number
  50. // Returns: Hours worked
  51. float getHours (int clockNumber){
  52.  
  53. // Initialize hours variable
  54. float hours;
  55.  
  56. // Prompt for hours work to be input
  57. //printf("Enter hours worked for %06i", clockNumber);
  58. scanf("%f", &hours);
  59.  
  60. // Return hours
  61. return hours;
  62.  
  63. }
  64.  
  65. // FUNCTION getRegularHours
  66. // Calculate regular hours worked
  67. // Parameters: totalHours - total hours worked
  68. // Returns: Regular hours worked
  69. float getRegularHours (float totalHours) {
  70. float regHours;
  71.  
  72. if (totalHours > STD_HOURS) {
  73. regHours = 40;
  74. } else {
  75. regHours = totalHours;
  76. }
  77.  
  78. return regHours;
  79.  
  80. }
  81.  
  82. // FUNCTION calculateOvtHours
  83. // Calculates overtime worked
  84. // Parameters: hours - total hours employee worked
  85. // Returns: Overtime horus worked
  86. float calculateOvtHours (float hours){
  87. float overtime;
  88.  
  89. //calculate overtime hours from total hours
  90. if (hours > STD_HOURS) {
  91. overtime = hours - STD_HOURS;
  92. } else {
  93. overtime = 0;
  94. }
  95.  
  96. //return amount of overtime hours
  97. return overtime;
  98. }
  99.  
  100. // FUNCTION calculateRegPay
  101. // Calculates the regular pay of employee
  102. // Parameters: regHours - regular hours
  103. // wage - rate of pay
  104. // Returns: regular pay
  105. float calculateRegPay (float regHours, float wage) {
  106.  
  107. float regPay;
  108. regPay = regHours * wage;
  109. return regPay;
  110.  
  111. }
  112.  
  113. // FUNCTION calculateOvtgPay
  114. // Calculates the overtime pay of employee
  115. // Parameters: ovtHours - overtime hours
  116. // wage - rate of pay
  117. // Returns: overtime pay
  118. float calculateOvtPay (float ovtHours, float wage) {
  119.  
  120. float ovtPay;
  121. ovtPay = ovtHours * wage * OVT_RATE;
  122. return ovtPay;
  123.  
  124. }
  125.  
  126. // FUNCTION calculateGrossPay
  127. // Calculates the gross pay of employee. Regular pay + overtime pay
  128. // Parameters: regPay - regular pay
  129. // overtimPay - overtime pay
  130. // Returns: gross pay
  131. float calculateGrossPay (float regPay, float overtimePay) {
  132.  
  133. float gross;
  134. gross = regPay + overtimePay;
  135. return gross;
  136.  
  137. }
  138.  
  139. int main(void) {
  140. //scruct array initialization
  141. struct employee emps[SIZE] = {
  142. {98401, 10.60, 0, 0, 0, 0, 0, 0},
  143. {526488, 9.75, 0, 0, 0, 0, 0, 0},
  144. {765349, 10.50, 0, 0, 0, 0, 0, 0},
  145. {34645, 12.25, 0, 0, 0, 0, 0, 0},
  146. {127615, 8.35, 0, 0, 0, 0, 0, 0}
  147. };
  148.  
  149. printf("Clock# Wage Hours OT GrossPay\n");
  150. printf("---------------------------------------\n");
  151.  
  152. for (int i =0; i < SIZE; ++i) {
  153. emps[i].totalHours = getHours(emps[i].number);
  154. emps[i].regHours = getRegularHours(emps[i].totalHours);
  155. emps[i].ovtHours = calculateOvtHours(emps[i].totalHours);
  156. emps[i].regPay = calculateRegPay(emps[i].regHours, emps[i].wage);
  157. emps[i].ovtPay = calculateOvtPay(emps[i].ovtHours, emps[i].wage);
  158. emps[i].grossPay = calculateGrossPay(emps[i].regPay, emps[i].ovtPay);
  159.  
  160. printf("%06li\t %.2f\t %.2f\t %.2f\t %.2f\t\n", emps[i].number, emps[i].wage, emps[i].totalHours, emps[i].ovtHours, emps[i].grossPay);
  161. }
  162. return 0;
  163. }
  164.  
Success #stdin #stdout 0s 5288KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
Clock#	Wage	Hours	OT	GrossPay
---------------------------------------
098401	 10.60	 51.00	 11.00	 598.90	
526488	 9.75	 42.50	 2.50	 426.56	
765349	 10.50	 37.00	 0.00	 388.50	
034645	 12.25	 45.00	 5.00	 581.88	
127615	 8.35	 0.00	 0.00	 0.00