fork(2) download
  1. //********************************************************
  2. //
  3. // Assignment 6 - structure
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 7/06/2025
  10. //
  11. // Description: Write a C program that will calculate
  12. // thegross pay of a set of employees. Continue
  13. // to use all the features from your past assignments.
  14. // In particular, expand upon your previous assignment
  15. // and continue to use multiple functions and constants
  16. // to help with various tasks called upon by your program.
  17. //
  18. // All functions are called by value
  19. //
  20. //********************************************************
  21.  
  22. #include <stdio.h>
  23.  
  24. // constants
  25. #define SIZE 5
  26. #define OVERTIME_RATE 1.5f
  27. #define STD_WORK_WEEK 40.0f
  28.  
  29. // function prototypes
  30. float getHours (long int clockNumber);
  31. void printHeader (void);
  32. void printEmp (long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay);
  33.  
  34. float calcOvertimeHours(float hours);
  35. float calcGrossPay(float hours, float wageRate);
  36.  
  37.  
  38. // TODO: Add other function prototypes here as needed
  39.  
  40. int main() {
  41.  
  42. /* Variable Declarations */
  43.  
  44. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  45. float grossPay[SIZE]; // gross pay
  46. float hours[SIZE] = {51.0, 42.5, 37.0, 45.0, 0.0}; // hours worked in a given week
  47. int i; // loop and array index
  48. float overtimeHrs[SIZE]; // overtime hours
  49. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  50.  
  51. // process each employee
  52. for (i = 0; i < SIZE; ++i)
  53. {
  54. // Read in hours for employee
  55. hours[i] = getHours(clockNumber[i]);
  56.  
  57. // TODO: Function call to calculate overtime hours
  58. overtimeHrs[i] = calcOvertimeHours(hours[i]);
  59.  
  60. // TODO: Function call to calculate gross pay
  61. grossPay[i] = calcGrossPay(hours[i], wageRate[i]);
  62. }
  63.  
  64. // print the header info
  65. printHeader();
  66. for (i = 0; i < SIZE; ++i) {
  67. printEmp(clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  68. } {
  69. printf("\n\n*** Pay Calculator ***\n");
  70. printf("\nClock# Wage Hours OT Gross\n");
  71. printf("----------------------------------------\n");
  72. }
  73.  
  74. // print out each employee
  75. for (i = 0; i < SIZE; ++i)
  76. {
  77. // Print all the employees - call by value
  78. printEmp (clockNumber[i], wageRate[i], hours[i],
  79. overtimeHrs[i], grossPay[i]);
  80.  
  81. // for
  82. } // main
  83.  
  84. return (0);
  85.  
  86. }
  87. //**************************************************************
  88. // Function: getHours
  89. //
  90. // Purpose: Obtains input from user, the number of hours worked
  91. // per employee and stores the result in a local variable
  92. // that is passed back to the calling function.
  93. //
  94. // Parameters: clockNumber - The unique employee ID
  95. //
  96. // Returns: hoursWorked - hours worked in a given week
  97. //
  98. //**************************************************************
  99.  
  100. float getHours (long int clockNumber) {
  101. float hoursWorked; // hours worked in a given week
  102. // Read in hours for employee
  103. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  104. scanf("%f", &hoursWorked);
  105. // return hours back to the calling function
  106. return hoursWorked;
  107.  
  108. } // getHours
  109.  
  110. float calcOvertimeHours(float hours) {
  111. if (hours > STD_WORK_WEEK)
  112. return hours - STD_WORK_WEEK;
  113. else
  114. return 0.0f;}
  115.  
  116. float calcGrossPay(float hours, float wageRate) {
  117. float overtime = calcOvertimeHours(hours);
  118. float regularHours = (hours > STD_WORK_WEEK) ? STD_WORK_WEEK : hours;
  119. return (regularHours * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  120.  
  121. }
  122.  
  123.  
  124. //**************************************************************
  125. // Function: printHeader
  126. //
  127. // Purpose: Prints the initial table header information.
  128. //
  129. // Parameters: none
  130. //
  131. // Returns: void
  132. //
  133. //**************************************************************
  134.  
  135. void printHeader (void)
  136. {
  137.  
  138. printf ("\n\n*** Pay Calculator ***\n");
  139.  
  140. // print the table header
  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 the employee
  167. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n",
  168. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  169. // TODO: add code to print out a single employee
  170. printf("------------------------------------------------\n");
  171.  
  172.  
  173.  
  174. }
  175.  
  176.  
  177. // TODO: Add other functions here as needed
  178. // ... remember your comment block headers for each function
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
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 ***
098401  10.60    0.0    0.0      0.00
------------------------------------------------
526488   9.75    0.0    0.0      0.00
------------------------------------------------
765349  10.50    0.0    0.0      0.00
------------------------------------------------
034645  12.25    0.0    0.0      0.00
------------------------------------------------
127615   8.35    0.0    0.0      0.00
------------------------------------------------


*** Pay Calculator ***

Clock#   Wage   Hours   OT     Gross
----------------------------------------
098401  10.60    0.0    0.0      0.00
------------------------------------------------
526488   9.75    0.0    0.0      0.00
------------------------------------------------
765349  10.50    0.0    0.0      0.00
------------------------------------------------
034645  12.25    0.0    0.0      0.00
------------------------------------------------
127615   8.35    0.0    0.0      0.00
------------------------------------------------