fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: John Semenuk
  6. // Class: C Programming, Spring 2026
  7. // Date: April 27, 2026
  8. //
  9. //********************************************************
  10.  
  11. #include <iostream>
  12. #include <iomanip>
  13. #include <string>
  14. #include <cctype>
  15.  
  16. using namespace std;
  17.  
  18. #define STD_HOURS 40.0
  19. #define OT_RATE 1.5
  20.  
  21. #define MA_TAX_RATE 0.05
  22. #define NH_TAX_RATE 0.0
  23. #define VT_TAX_RATE 0.06
  24. #define CA_TAX_RATE 0.07
  25. #define DEFAULT_TAX_RATE 0.08
  26.  
  27. #define FED_TAX_RATE 0.25
  28. #define EMP_SIZE 5
  29.  
  30.  
  31. class Employee
  32. {
  33. private:
  34. string firstName;
  35. string lastName;
  36. string taxState;
  37. int clockNumber;
  38. float wageRate;
  39. float hours;
  40.  
  41. float overTimeHrs;
  42. float grossPay;
  43. float stateTax;
  44. float fedTax;
  45. float netPay;
  46.  
  47. float calcOverTimeHrs();
  48. float calcGrossPay();
  49. float calcStateTax();
  50. float calcFedTax();
  51. float calcNetPay();
  52.  
  53. string getFirstName();
  54. string getLastName();
  55. string getTaxState();
  56. int getClockNumber();
  57. float getWageRate();
  58. float getHours();
  59. float getOverTimeHrs();
  60. float getGrossPay();
  61. float getStateTax();
  62. float getFedTax();
  63. float getNetPay();
  64.  
  65. public:
  66. Employee() {}
  67.  
  68. Employee(string f, string l, string s,
  69. int c, float w, float h);
  70.  
  71. ~Employee() {}
  72.  
  73. void printEmployee();
  74. };
  75.  
  76. // ================= GETTERS =================
  77. inline string Employee::getFirstName() { return firstName; }
  78. inline string Employee::getLastName() { return lastName; }
  79. inline string Employee::getTaxState() { return taxState; }
  80. inline int Employee::getClockNumber() { return clockNumber; }
  81. inline float Employee::getWageRate() { return wageRate; }
  82. inline float Employee::getHours() { return hours; }
  83. inline float Employee::getOverTimeHrs() { return overTimeHrs; }
  84. inline float Employee::getGrossPay() { return grossPay; }
  85. inline float Employee::getStateTax() { return stateTax; }
  86. inline float Employee::getFedTax() { return fedTax; }
  87. inline float Employee::getNetPay() { return netPay; }
  88.  
  89. // ================= CALCULATIONS =================
  90. float Employee::calcOverTimeHrs()
  91. {
  92. overTimeHrs = (hours > STD_HOURS) ? hours - STD_HOURS : 0;
  93. return overTimeHrs;
  94. }
  95.  
  96. float Employee::calcGrossPay()
  97. {
  98. if (overTimeHrs > 0)
  99. grossPay = (STD_HOURS * wageRate) + (overTimeHrs * wageRate * OT_RATE);
  100. else
  101. grossPay = hours * wageRate;
  102.  
  103. return grossPay;
  104. }
  105.  
  106. float Employee::calcStateTax()
  107. {
  108. float rate;
  109.  
  110. if (taxState == "MA") rate = MA_TAX_RATE;
  111. else if (taxState == "VT") rate = VT_TAX_RATE;
  112. else if (taxState == "NH") rate = NH_TAX_RATE;
  113. else if (taxState == "CA") rate = CA_TAX_RATE;
  114. else rate = DEFAULT_TAX_RATE;
  115.  
  116. stateTax = grossPay * rate;
  117. return stateTax;
  118. }
  119.  
  120. float Employee::calcFedTax()
  121. {
  122. fedTax = grossPay * FED_TAX_RATE;
  123. return fedTax;
  124. }
  125.  
  126. float Employee::calcNetPay()
  127. {
  128. netPay = grossPay - stateTax - fedTax;
  129. return netPay;
  130. }
  131.  
  132. // ================= CONSTRUCTOR =================
  133. Employee::Employee(string f, string l, string s,
  134. int c, float w, float h)
  135. {
  136. firstName = f;
  137. lastName = l;
  138.  
  139. if (islower(s[0])) s[0] = toupper(s[0]);
  140. if (islower(s[1])) s[1] = toupper(s[1]);
  141. taxState = s;
  142.  
  143. clockNumber = c;
  144. wageRate = w;
  145. hours = h;
  146.  
  147. overTimeHrs = calcOverTimeHrs();
  148. grossPay = calcGrossPay();
  149. stateTax = calcStateTax();
  150. fedTax = calcFedTax();
  151. netPay = calcNetPay();
  152. }
  153.  
  154. // ================= PRINT =================
  155. void Employee::printEmployee()
  156. {
  157. cout << "\n\n*** Entered Details are ***\n";
  158. cout << "First Name: " << getFirstName() << endl;
  159. cout << "Last Name: " << getLastName() << endl;
  160. cout << "Tax State: " << getTaxState() << endl;
  161. cout << "Clock Number: " << getClockNumber() << endl;
  162. cout << "Wage Rate: " << getWageRate() << endl;
  163. cout << "Hours: " << getHours() << endl;
  164.  
  165. cout << "\n*** Calculated Values are ***\n";
  166. cout << "Overtime Hours : " << getOverTimeHrs() << endl;
  167. cout << "Gross Pay : $" << getGrossPay() << endl;
  168. cout << "State Tax : $" << getStateTax() << endl;
  169. cout << "Federal Tax : $" << getFedTax() << endl;
  170. cout << "Net Pay : $" << getNetPay() << endl;
  171. }
  172.  
  173. // ================= MAIN =================
  174. int main()
  175. {
  176. cout << fixed << setprecision(2);
  177.  
  178. Employee e[EMP_SIZE];
  179.  
  180. for (int i = 0; i < EMP_SIZE; i++)
  181. {
  182. string f, l, s;
  183. int c;
  184. float w, h;
  185.  
  186. cout << "\n\n Enter Employee First Name: " << endl;
  187. cin >> f;
  188.  
  189. cout << " Enter Employee Last Name: " << endl;
  190. cin >> l;
  191.  
  192. cout << " Enter Employee Tax State: " << endl;
  193. cin >> s;
  194.  
  195. cout << " Enter Employee Clock Number: " << endl;
  196. cin >> c;
  197.  
  198. cout << " Enter Employee Hourly Wage Rate: " << endl;
  199. cin >> w;
  200.  
  201. cout << " Enter Employee Hours Worked for the Week: " << endl;
  202. cin >> h;
  203.  
  204. e[i] = Employee(f, l, s, c, w, h);
  205. e[i].printEmployee();
  206. }
  207.  
  208. return 0;
  209. }
