The creation of a simple hierarchy of classes along with the implementation and
ID: 3771170 • Letter: T
Question
The creation of a simple hierarchy of classes along with the implementation and use of inheritance.
CODE: LEVEL 1: Taxpayer
Level 2: WeeklyTaxpayer BiweeklyTaxpayer MonthlyTaxpayer
The program should create instances of the WeeklyTaxPayer,BiweeklyTaxPayer, and MonthlyTaxpayer classes, which are described below. The program should not create instances of the Taxpayer class. The client should work correctly for all subclasses
THE FOLLOWING CLASS (BIWEEKLY) HAS BEEN COMPLETED,YOU ARE TO CREATE
THE WEEKLY AND MONTHLY TAXPAYERS IN A SIMILAR FASHION
Create a new class, called BiweeklyTaxpayer, that is a subclass of Taxpayer.This new class must be in a separate file with the same name as the class.The BiweeklyTaxpayer class must inherit all the member variables of the Taxpayer class.Do not declare any member variables in the BiweeklyTaxpayer class. The BiweeklyTaxpayer class must have a public constructor that takes a value for each of the inherited member variables as parameter.
The inherited variables are: name,SSN number,and gross pay.
The constructor must invoke the constructor of the parent class to initialize the variables. The BiweeklyTaxpayer class must have a public computeStateTax member function that calculates tax by the rules provided below.
For each type of Taxpayer use the following NYS rates
1
0.0400
2
0.0450
3
0.0525
4
0.0590
5
0.0685
6
0.0764
7
0.0814
8
0.0935
See example for computing NYS tax after the monthly calculation.
Example for NYS tax calculation:If the gross pay is $700 and monthly,find where it fits in the table.This would be row 2 (667 to 917).Subtract the amount 667 from the gross pay. This is the adjusted pay(33).Multiply the adjusted pay by the corresponding rate found in row 2 of the NYS rates(0.0450).Now add the amount 26.27 to that product(26.27+1.485).This the NYS tax,27.76.
Modification One:
Implement the member function for Biweekly state tax calculation: Write the code for the member function named computeStateTax()
Calculate tax as follows:
Compute The State Tax to beWithHeld
Gross Wages at Least
But Less Than
Subtract This Amount From Net Wages
Multiply The Result by Corresponding Rates and Add The result to the Following.Then Withhold The Sum
1
0
308
0
0
2
308
423
308
12.31
3
423
500
423
17.50
4
500
769
500
21.54
5
769
3462
769
37.42
6
3462
3846
3462
221.85
7
3846
5769
3846
251.23
8
5769
…....
5769
407.85
Modification Two:
Implement the member functions for Weekly State tax calculation. Write the code for the member function named computeStateTax()
Calculate tax as follows:
WEEKLY PAYROLL
Compute The State Tax to beWithHeld
Gross Wages at Least
But Less Than
Subtract This Amount From Net Wages
Multiply The Result by Corresponding Rates and Add The result to the Following.Then Withhold The Sum
1
0
154
0
0
2
154
212
154
6.15
3
212
250
212
8.75
4
250
385
250
10.77
5
385
1731
385
18.71
6
1731
1923
1731
110.92
7
1923
2885
1923
125.62
8
2885
…....
2885
203.92
Modification Three:
Implement the member function for Monthly Tax calculation: Write the code for the following member function named computeStateTax()
Calculate tax as follows:
MONTHLY PAYROLL
Compute The State Tax to beWithHeld
Gross Wages at Least
But Less Than
Subtract This Amount From Net Wages
Multiply The Result by Corresponding Rates and Add The result to the Following.Then Withhold The Sum
1
0
667
0
0
2
667
917
667
26.27
3
917
1083
917
37.92
4
1083
1667
1083
46.67
5
1667
7500
1667
81.08
6
7500
8333
7500
480.67
7
8333
12500
8333
544.33
8
12500
…......
12500
883.67
Example for NYS tax calculation: If the gross pay is $700 and monthly, find where it fits in the table
This would be row 2(667 to917).
Subtract the amount 667 from the gross pay. This is the adjusted pay.Multiply the adjusted pay by the corresponding rate found in row 2 of the NYS rates(0.0450).Now add the amount 26.27 to that product(26.27+1.485)
This is the NYS tax,27.76
MODIFICATION Four
Add the computeFederalTax member function for ALL the classes. Write the code for the member function named computeFederalTax() member function of the existing program classes.The member function must calculate tax as follows:(see example after tables)
CORRESPONDING FEDERAL RATES
1
0%
2
10%
3
15%
4
25%
5
28%
6
33%
7
35%
FEDERAL
Wages-Withholding Allowance is More Than
But Not Over
Add Amount Below To
Corresponding Percentage of Excess Over
1
0
51
0
0
2
51
195
0
51
3
195
645
14.40
195
4
645
1482
81.90
645
5
1482
3131
291.15
1482
6
3131
6763
752.87
3131
7
6753
….....
1951.43
6763
FEDERAL WITHHOLDING ALLOWANCE
ALLOW ONLY ONE AMOUNT
PAYROLL PERIOD
WITHHOLDING ALLOWANCE
WEEKLY
65.38
BIWEEKLY
130.77
MONTHLY
283.33
Example for Federal tax calculation: If the gross pay is $700 and monthly, then subtract the monthly allowance of 283.33 from the gross pay.Take this adjusted pay,416.67 and find where it fits into the table under? wages?allowance? This would be row 3(195 to 645).The corresponding rate is then row 3 in the rate table at 15%. Adjust pay again by subtracting (row 3 column 5) 195(416.67-195). Take 15% of the adjusted pay(221.67) and add $14.40 to the amount.(33.25+14.40=47.65)
This is your Federal Tax.
Example for NYS Tax Calculation: If the gross pay is $700 and biweekly.
Find where it fits in the table.
This would be row 4(500 to769). Subtract the amount 500(row 4 col 4) from gross pay.This is the adjusted pay(200). Multiply the adjusted pay by the corresponding rate found in row 4 of the NYS rates (0.0590).
Now add the amount 21.54 to that product(11.80+21.54). This is the NYS tax, 33.34 Note that you always work from row 4 once you have determined that is where the gross pay fits in the table.
The BiweeklyTaxpayer class must have a public computeFederalTax member function that calculates tax by the rules provided above.
Example for Federal tax calculation: If the gross pay is $700 and biweekly, then subtract the biweekly allowance of 130.77 form the gross pay. Take this adjusted pay,569.23 and find where it fits into the table under wages allowance. This would be row 3(195 to 645). Adjust pay again by subtracting (row 3 column 5) 195 (569.23-195). The corresponding rate is then on row 3 in the rate table at 15%. Take 15% of the adjusted pay(374.23) and add $14.40 to the amount (56.13+14.40=70.53).This is your federal tax. Note that you always work from row 3 once you have determined that is where the gross pay minus the exemption fits in the table
C++ project
1
0.0400
2
0.0450
3
0.0525
4
0.0590
5
0.0685
6
0.0764
7
0.0814
8
0.0935
Explanation / Answer
Here you go
1. Taxpayer class
#include <string>
#include <vector>
namespace chegg_taxPay
{
class TaxPayer
{
public:
std::wstring name;
int ssn = 0;
int grossPay = 0;
//JAVA TO C++ CONVERTER TODO TASK: Native C++ does not allow initialization of static non-const/integral fields in their declarations:
static std::vector<double> nysTax = {0.0400, 0.0450, 0.0525, 0.0590, 0.0685, 0.0764, 0.0814, 0.0935};
TaxPayer(const std::wstring &name, int ssn, int gross)
{
this->name = name;
this->ssn = ssn;
this->grossPay = gross;
}
};
}
2. BiweeklyTaxpayer
#include <string>
namespace chegg_taxPay
{
class BiweeklyTaxpayer : public TaxPayer
{
public:
BiweeklyTaxpayer(const std::wstring &name, int ssn, int gross) : TaxPayer(name, ssn, gross)
{
}
virtual double computeStateTax(int gross)
{
double totalTax = 0.0;
if (gross < 308)
{
totalTax = 0.0;
}
else if (gross < 423)
{
int net = gross - 308;
totalTax = 12.31 + TaxPayer::nysTax[1]*net;
}
else if (gross < 500)
{
int net = gross - 423;
totalTax = 17.50 + TaxPayer::nysTax[2]*net;
}
else if (gross < 769)
{
int net = gross - 500;
totalTax = 21.54 + TaxPayer::nysTax[3]*net;
}
else if (gross < 3462)
{
int net = gross - 769;
totalTax = 37.42 + TaxPayer::nysTax[4]*net;
}
else if (gross < 3846)
{
int net = gross - 3462;
totalTax = 221.85 + TaxPayer::nysTax[5]*net;
}
else if (gross < 5769)
{
int net = gross - 3846;
totalTax = 251.23 + TaxPayer::nysTax[6]*net;
}
else
{
int net = gross - 5769;
totalTax = 407.85 + TaxPayer::nysTax[7]*net;
}
return totalTax;
}
};
}
3. WeeklyTaxpayer
#include <string>
namespace chegg_taxPay
{
class WeeklyTaxpayer : public TaxPayer
{
public:
WeeklyTaxpayer(const std::wstring &name, int ssn, int gross) : TaxPayer(name, ssn, gross)
{
}
virtual double computeStateTax(int gross)
{
double totalTax = 0.0;
if (gross < 154)
{
totalTax = 0.0;
}
else if (gross < 212)
{
int net = gross - 154;
totalTax = 6.15 + TaxPayer::nysTax[1]*net;
}
else if (gross < 250)
{
int net = gross - 212;
totalTax = 8.75 + TaxPayer::nysTax[2]*net;
}
else if (gross < 385)
{
int net = gross - 250;
totalTax = 10.77 + TaxPayer::nysTax[3]*net;
}
else if (gross < 1731)
{
int net = gross - 385;
totalTax = 18.71 + TaxPayer::nysTax[4]*net;
}
else if (gross < 1923)
{
int net = gross - 1731;
totalTax = 110.92 + TaxPayer::nysTax[5]*net;
}
else if (gross < 2885)
{
int net = gross - 1923;
totalTax = 125.62 + TaxPayer::nysTax[6]*net;
}
else
{
int net = gross - 2885;
totalTax = 203.92 + TaxPayer::nysTax[7]*net;
}
return totalTax;
}
};
}
4. MonthlyTaxpayer
#include <string>
namespace chegg_taxPay
{
class MonthlyTaxpayer : public TaxPayer
{
public:
MonthlyTaxpayer(const std::wstring &name, int ssn, int gross) : TaxPayer(name, ssn, gross)
{
}
virtual double computeStateTax(int gross)
{
double totalTax = 0.0;
if (gross < 667)
{
totalTax = 0.0;
}
else if (gross < 917)
{
int net = gross - 667;
totalTax = 6.15 + TaxPayer::nysTax[1]*net;
}
else if (gross < 1083)
{
int net = gross - 917;
totalTax = 8.75 + TaxPayer::nysTax[2]*net;
}
else if (gross < 1667)
{
int net = gross - 1083;
totalTax = 10.77 + TaxPayer::nysTax[3]*net;
}
else if (gross < 7500)
{
int net = gross - 1667;
totalTax = 18.71 + TaxPayer::nysTax[4]*net;
}
else if (gross < 8333)
{
int net = gross - 7500;
totalTax = 110.92 + TaxPayer::nysTax[5]*net;
}
else if (gross < 12500)
{
int net = gross - 8333;
totalTax = 125.62 + TaxPayer::nysTax[6]*net;
}
else
{
int net = gross - 12500;
totalTax = 203.92 + TaxPayer::nysTax[7]*net;
}
return totalTax;
}
};
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.