fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Katie Sandoval
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 10/19/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. #include <stdio.h>
  20.  
  21. // Define Constants
  22. #define SIZE 5
  23. #define STD_HOURS 40.0
  24. #define OT_RATE 1.5
  25.  
  26. // Define a global structure to pass employee data between functions
  27. // Note that the structure type is global, but you don't want a variable
  28. // of that type to be global. Best to declare a variable of that type
  29. // in a function like main or another function and pass as needed.
  30. struct employee
  31. {
  32. long int clockNumber;
  33. float wageRate;
  34. float hours;
  35. float overtimeHrs;
  36. float grossPay;
  37. };
  38.  
  39. // define prototypes here for each function except main
  40. float getHours (long int clockNumber);
  41. void printHeader (void);
  42. void printEmp (long int clockNumber, float wageRate, float hours,
  43. float overtimeHrs, float grossPay);
  44.  
  45. // TODO: Add your other function prototypes here
  46. float calcOT (float hours);
  47. float calcGross (float wageRate, float hours, float overtimeHrs);
  48.  
  49. //**************************************************************
  50. int main ()
  51. {
  52. // Set up a local variable to store the employee information
  53. struct employee employeeData[SIZE] = {
  54. { 98401, 10.60 },
  55. { 526488, 9.75 },
  56. { 765349, 10.50 }, // initialize clock and wage values
  57. { 34645, 12.25 },
  58. { 127615, 8.35 }
  59. };
  60.  
  61. int i; // loop and array index
  62.  
  63. // Call functions as needed to read and calculate information
  64. for (i = 0; i < SIZE; ++i)
  65. {
  66. // Prompt for the number of hours worked by the employee
  67.  
  68. employeeData[i].hours = getHours (employeeData[i].clockNumber);
  69.  
  70. // TODO: Add other function calls as needed to calculate overtime and gross
  71. employeeData[i].overtimeHrs = calcOT(employeeData[i].hours);
  72. employeeData[i].grossPay = calcGross(employeeData[i].wageRate,
  73. employeeData[i].hours,
  74. employeeData[i].overtimeHrs);
  75. } // for
  76.  
  77. // Print the column headers
  78. printHeader();
  79.  
  80. // print out each employee
  81. for (i = 0; i < SIZE; ++i)
  82. {
  83. printEmp (employeeData[i].clockNumber,
  84. employeeData[i].wageRate,
  85. employeeData[i].hours,
  86. employeeData[i].overtimeHrs,
  87. employeeData[i].grossPay);
  88. }
  89.  
  90. return(0); // success
  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. float getHours (long int clockNumber)
  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. } // getHours
  116.  
  117. //**************************************************************
  118. // Function: printHeader
  119. //
  120. // Purpose: Prints the initial table header information.
  121. //
  122. // Parameters: none
  123. //
  124. // Returns: void
  125. //
  126. //**************************************************************
  127. void printHeader (void)
  128. {
  129. printf ("\n\n--------------------------------------------------------------------------\n");
  130. printf(" Clock# Wage Hours OT Gross\n");
  131. printf("--------------------------------------------------------------------------\n");
  132. } // printHeader
  133.  
  134. //*************************************************************
  135. // Function: printEmp
  136. //
  137. // Purpose: Prints out all the information for an employee
  138. // in a nice and orderly table format.
  139. //
  140. // Parameters:
  141. //
  142. // clockNumber - unique employee ID
  143. // wageRate - hourly wage rate
  144. // hours - Hours worked for the week
  145. // overtimeHrs - overtime hours worked in a week
  146. // grossPay - gross pay for the week
  147. //
  148. // Returns: void
  149. //
  150. //**************************************************************
  151. void printEmp (long int clockNumber, float wageRate, float hours,
  152. float overtimeHrs, float grossPay)
  153. {
  154.  
  155. printf ("\t%06ld %5.2f %5.1f %5.1f %7.2f\n",
  156. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  157. } // printEmp
  158.  
  159. // TODO: Add your functions here
  160.  
  161. //*************************************************************
  162. // Function: calcOT
  163. //
  164. // Purpose: Calulates Overtime.
  165. //
  166. // Parameters: float hours
  167. //
  168. //
  169. // Returns: value
  170. //*************************************************************
  171. float calcOT (float hours)
  172. {
  173. float overtimeHrs;
  174. // TODO: implement overtime calculation
  175. if (hours > STD_HOURS)
  176. return hours - STD_HOURS;
  177. else
  178. {
  179. overtimeHrs=0;
  180.  
  181. }
  182. //return the calculatd overtime hours value
  183. return(overtimeHrs);
  184. }//calcOT
  185.  
  186. //*************************************************************
  187. // Function: calcGross
  188. //
  189. // Purpose: Calulates Grosspay.
  190. //
  191. // Parameters: float wageRate, float hours, floar overtimeHRs
  192. //
  193. //
  194. // Returns: value
  195. //*************************************************************
  196. //Funcation Definition for calGross(Call by Value)
  197. float calcGross (float wageRate, float hours, float overtimeHrs)
  198. {
  199. // TODO: implement gross pay calculation
  200. float grossPay;
  201. float normalPay; //normal pay earned
  202. float overtimePay; //overtime pay earned
  203. if (hours > STD_HOURS)
  204. {
  205. float normalPay = STD_HOURS * wageRate;
  206. float overtimePay = overtimeHrs * wageRate * OT_RATE;
  207. grossPay = normalPay + overtimePay;
  208. }
  209. else
  210. {
  211. grossPay = wageRate * hours;
  212. }
  213.  
  214. return grossPay;
  215. }// calcGross
Success #stdin #stdout 0.01s 5316KB
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: 

--------------------------------------------------------------------------
    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