fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: John Nguyen
  6. //
  7. // Class: C Programming, Fall 2024
  8. //
  9. // Date: 12/1/2024
  10. //
  11. // Description: An object oriented program design using
  12. // C++ that will process our existing set of employees.
  13. // It utilizes a class called Employee and generates an
  14. // array of objects that are used to store, calculate,
  15. // and print out a simple report of inputted and calculated
  16. // values.
  17. //
  18. //
  19. // Object Oriented Design (using C++)
  20. //
  21. //********************************************************
  22.  
  23. #include <iomanip>
  24. #include <iostream>
  25. #include <string>
  26.  
  27. #define EMP_SIZE 5
  28. #define STD_HOURS 40.0
  29. #define OT_RATE 1.5
  30. #define MA_TAX_RATE 0.05
  31. #define NH_TAX_RATE 0.0
  32. #define VT_TAX_RATE 0.06
  33. #define CA_TAX_RATE 0.07
  34. #define DEFAULT_TAX_RATE 0.08
  35. #define FED_TAX_RATE 0.25
  36.  
  37. using namespace std;
  38.  
  39. class Employee {
  40. private:
  41. string firstName;
  42. string lastName;
  43. string taxState;
  44. int clockNumber;
  45. float wageRate;
  46. float hours;
  47. float overTimeHrs;
  48. float grossPay;
  49. float stateTax;
  50. float fedTax;
  51. float netPay;
  52.  
  53. // Calculate overtime hours
  54. float calcOverTimeHrs() {
  55. return (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
  56. }
  57.  
  58. // Calculate gross pay
  59. float calcGrossPay() {
  60. if (overTimeHrs > 0) {
  61. return (STD_HOURS * wageRate) + (overTimeHrs * wageRate * OT_RATE);
  62. }
  63. return wageRate * hours;
  64. }
  65.  
  66. // Calculate state tax
  67. float calcStateTax() {
  68. float taxRate;
  69. if (taxState == "MA") taxRate = MA_TAX_RATE;
  70. else if (taxState == "NH") taxRate = NH_TAX_RATE;
  71. else if (taxState == "VT") taxRate = VT_TAX_RATE;
  72. else if (taxState == "CA") taxRate = CA_TAX_RATE;
  73. else taxRate = DEFAULT_TAX_RATE;
  74. return grossPay * taxRate;
  75. }
  76.  
  77. // Calculate federal tax
  78. float calcFedTax() {
  79. return grossPay * FED_TAX_RATE;
  80. }
  81.  
  82. // Calculate net pay
  83. float calcNetPay() {
  84. return grossPay - (stateTax + fedTax);
  85. }
  86.  
  87. public:
  88. Employee() : firstName(""), lastName(""), taxState(""), clockNumber(0), wageRate(0), hours(0) {}
  89.  
  90. Employee(string myFirstName, string myLastName, string myTaxState, int myClockNumber, float myWageRate, float myHours) {
  91. firstName = myFirstName;
  92. lastName = myLastName;
  93. taxState = myTaxState;
  94. clockNumber = myClockNumber;
  95. wageRate = myWageRate;
  96. hours = myHours;
  97.  
  98. overTimeHrs = calcOverTimeHrs();
  99. grossPay = calcGrossPay();
  100. stateTax = calcStateTax();
  101. fedTax = calcFedTax();
  102. netPay = calcNetPay();
  103. }
  104.  
  105. string getFirstName() { return firstName; }
  106. string getLastName() { return lastName; }
  107. string getTaxState() { return taxState; }
  108. int getClockNumber() { return clockNumber; }
  109. float getWageRate() { return wageRate; }
  110. float getHours() { return hours; }
  111. float getOverTimeHrs() { return overTimeHrs; }
  112. float getGrossPay() { return grossPay; }
  113. float getStateTax() { return stateTax; }
  114. float getFedTax() { return fedTax; }
  115. float getNetPay() { return netPay; }
  116.  
  117. void printEmployee() {
  118. cout << "\n\n *** Entered Details are *** \n";
  119. cout << "\n First Name: " << getFirstName();
  120. cout << "\n Last Name: " << getLastName();
  121. cout << "\n Tax State: " << getTaxState();
  122. cout << "\n Clock Number: " << getClockNumber();
  123. cout << "\n Wage Rate: $" << getWageRate();
  124. cout << "\n Hours: " << getHours();
  125. cout << "\n\n *** Calculated Values are *** \n";
  126. cout << "\n Overtime Hours : " << getOverTimeHrs();
  127. cout << "\n Gross Pay : $" << getGrossPay();
  128. cout << "\n State Tax : $" << getStateTax();
  129. cout << "\n Federal Tax : $" << getFedTax();
  130. cout << "\n Net Pay : $" << getNetPay();
  131. cout << "\n";
  132. }
  133. };
  134.  
  135. int main() {
  136. string myFirstName, myLastName, myTaxState;
  137. int myClockNumber;
  138. float myWageRate, myHours;
  139.  
  140. Employee e[EMP_SIZE];
  141.  
  142. for (int i = 0; i < EMP_SIZE; ++i) {
  143. cout << "\n\n Enter Employee First Name: ";
  144. cin >> myFirstName;
  145. cout << "\n Enter Employee Last Name: ";
  146. cin >> myLastName;
  147. cout << "\n Enter Employee Tax State: ";
  148. cin >> myTaxState;
  149. cout << "\n Enter Employee Clock Number: ";
  150. cin >> myClockNumber;
  151. cout << "\n Enter Employee Hourly Wage Rate: ";
  152. cin >> myWageRate;
  153. cout << "\n Enter Employee Hours Worked for the Week: ";
  154. cin >> myHours;
  155.  
  156. e[i] = {myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours};
  157. e[i].printEmployee();
  158. }
  159. return 0;
  160. }
  161.  
Success #stdin #stdout 0.01s 5288KB
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.6
 Hours: 51

 *** Calculated Values are *** 

 Overtime Hours : 11
 Gross Pay : $598.9
 State Tax : $29.945
 Federal Tax : $149.725
 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.5

 *** Calculated Values are *** 

 Overtime Hours : 2.5
 Gross Pay : $426.562
 State Tax : $0
 Federal Tax : $106.641
 Net Pay : $319.922


 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.5
 Hours: 37

 *** Calculated Values are *** 

 Overtime Hours : 0
 Gross Pay : $388.5
 State Tax : $23.31
 Federal Tax : $97.125
 Net Pay : $268.065


 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

 *** Calculated Values are *** 

 Overtime Hours : 5
 Gross Pay : $581.875
 State Tax : $46.55
 Federal Tax : $145.469
 Net Pay : $389.856


 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

 *** Calculated Values are *** 

 Overtime Hours : 0
 Gross Pay : $334
 State Tax : $23.38
 Federal Tax : $83.5
 Net Pay : $227.12