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