fork(1) download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Functions
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 6/29/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. // constants
  22. #define SIZE 5
  23. #define OVERTIME_RATE 1.5f
  24. #define STD_WORK_WEEK 40.0f
  25.  
  26. // function prototypes
  27. struct employee {
  28. long int clockNumber;
  29. float wageRate;
  30. float hours;
  31. float overtimeHrs;
  32. float grossPay;
  33. };
  34.  
  35. float getHours(long int clockNumber);
  36. float calcOvertimeHours(float hours);
  37. float calcGrossPay(float hours, float wageRate);
  38. void printHeader(void);
  39. void printEmp(struct employee emp);
  40.  
  41. // TODO: Add other function prototypes here as needed
  42.  
  43.  
  44. /* Variable Declarations */
  45. int main() {
  46. struct employee employeeData[SIZE] = {
  47. {98401, 10.60, 0, 0, 0},
  48. {526488, 9.75, 0, 0, 0},
  49. {765349, 10.50, 0, 0, 0},
  50. {34645, 12.25, 0, 0, 0},
  51. {127615, 8.35, 0, 0, 0}
  52. };
  53.  
  54. int i;
  55.  
  56. // function prototypes
  57.  
  58.  
  59. // process each employee
  60. for (i = 0; i < SIZE; ++i)
  61. {
  62. // Read in hours for employee
  63. employeeData[i].hours = getHours(employeeData[i].clockNumber);
  64.  
  65. // TODO: Function call to calculate overtime hours
  66. employeeData[i].overtimeHrs = calcOvertimeHours(employeeData[i].hours);
  67.  
  68. // TODO: Function call to calculate gross pay
  69. employeeData[i].grossPay = calcGrossPay(employeeData[i].hours, employeeData[i].wageRate);
  70.  
  71.  
  72. }
  73. // print the header info
  74. printHeader();{
  75. printf("\nClock# Wage Hours OT Gross\n");
  76. printf("----------------------------------------\n");
  77. }
  78.  
  79. // Print employee data
  80. for (i = 0; i < SIZE; ++i) {
  81. printEmp(employeeData[i]);
  82. }
  83.  
  84. return 0;
  85. }
  86.  
  87.  
  88. //**************************************************************
  89. // Function: getHours
  90. //
  91. // Purpose: Obtains input from user, the number of hours worked
  92. // per employee and stores the result in a local variable
  93. // that is passed back to the calling function.
  94. //
  95. // Parameters: clockNumber - The unique employee ID
  96. //
  97. // Returns: hoursWorked - hours worked in a given week
  98. //
  99. //**************************************************************
  100.  
  101. float getHours (long int clockNumber) {
  102. float hoursWorked; // hours worked in a given week
  103. // Read in hours for employee
  104. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  105. scanf("%f", &hoursWorked);
  106. // return hours back to the calling function
  107. return hoursWorked;
  108.  
  109. } // getHours
  110.  
  111. float calcOvertimeHours(float hours) {
  112. if (hours > STD_WORK_WEEK)
  113. return hours - STD_WORK_WEEK;
  114. else
  115. return 0.0f;
  116. }
  117.  
  118. float calcGrossPay(float hours, float wageRate) {
  119. float overtime = calcOvertimeHours(hours);
  120. if (hours > STD_WORK_WEEK) {
  121. return (STD_WORK_WEEK * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  122. } else {
  123. return hours * wageRate;
  124. }
  125. }// overtime pay
  126.  
  127.  
  128. //**************************************************************
  129. // Function: printHeader
  130. //
  131. // Purpose: Prints the initial table header information.
  132. //
  133. // Parameters: none
  134. //
  135. // Returns: void
  136. //
  137. //**************************************************************
  138.  
  139. void printHeader (void)
  140. {
  141.  
  142. printf ("\n\n*** Pay Calculator ***\n");
  143.  
  144. // print the table header
  145. printf("\nClock# Wage Hours OT Gross\n");
  146. printf("----------------------------------------\n");
  147.  
  148. } // printHeader
  149.  
  150. //*************************************************************
  151. // Function: printEmp
  152. //
  153. // Purpose: Prints out all the information for an employee
  154. // in a nice and orderly table format.
  155. //
  156. // Parameters:
  157. //
  158. // clockNumber - unique employee ID
  159. // wageRate - hourly wage rate
  160. // hours - Hours worked for the week
  161. // overtimeHrs - overtime hours worked in a week
  162. // grossPay - gross pay for the week
  163. //
  164. // Returns: void
  165. //
  166. //**************************************************************
  167.  
  168. void printEmp(struct employee emp) {
  169. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n",
  170. emp.clockNumber, emp.wageRate, emp.hours,
  171. emp.overtimeHrs, emp.grossPay);
  172.  
  173.  
  174. // TODO: Add other functions here as needed
  175. // ... remember your comment block headers for each function
  176.  
  177. }
  178.  
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
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
----------------------------------------

Clock#   Wage   Hours   OT     Gross
----------------------------------------
098401  10.60    0.0    0.0      0.00
526488   9.75    0.0    0.0      0.00
765349  10.50    0.0    0.0      0.00
034645  12.25    0.0    0.0      0.00
127615   8.35    0.0    0.0      0.00