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