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 hoursTotal;
  38. float overtimeHrs;
  39. float grossPay;
  40. float normalPay;
  41. float overtimePay;
  42. };
  43.  
  44. // define prototypes here for each function except main
  45. float getHours (long int clockNumber);
  46. void printHeader (void);
  47. void printEmp (long int clockNumber, float wageRate, float hoursTotal,
  48. float overtimeHrs, float grossPay);
  49.  
  50. // TODO: Add your other function prototypes here
  51. float calcOT (float hoursTotal);
  52. float calcGross (float wageRate, float hoursTotal, float overtimeHrs);
  53.  
  54. int main ()
  55. {
  56. // Set up a local variable to store the employee information
  57. struct employee employeeData[SIZE] = {
  58. { 98401, 10.60 },
  59. { 526488, 9.75 },
  60. { 765349, 10.50 }, // initialize clock and wage values
  61. { 34645, 12.25 },
  62. { 127615, 8.35 }
  63. };
  64.  
  65. int i; // loop and array index
  66.  
  67. // Call functions as needed to read and calculate information
  68. for (i = 0; i < SIZE; ++i)
  69. {
  70.  
  71. // Prompt for the number of hours worked by the employee
  72. employeeData[i].hoursTotal = getHours (employeeData[i].clockNumber);
  73.  
  74. // TODO: Add other function calls as needed to calculate overtime and gross
  75.  
  76. } // for
  77.  
  78. // Print the column headers
  79. printHeader();
  80.  
  81. // print out each employee
  82. for (i = 0; i < SIZE; ++i)
  83. {
  84. printEmp (employeeData[i].clockNumber,
  85. employeeData[i].wageRate,
  86. employeeData[i].hoursTotal,
  87. employeeData[i].overtimeHrs,
  88. employeeData[i].grossPay);
  89. }
  90.  
  91. return(0); // success
  92.  
  93. } // main
  94.  
  95. //**************************************************************
  96. // Function: getHours
  97. //
  98. // Purpose: Obtains input from user, the number of hours worked
  99. // per employee and stores the result in a local variable
  100. // that is passed back to the calling function.
  101. //
  102. // Parameters: clockNumber - The unique employee ID
  103. //
  104. // Returns: hoursWorked - hours worked in a given week
  105. //
  106. //**************************************************************
  107.  
  108. float getHours (long int clockNumber)
  109. {
  110.  
  111. float hoursWorked; // hours worked in a given week
  112.  
  113. // Read in hours for employee
  114. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  115. scanf ("%f", &hoursWorked);
  116.  
  117. // return hours back to the calling function
  118. return (hoursWorked);
  119.  
  120. } // getHours
  121.  
  122. //**************************************************************
  123. // Function: printHeader
  124. //
  125. // Purpose: Prints the initial table header information.
  126. //
  127. // Parameters: none
  128. //
  129. // Returns: void
  130. //
  131. //**************************************************************
  132.  
  133. void printHeader (void)
  134. {
  135.  
  136. printf ("\n\n*** Pay Calculator ***\n");
  137.  
  138. // print the table header
  139. printf("\nClock# Wage Hours OT Gross\n");
  140. printf("------------------------------------------------\n");
  141.  
  142. } // printHeader
  143.  
  144. //*************************************************************
  145. // Function: printEmp
  146. //
  147. // Purpose: Prints out all the information for an employee
  148. // in a nice and orderly table format.
  149. //
  150. // Parameters:
  151. //
  152. // clockNumber - unique employee ID
  153. // wageRate - hourly wage rate
  154. // hours - Hours worked for the week
  155. // overtimeHrs - overtime hours worked in a week
  156. // grossPay - gross pay for the week
  157. //
  158. // Returns: void
  159. //
  160. //**************************************************************
  161.  
  162. void printEmp (long int clockNumber, float wageRate, float hours,
  163. float overtimeHrs, float grossPay)
  164. {
  165.  
  166. // Print out a single employee
  167. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  168. clockNumber, wageRate, hours,
  169. overtimeHrs, grossPay);
  170.  
  171. } // printEmp
  172.  
  173. // TODO: Add your functions here
  174. //*************************************************************
  175. // Function: calcOT
  176. //
  177. // Purpose: Calculate the overtime hours of employees if logged
  178. // more than the standard week
  179. //
  180. // Parameters:
  181. // hoursTotal- total logged hours per employee
  182. // STD_WORK_WEEK - the standard amount of 40 hours per week
  183. //
  184. // Returns: overtimeHrs
  185. //
  186. //**************************************************************
  187. //
  188.  
  189. float calcOT (float hoursTotal) // Function Definition
  190. {
  191. //local variable
  192. float overtimeHrs;
  193. //computation
  194. if (hoursTotal > STD_HOURS)
  195. {
  196. overtimeHrs = hoursTotal - STD_HOURS;
  197. }
  198. //return computation
  199. return (overtimeHrs);
  200. } // calcOT
  201.  
  202. //
  203. //*************************************************************
  204. // Function: calcGross
  205. //
  206. // Purpose: Calculate the Gross Pay of employees considering
  207. // any overtime hours logged
  208. //
  209. // Parameters:
  210. // wageRate - hourly wage of employees
  211. // hoursTotal- the total hours logged for employees
  212. // overtimeHrs - any overtime hours for any applicable employee logs
  213. //
  214. // Returns: grossPay
  215. //
  216. //**************************************************************
  217. //
  218. float calcGross (float wageRate, float hoursTotal, float overtimeHrs) // Function Definition
  219. {
  220. //local variable
  221. float grossPay;
  222. float normalPay;
  223. float overtimePay;
  224. //computation
  225. if (hoursTotal > STD_HOURS)
  226. {
  227. overtimeHrs = hoursTotal - STD_HOURS;
  228. overtimePay = overtimeHrs * (OT_RATE*wageRate);
  229. normalPay = STD_HOURS*wageRate;
  230. grossPay = normalPay + overtimePay;
  231. } // End if
  232.  
  233. else // No Overtime
  234. {
  235. overtimeHrs=0;
  236. normalPay=wageRate*hoursTotal;
  237. grossPay=normalPay;
  238. } // End else
  239. //return computation
  240. return (grossPay);
  241. } // calcGross
  242. //**************************************************************
Success #stdin #stdout 0s 5296KB
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