fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: <Amir Gharouadi>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <03/08/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. #include <stdio.h>
  20.  
  21. #define SIZE 5
  22. #define STD_HOURS 40.0
  23. #define OT_RATE 1.5
  24.  
  25. struct employee
  26. {
  27. long int clockNumber;
  28. float wageRate;
  29. float hours;
  30. float overtimeHrs;
  31. float grossPay;
  32. };
  33.  
  34. /* function prototypes */
  35. float getHours(long int clockNumber);
  36. float calcOvertime(float hours);
  37. float calcGross(float wageRate, float hours, float overtimeHrs);
  38. void printHeader(void);
  39. void printEmp(long int clockNumber, float wageRate, float hours,
  40. float overtimeHrs, float grossPay);
  41.  
  42. int main(void)
  43. {
  44. struct employee employeeData[SIZE] = {
  45. {98401, 10.60, 0.0, 0.0, 0.0},
  46. {526488, 9.75, 0.0, 0.0, 0.0},
  47. {765349, 10.50, 0.0, 0.0, 0.0},
  48. {34645, 12.25, 0.0, 0.0, 0.0},
  49. {127615, 8.35, 0.0, 0.0, 0.0}
  50. };
  51.  
  52. int i;
  53.  
  54. for (i = 0; i < SIZE; i++)
  55. {
  56. employeeData[i].hours = getHours(employeeData[i].clockNumber);
  57. employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
  58. employeeData[i].grossPay = calcGross(employeeData[i].wageRate,
  59. employeeData[i].hours,
  60. employeeData[i].overtimeHrs);
  61. }
  62.  
  63. printHeader();
  64.  
  65. for (i = 0; i < SIZE; i++)
  66. {
  67. printEmp(employeeData[i].clockNumber,
  68. employeeData[i].wageRate,
  69. employeeData[i].hours,
  70. employeeData[i].overtimeHrs,
  71. employeeData[i].grossPay);
  72. }
  73.  
  74. return 0;
  75. }
  76.  
  77. //**************************************************************
  78. // Function: getHours
  79. //
  80. // Purpose: Obtains input from user, the number of hours worked
  81. // per employee and returns it to the calling function.
  82. //
  83. // Parameters: clockNumber - The unique employee ID
  84. //
  85. // Returns: hoursWorked - hours worked in a given week
  86. //**************************************************************
  87. float getHours(long int clockNumber)
  88. {
  89. float hoursWorked;
  90.  
  91. printf("Enter hours worked by emp # %06li: ", clockNumber);
  92. scanf("%f", &hoursWorked);
  93.  
  94. return hoursWorked;
  95. }
  96.  
  97. //**************************************************************
  98. // Function: calcOvertime
  99. //
  100. // Purpose: Determines overtime hours worked.
  101. //
  102. // Parameters: hours - total hours worked
  103. //
  104. // Returns: overtime hours
  105. //**************************************************************
  106. float calcOvertime(float hours)
  107. {
  108. if (hours > STD_HOURS)
  109. {
  110. return hours - STD_HOURS;
  111. }
  112. else
  113. {
  114. return 0.0;
  115. }
  116. }
  117.  
  118. //**************************************************************
  119. // Function: calcGross
  120. //
  121. // Purpose: Determines gross pay including overtime.
  122. //
  123. // Parameters:
  124. // wageRate - employee hourly wage
  125. // hours - total hours worked
  126. // overtimeHrs - overtime hours worked
  127. //
  128. // Returns: gross pay
  129. //**************************************************************
  130. float calcGross(float wageRate, float hours, float overtimeHrs)
  131. {
  132. float regularHours;
  133. float normalPay;
  134. float overtimePay;
  135.  
  136. regularHours = hours - overtimeHrs;
  137. normalPay = regularHours * wageRate;
  138. overtimePay = overtimeHrs * wageRate * OT_RATE;
  139.  
  140. return normalPay + overtimePay;
  141. }
  142.  
  143. //**************************************************************
  144. // Function: printHeader
  145. //
  146. // Purpose: Prints the initial table header information.
  147. //
  148. // Parameters: none
  149. //
  150. // Returns: void
  151. //**************************************************************
  152. void printHeader(void)
  153. {
  154. printf("\n--------------------------------------------------------------------------\n");
  155. printf(" Clock# Wage Hours OT Gross\n");
  156. printf("--------------------------------------------------------------------------\n");
  157. }
  158.  
  159. //**************************************************************
  160. // Function: printEmp
  161. //
  162. // Purpose: Prints out all the information for an employee
  163. // in a nice and orderly table format.
  164. //
  165. // Parameters:
  166. // clockNumber - unique employee ID
  167. // wageRate - hourly wage rate
  168. // hours - hours worked for the week
  169. // overtimeHrs - overtime hours worked in a week
  170. // grossPay - gross pay for the week
  171. //
  172. // Returns: void
  173. //**************************************************************
  174. void printEmp(long int clockNumber, float wageRate, float hours,
  175. float overtimeHrs, float grossPay)
  176. {
  177. printf(" %06li %5.2f %5.1f %5.1f %7.2f\n",
  178. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  179. }
Success #stdin #stdout 0.01s 5308KB
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: 
--------------------------------------------------------------------------
    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