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