Success #stdin #stdout 0s 5324KB
stdin
Connie
Cobol
MA
98401
10.60
51.0
Mary
Apl
NH
526488
9.75
42.5
Frank
Fortran
VT
765349
10.50
37.0
Jeff
Ada
NY
34645
12.25
45
Anton
Pascal
CA
127615
8.35
40.0
stdout

 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 


*** Entered Details are ***
First Name: Connie
Last Name: Cobol
Tax State: MA
Clock Number: 98401
Wage Rate: 10.60
Hours: 51.00

*** Calculated Values are ***
Overtime Hours : 11.00
Gross Pay : $598.90
State Tax : $29.95
Federal Tax : $149.73
Net Pay : $419.23


 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 


*** Entered Details are ***
First Name: Mary
Last Name: Apl
Tax State: NH
Clock Number: 526488
Wage Rate: 9.75
Hours: 42.50

*** Calculated Values are ***
Overtime Hours : 2.50
Gross Pay : $426.56
State Tax : $0.00
Federal Tax : $106.64
Net Pay : $319.92


 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 


*** Entered Details are ***
First Name: Frank
Last Name: Fortran
Tax State: VT
Clock Number: 765349
Wage Rate: 10.50
Hours: 37.00

*** Calculated Values are ***
Overtime Hours : 0.00
Gross Pay : $388.50
State Tax : $23.31
Federal Tax : $97.12
Net Pay : $268.07


 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 


*** Entered Details are ***
First Name: Jeff
Last Name: Ada
Tax State: NY
Clock Number: 34645
Wage Rate: 12.25
Hours: 45.00

*** Calculated Values are ***
Overtime Hours : 5.00
Gross Pay : $581.88
State Tax : $46.55
Federal Tax : $145.47
Net Pay : $389.86


 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 


*** Entered Details are ***
First Name: Anton
Last Name: Pascal
Tax State: CA
Clock Number: 127615
Wage Rate: 8.35
Hours: 40.00

*** Calculated Values are ***
Overtime Hours : 0.00
Gross Pay : $334.00
State Tax : $23.38
Federal Tax : $83.50
Net Pay : $227.12