fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Marin Haxhiaj
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: 03/08/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. // All functions are called by value
  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. // Define a global structure to pass employee data between functions
  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. float calcOvertime(float hours);
  42. float calcGrossPay(float wage, float hours, float overtimeHrs);
  43.  
  44. int main()
  45. {
  46. struct employee employeeData[SIZE] = {
  47. {98401, 10.60},
  48. {526488, 9.75},
  49. {765349, 10.50},
  50. {34645, 12.25},
  51. {127615, 8.35}};
  52.  
  53. int i;
  54.  
  55. for (i = 0; i < SIZE; ++i)
  56. {
  57. employeeData[i].hours = getHours(employeeData[i].clockNumber);
  58. employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
  59. employeeData[i].grossPay = calcGrossPay(employeeData[i].wageRate,
  60. employeeData[i].hours,
  61. employeeData[i].overtimeHrs);
  62. }
  63.  
  64. printHeader();
  65.  
  66. for (i = 0; i < SIZE; ++i)
  67. {
  68. printEmp(employeeData[i].clockNumber,
  69. employeeData[i].wageRate,
  70. employeeData[i].hours,
  71. employeeData[i].overtimeHrs,
  72. employeeData[i].grossPay);
  73. }
  74.  
  75. return 0;
  76. }
  77.  
  78. //**************************************************************
  79. // Function: getHours
  80. //
  81. // Purpose: Obtains input from user, the number of hours worked
  82. // per employee and stores the result in a local variable
  83. // that is passed back to the calling function.
  84. //
  85. // Parameters: clockNumber - The unique employee ID
  86. //
  87. // Returns: hoursWorked - hours worked in a given week
  88. //
  89. //**************************************************************
  90.  
  91. float getHours(long int clockNumber)
  92. {
  93. float hoursWorked;
  94. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  95. scanf("%f", &hoursWorked);
  96. return hoursWorked;
  97. }
  98.  
  99. //**************************************************************
  100. // Function: printHeader
  101. //
  102. // Purpose: Prints the initial table header information.
  103. //
  104. // Parameters: none
  105. //
  106. // Returns: void
  107. //
  108. //**************************************************************
  109. void printHeader(void)
  110. {
  111. printf("\n\n*** Pay Calculator ***\n");
  112. printf("\nClock# Wage Hours OT Gross\n");
  113. printf("------------------------------------------------\n");
  114. }
  115.  
  116. //*************************************************************
  117. // Function: printEmp
  118. //
  119. // Purpose: Prints out all the information for an employee
  120. // in a nice and orderly table format.
  121. //
  122. // Parameters:
  123. //
  124. // clockNumber - unique employee ID
  125. // wageRate - hourly wage rate
  126. // hours - Hours worked for the week
  127. // overtimeHrs - overtime hours worked in a week
  128. // grossPay - gross pay for the week
  129. //
  130. // Returns: void
  131. //
  132. //**************************************************************
  133. void printEmp(long int clockNumber, float wageRate, float hours,
  134. float overtimeHrs, float grossPay)
  135. {
  136. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  137. clockNumber, wageRate, hours,
  138. overtimeHrs, grossPay);
  139. }
  140.  
  141. float calcOvertime(float hours)
  142. {
  143. if (hours > STD_HOURS)
  144. {
  145. return hours - STD_HOURS;
  146. }
  147. else
  148. {
  149. return 0.0;
  150. }
  151. }
  152.  
  153. float calcGrossPay(float wage, float hours, float overtimeHrs)
  154. {
  155. float regularPay = (hours - overtimeHrs) * wage;
  156. float overtimePay = overtimeHrs * wage * OT_RATE;
  157. return regularPay + overtimePay;
  158. }
Success #stdin #stdout 0s 5276KB
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