fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - structure
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 7/13/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. #include <stdio.h>
  22. #include <string.h>
  23.  
  24. #define SIZE 5
  25. #define STD_HOURS 40.0
  26. #define OT_RATE 1.5
  27.  
  28.  
  29. struct name {
  30. char firstName [10];
  31. char lastName [10];
  32. };
  33.  
  34.  
  35.  
  36. struct employee {
  37. struct name empName;
  38. char taxState[3];
  39. long int clockNumber;
  40. float wageRate;
  41. float hours;
  42. float overtimeHrs;
  43. float grossPay;
  44. float stateTax;
  45. float fedTax;
  46. float netPay;
  47. };
  48.  
  49. // constants
  50. struct employeeData {
  51. char taxState[3];
  52. long int clockNumber;
  53. float wageRate;
  54. float hours;
  55. float overtimeHrs;
  56. float grossPay;
  57. float stateTax;
  58. float fedTax;
  59. float netPay;
  60. };
  61.  
  62.  
  63. int main() {
  64.  
  65. struct employee employeeData[SIZE] = {
  66. {{"Connie", "Cobol"}, "MA", 98401, 10.60, 51.0},
  67. {{"Mary", "Apa"}, "CA", 526488, 9.75, 42.5},
  68. {{"Frank", "Fortran"},"VT", 765349, 10.50, 37.0},
  69. {{"Jeff", "Ada"}, "NH", 34645, 12.25, 45.0},
  70. {{"Anton", "Pascal"},"MA", 127615, 8.25, 0.0}
  71. };
  72.  
  73. float calcFedTax(float grossPay) {
  74. return grossPay * 0.15;
  75. };
  76.  
  77. float calcNetPay(float grossPay, float stateTax, float fedTax) {
  78. return grossPay - stateTax - fedTax;
  79. };
  80. float calcOvertime(float hours) {
  81. return (hours > STD_HOURS) ? hours - STD_HOURS : 0.0;
  82. };
  83.  
  84. float calcStateTax(char state[], float grossPay) {
  85. if (strcmp(state, "MA") == 0)
  86. return grossPay * 0.05;
  87.  
  88. else if (strcmp(state, "NH") == 0)
  89. return 0.0;
  90.  
  91. else if (strcmp(state, "VT") == 0)
  92. return grossPay * 0.06;
  93.  
  94. else if (strcmp(state, "CA") == 0)
  95. return grossPay * 0.07;
  96.  
  97. else return 0.0;
  98.  
  99.  
  100. }
  101.  
  102.  
  103. // Function to calculate gross pay
  104. float calcGross(float wage, float hours, float overtime) {
  105. return (hours > STD_HOURS)
  106. ? (STD_HOURS * wage) + (overtime * wage * OT_RATE)
  107. : hours * wage;
  108. }
  109.  
  110. printf("\n%-6s %-7s %-6s %-6s %-8s %-8s %-8s %-8s\n",
  111. "Clock#", "Wage", "Hours", " OT", " Gross", " State", " Fed", " Net");
  112. printf("-----------------------------------------------------------------\n");
  113.  
  114. // Display employee data
  115. for (int i = 0; i < SIZE; ++i) {
  116. employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
  117. employeeData[i].grossPay = calcGross(employeeData[i].wageRate,
  118. employeeData[i].hours, employeeData[i].overtimeHrs);
  119. employeeData[i].stateTax = calcStateTax(employeeData[i].taxState,
  120. employeeData[i].grossPay);
  121. employeeData[i].fedTax = calcFedTax(employeeData[i].grossPay);
  122. employeeData[i].netPay = calcNetPay(employeeData[i].grossPay,
  123. employeeData[i].stateTax, employeeData[i].fedTax
  124. );
  125.  
  126. printf("%06ld %7.2f %6.1f %6.1f %8.2f %8.2f %8.2f %8.2f\n",
  127. employeeData[i].clockNumber,
  128. employeeData[i].wageRate,
  129. employeeData[i].hours,
  130. employeeData[i].overtimeHrs,
  131. employeeData[i].grossPay,
  132. employeeData[i].stateTax,
  133. employeeData[i].fedTax,
  134. employeeData[i].netPay);
  135.  
  136.  
  137. };
  138.  
  139. return 0;
  140.  
  141.  
  142. }
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Clock#  Wage    Hours    OT    Gross     State     Fed     Net   
-----------------------------------------------------------------
098401   10.60   51.0   11.0   598.90    29.95    89.84   479.12
526488    9.75   42.5    2.5   426.56    29.86    63.98   332.72
765349   10.50   37.0    0.0   388.50    23.31    58.28   306.92
034645   12.25   45.0    5.0   581.88     0.00    87.28   494.59
127615    8.25    0.0    0.0     0.00     0.00     0.00     0.00