fork(1) download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Brian Fallon
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: March 3, 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. // Call by Value design
  16. //
  17. //********************************************************
  18.  
  19. // Define and Includes
  20.  
  21. #include <stdio.h>
  22.  
  23. // Define Constants
  24. #define SIZE 5
  25. #define STD_HOURS 40.0
  26. #define OT_RATE 1.5
  27.  
  28. // Define a global structure to pass employee data between functions
  29. // Note that the structure type is global, but you don't want a variable
  30. // of that type to be global. Best to declare a variable of that type
  31. // in a function like main or another function and pass as needed.
  32.  
  33. struct employee
  34. {
  35. long int clockNumber;
  36. float wageRate;
  37. float hours;
  38. float overtimeHrs;
  39. float grossPay;
  40. };
  41.  
  42. // define prototypes here for each function except main
  43. float getHours (long int clockNumber);
  44. void printHeader (void);
  45. void printEmp (long int clockNumber, float wageRate, float hours,
  46. float overtimeHrs, float grossPay);
  47.  
  48. // TODO: Add your other function prototypes here
  49. float calcOT (float hoursTotal);
  50. float calcGross (float wageRate, float hoursTotal, float overtimeHrs);
  51.  
  52. int main ()
  53. {
  54. // Set up a local variable to store the employee information
  55. struct employee employeeData[SIZE] = {
  56. { 98401, 10.60 },
  57. { 526488, 9.75 },
  58. { 765349, 10.50 }, // initialize clock and wage values
  59. { 34645, 12.25 },
  60. { 127615, 8.35 }
  61. };
  62.  
  63. int i; // loop and array index
  64.  
  65. // Call functions as needed to read and calculate information
  66. for (i = 0; i < SIZE; ++i)
  67. {
  68.  
  69. // Prompt for the number of hours worked by the employee
  70. employeeData[i].hours = getHours (employeeData[i].clockNumber);
  71.  
  72. // TODO: Add other function calls as needed to calculate overtime and gross
  73.  
  74. } // for
  75.  
  76. // Print the column headers
  77. printHeader();
  78.  
  79. // print out each employee
  80. for (i = 0; i < SIZE; ++i)
  81. {
  82. printEmp (employeeData[i].clockNumber,
  83. employeeData[i].wageRate,
  84. employeeData[i].hours,
  85. employeeData[i].overtimeHrs,
  86. employeeData[i].grossPay);
  87. }
  88.  
  89. return(0); // success
  90.  
  91. } // main
  92.  
  93. //**************************************************************
  94. // Function: getHours
  95. //
  96. // Purpose: Obtains input from user, the number of hours worked
  97. // per employee and stores the result in a local variable
  98. // that is passed back to the calling function.
  99. //
  100. // Parameters: clockNumber - The unique employee ID
  101. //
  102. // Returns: hoursWorked - hours worked in a given week
  103. //
  104. //**************************************************************
  105.  
  106. float getHours (long int clockNumber)
  107. {
  108.  
  109. float hoursWorked; // hours worked in a given week
  110.  
  111. // Read in hours for employee
  112. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  113. scanf ("%f", &hoursWorked);
  114.  
  115. // return hours back to the calling function
  116. return (hoursWorked);
  117.  
  118. } // getHours
  119.  
  120. //**************************************************************
  121. // Function: printHeader
  122. //
  123. // Purpose: Prints the initial table header information.
  124. //
  125. // Parameters: none
  126. //
  127. // Returns: void
  128. //
  129. //**************************************************************
  130.  
  131. void printHeader (void)
  132. {
  133.  
  134. printf ("\n\n*** Pay Calculator ***\n");
  135.  
  136. // print the table header
  137. printf("\nClock# Wage Hours OT Gross\n");
  138. printf("------------------------------------------------\n");
  139.  
  140. } // printHeader
  141.  
  142. //*************************************************************
  143. // Function: printEmp
  144. //
  145. // Purpose: Prints out all the information for an employee
  146. // in a nice and orderly table format.
  147. //
  148. // Parameters:
  149. //
  150. // clockNumber - unique employee ID
  151. // wageRate - hourly wage rate
  152. // hours - Hours worked for the week
  153. // overtimeHrs - overtime hours worked in a week
  154. // grossPay - gross pay for the week
  155. //
  156. // Returns: void
  157. //
  158. //**************************************************************
  159.  
  160. void printEmp (long int clockNumber, float wageRate, float hours,
  161. float overtimeHrs, float grossPay)
  162. {
  163.  
  164. // Print out a single employee
  165. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  166. clockNumber, wageRate, hours,
  167. overtimeHrs, grossPay);
  168.  
  169. } // printEmp
  170.  
  171. // TODO: Add your functions here
  172. //*************************************************************
  173. // Function: calcGross
  174. //
  175. // Purpose: Calculate the Gross Pay of employees considering
  176. // any overtime hours logged
  177. //
  178. // Parameters:
  179. // wageRate - hourly wage of employees
  180. // hoursTotal- the total hours logged for employees
  181. // overtimeHrs - any overtime hours for any applicable employee logs
  182. //
  183. // Returns: grossPay
  184. //
  185. //**************************************************************
  186. //
  187. float calcOT (float hoursTotal) // Function Definition
  188. {
  189. //local variable
  190. float overtimeHrs;
  191. //computation
  192. if (hoursTotal > STD_HOURS)
  193. {
  194. overtimeHrs = hoursTotal - STD_HOURS;
  195. }
  196. //return computation
  197. return (overtimeHrs);
  198. } // calcOT
  199. //**************************************************************
  200. //
  201. float calcGross (float wageRate, float hoursTotal, float overtimeHrs) // Function Definition
  202. {
  203. //local variable
  204. float grossPay;
  205. float normalPay;
  206. float overtimePay;
  207. //computation
  208. if (hoursTotal > STD_HOURS)
  209. {
  210. overtimeHrs = hoursTotal - STD_HOURS;
  211. overtimePay = overtimeHrs * (OT_RATE*wageRate);
  212. normalPay = STD_HOURS*wageRate;
  213. grossPay = normalPay + overtimePay;
  214. } // End if
  215.  
  216. else // No Overtime
  217. {
  218. overtimeHrs=0;
  219. normalPay=wageRate*hoursTotal;
  220. grossPay=normalPay;
  221. } // End else
  222. //return computation
  223. return (grossPay);
  224. } // calcGross
  225. //**************************************************************
Success #stdin #stdout 0.01s 5284KB
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  0.0     0.00
 526488  9.75 42.5  0.0     0.00
 765349 10.50 37.0  0.0     0.00
 034645 12.25 45.0  0.0     0.00
 127615  8.35  0.0  0.0     0.00