fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Nalani Fernandez
  6. //
  7. // Class: C Programming, Summer 2026
  8. //
  9. // Date: 7/2/2026
  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. void calcOT(struct employee employeeData[], int size);
  49. void calcGrossPay(struct employee employeeData[], int size);
  50.  
  51. int main ()
  52. {
  53. // Set up a local variable to store the employee information
  54. struct employee employeeData[SIZE] = {
  55. { 98401, 10.60 },
  56. { 526488, 9.75 },
  57. { 765349, 10.50 }, // initialize clock and wage values
  58. { 34645, 12.25 },
  59. { 127615, 8.35 }
  60. };
  61.  
  62. int i; // loop and array index
  63.  
  64. // Call functions as needed to read and calculate information
  65. for (i = 0; i < SIZE; ++i)
  66. {
  67.  
  68. // Prompt for the number of hours worked by the employee
  69. employeeData[i].hours = getHours (employeeData[i].clockNumber);
  70. } // for
  71.  
  72. calcOT(employeeData, SIZE);
  73. calcGrossPay(employeeData, SIZE);
  74.  
  75. // Print the column headers
  76. printHeader();
  77.  
  78. // print out each employee
  79. for (i = 0; i < SIZE; ++i)
  80. {
  81. printEmp (employeeData[i].clockNumber,
  82. employeeData[i].wageRate,
  83. employeeData[i].hours,
  84. employeeData[i].overtimeHrs,
  85. employeeData[i].grossPay);
  86. }
  87.  
  88. return(0); // success
  89.  
  90. } // main
  91.  
  92. //**************************************************************
  93. // Function: getHours
  94. //
  95. // Purpose: Obtains input from user, the number of hours worked
  96. // per employee and stores the result in a local variable
  97. // that is passed back to the calling function.
  98. //
  99. // Parameters: clockNumber - The unique employee ID
  100. //
  101. // Returns: hoursWorked - hours worked in a given week
  102. //
  103. //**************************************************************
  104.  
  105. float getHours (long int clockNumber)
  106. {
  107.  
  108. float hoursWorked; // hours worked in a given week
  109.  
  110. // Read in hours for employee
  111. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  112. scanf ("%f", &hoursWorked);
  113.  
  114. // return hours back to the calling function
  115. return (hoursWorked);
  116.  
  117. } // getHours
  118.  
  119. //**************************************************************
  120. // Function: printHeader
  121. //
  122. // Purpose: Prints the initial table header information.
  123. //
  124. // Parameters: none
  125. //
  126. // Returns: void
  127. //
  128. //**************************************************************
  129.  
  130. void printHeader (void)
  131. {
  132.  
  133. printf ("\n\n*** Pay Calculator ***\n");
  134.  
  135. // print the table header
  136. printf("\nClock# Wage Hours OT Gross\n");
  137. printf("------------------------------------------------\n");
  138.  
  139. } // printHeader
  140.  
  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. void calcOT(struct employee employeeData[], int size)
  172. {
  173. int i;
  174.  
  175. for (i = 0; i < size; ++i)
  176. {
  177. if (employeeData[i].hours > STD_HOURS)
  178. {
  179. employeeData[i].overtimeHrs =
  180. employeeData[i].hours - STD_HOURS;
  181. }
  182. else
  183. {
  184. employeeData[i].overtimeHrs = 0.0;
  185. }
  186. }
  187. }
  188. void calcGrossPay(struct employee employeeData[], int size)
  189. {
  190. int i;
  191.  
  192. for (i = 0; i < size; ++i)
  193. {
  194. employeeData[i].grossPay =
  195. (employeeData[i].hours - employeeData[i].overtimeHrs)
  196. * employeeData[i].wageRate
  197. + employeeData[i].overtimeHrs
  198. * employeeData[i].wageRate
  199. * OT_RATE;
  200. }
  201. }
Success #stdin #stdout 0s 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: 

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