fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Fisher Brown
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: March 9th 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 reference design
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20.  
  21. #define SIZE 5
  22. #define STD_HOURS 40.0
  23. #define OT_RATE 1.5
  24.  
  25. struct employee {
  26. long clockNumber;
  27. float wageRate;
  28. float hours;
  29. float overtimeHrs;
  30. float grossPay;
  31. };
  32.  
  33. void getHours(struct employee employeeData[], int theSize);
  34. void calculateOvertime(struct employee employeeData[], int theSize);
  35. void calculateGrossPay(struct employee employeeData[], int theSize);
  36. void printHeader(void);
  37. void printEmp(struct employee employeeData[], int theSize);
  38.  
  39. int main() {
  40. struct employee employeeData[SIZE] = {
  41. { 98401, 10.60, 0, 0, 0 },
  42. { 526488, 9.75, 0, 0, 0 },
  43. { 765349, 10.50, 0, 0, 0 },
  44. { 34645, 12.25, 0, 0, 0 },
  45. { 127615, 8.35, 0, 0, 0 }
  46. };
  47.  
  48. getHours(employeeData, SIZE);
  49. calculateOvertime(employeeData, SIZE);
  50. calculateGrossPay(employeeData, SIZE);
  51. printHeader();
  52. printEmp(employeeData, SIZE);
  53.  
  54. return 0;
  55. }
  56.  
  57. void getHours(struct employee employeeData[], int theSize) {
  58. for (int i = 0; i < theSize; ++i) {
  59. printf("\nEnter hours worked by emp # %06li: ", employeeData[i].clockNumber);
  60. scanf("%f", &employeeData[i].hours);
  61. }
  62. }
  63.  
  64. void calculateOvertime(struct employee employeeData[], int theSize) {
  65. for (int i = 0; i < theSize; ++i) {
  66. if (employeeData[i].hours > STD_HOURS) {
  67. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  68. } else {
  69. employeeData[i].overtimeHrs = 0;
  70. }
  71. }
  72. }
  73.  
  74. void calculateGrossPay(struct employee employeeData[], int theSize) {
  75. for (int i = 0; i < theSize; ++i) {
  76. float normalPay = (employeeData[i].hours - employeeData[i].overtimeHrs) * employeeData[i].wageRate;
  77. float overtimePay = employeeData[i].overtimeHrs * (employeeData[i].wageRate * OT_RATE);
  78. employeeData[i].grossPay = normalPay + overtimePay;
  79. }
  80. }
  81.  
  82. void printHeader(void) {
  83. printf("\n\n*** Pay Calculator ***\n");
  84. printf("\nClock# Wage Hours OT Gross\n");
  85. printf("------------------------------------------------\n");
  86. }
  87.  
  88. void printEmp(struct employee employeeData[], int theSize) {
  89. for (int i = 0; i < theSize; ++i) {
  90. printf("\n%06li %6.2f %6.1f %6.1f %8.2f",
  91. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  92. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  93. }
  94. printf("\n");
  95. }
Success #stdin #stdout 0s 5284KB
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