fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Jacquelin Saint Lucien
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 10/14/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.  
  22. #include <stdio.h>
  23.  
  24. // let's calculate the gross salary of a set of employees.
  25. // in relation to their hours worked, their normal salary and their overtime.
  26.  
  27. // Determine the structure used as requested in the problem description.
  28. struct employee {
  29. int clockNumber;
  30. float wage;
  31. float hours;
  32. float overtimeHours;
  33. float grossPay;
  34. };
  35.  
  36. // calculate overtime hours.
  37. // It takes a pointer to an employee structure and updates the overtimeHours field.
  38. void calculateOvertime(struct employee *emp) {
  39. if (emp->hours > 40.0) {
  40. emp->overtimeHours = emp->hours - 40.0;
  41. } else {
  42. emp->overtimeHours = 0.0;
  43. }
  44. }
  45.  
  46. // calculate gross pay.
  47. // It takes a pointer to an employee structure and updates the grossPay field.
  48. void calculateGrossPay(struct employee *emp) {
  49. float normalHours = emp->hours > 40.0 ? 40.0 : emp->hours;
  50. float overtimeHours = emp->overtimeHours;
  51.  
  52. float normalPay = normalHours * emp->wage;
  53. float overtimePay = overtimeHours * emp->wage * 1.5;
  54.  
  55. emp->grossPay = normalPay + overtimePay;
  56. }
  57.  
  58. int main() {
  59. //Used a local variable to store the employee information.
  60. struct employee employees[5] = {
  61. {98401, 10.00, 0.0, 0.0, 0.0},
  62. {526488, 9.75, 0.0, 0.0, 0.0},
  63. {763349, 10.50, 0.0, 0.0, 0.0},
  64. {34045, 12.25, 0.0, 0.0, 0.0},
  65. {127615, 8.35, 0.0, 0.0, 0.0}
  66. };
  67.  
  68. // The problem specifies to use these hours as input.
  69. float hoursInput[] = {31.0, 42.5, 37.0, 0.0, 0.0};
  70.  
  71. // Call functions as needed to read and calculate information.
  72. for (int i = 0; i < 5; i++) {
  73. // Assign the given hours to the current employee.
  74. employees[i].hours = hoursInput[i];
  75.  
  76. // Call the functions to calculate the overtime hours and gross pay.
  77. calculateOvertime(&employees[i]);
  78. calculateGrossPay(&employees[i]);
  79. }
  80.  
  81. // Print the table header with the specified column titles.
  82. printf("Clock Wage Hours OT Gross\n");
  83. printf("------- ------ ------ ------ ------\n");
  84.  
  85. // Loop through the array again to print the results in a formatted table.
  86. for (int i = 0; i < 5; i++) {
  87. printf("%06d %5.2f %5.1f %5.1f %7.2f\n",
  88. employees[i].clockNumber,
  89. employees[i].wage,
  90. employees[i].hours,
  91. employees[i].overtimeHours,
  92. employees[i].grossPay);
  93. }
  94.  
  95. return 0;
  96. }
  97.  
  98.  
  99.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Clock    Wage    Hours   OT      Gross
-------  ------  ------  ------  ------
098401   10.00   31.0    0.0   310.00
526488    9.75   42.5    2.5   426.56
763349   10.50   37.0    0.0   388.50
034045   12.25    0.0    0.0     0.00
127615    8.35    0.0    0.0     0.00