Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The creation of a simple hierarchy of classes along with the implementation and

ID: 3771185 • 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

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:

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

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

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

Subtract This Amount From Net Wages

Multiply The Result by Corresponding Rates and Add The result to the Following.Then Withhold The Sum

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

FEDERAL

FEDERAL WITHHOLDING ALLOWANCE

ALLOW ONLY ONE AMOUNT

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

TaxPayer.h

#pragma once
#include<string>
using namespace std;
class TaxPayer
{
public:
   TaxPayer(string tname, string tSSN, double pay);
   virtual ~TaxPayer();
  
   string name;
   string SSN;
   double grossPay;

   //Made them pure virtual functions so that object of TaxPayer cannot be created and
   //any class inheriting from it need to implement these functions
   //If you want to use the pointer of base class for calling derived class functions
   //Make them just virtual by removing the =0 from them and give the a base implementation in
   //TaxPayer.cpp
   virtual double computeStateTax()=0;
   virtual double computeFederalTax()=0;

};

TaxPayer.cpp

#include "TaxPayer.h"


TaxPayer::TaxPayer(string tname, string tSSN, double pay) :name(tname), SSN(tSSN), grossPay(pay)
{

}


TaxPayer::~TaxPayer()
{
}

BiWeeklyTaxPayer.h

#pragma once
#include "TaxPayer.h"
class BiWeeklyTaxPayer :public TaxPayer
{
public:
   BiWeeklyTaxPayer(string tname,string tSSN,double pay);
   ~BiWeeklyTaxPayer();

   double computeStateTax();
   double computeFederalTax();
};

BiWeeklyTaxPayer.cpp

#include "BiWeeklyTaxPayer.h"


BiWeeklyTaxPayer::BiWeeklyTaxPayer(string tname, string tSSN, double pay) :TaxPayer(tname,tSSN,pay)
{
}


BiWeeklyTaxPayer::~BiWeeklyTaxPayer()
{
}

double BiWeeklyTaxPayer::computeStateTax()
{
   double stateTax = 0;

   if (grossPay >= 0 && grossPay < 308)
   {
       stateTax = grossPay*0.0400;
   }
   else if (grossPay >= 308 && grossPay < 423)
   {
       stateTax = (grossPay - 308)*0.0450 + 12.31;
   }
   else if (grossPay >= 423 && grossPay < 500)
   {
       stateTax = (grossPay - 423)*0.0525 + 17.50;
   }
   else if (grossPay >= 500 && grossPay < 769)
   {
       stateTax = (grossPay - 500)*0.0590 + 21.54;
   }
   else if (grossPay >= 769 && grossPay < 3462)
   {
       stateTax = (grossPay - 769)*0.0685 + 37.42;
   }
   else if (grossPay >= 3462 && grossPay < 3846)
   {
       stateTax = (grossPay - 3462)*0.0764 + 221.85;
   }
   else if (grossPay >= 3846 && grossPay <5769)
   {
       stateTax = (grossPay - 3846)*0.0814 + 251.23;
   }
   else if (grossPay >= 5769)
   {
       stateTax = (grossPay - 5769)*0.0935 + 407.85;
   }

   return stateTax;
}

double BiWeeklyTaxPayer::computeFederalTax()
{
   double federealTax = 0;
  
   double allowance = 130.77;

   double pay = grossPay - allowance;

   if (pay>0 && pay < 51)
   {
       federealTax = 0;
   }
   else if (pay >= 51 && pay < 195)
   {
       federealTax = pay*0.1;
   }
   else if (pay >= 195 && pay < 645)
   {
       federealTax = (pay - 195)*0.15 + 14.40;
   }
   else if (pay >= 645 && pay < 1482)
   {
       federealTax = (pay - 645)*0.25 + 81.90;
   }
   else if (pay >= 1482 && pay < 3131)
   {
       federealTax = (pay - 1482)*0.28 + 291.15;
   }
   else if (pay >= 3131 && pay < 6763)
   {
       federealTax = (pay - 3131)*0.33 + 752.87;
   }
   else if (pay >= 6763)
   {
       federealTax = (pay - 6763)*0.35 + 1951.43;
   }

   return federealTax;
}

WeeklyTaxPayer.h

#pragma once
#include "TaxPayer.h"
class WeeklyTaxPayer:public TaxPayer
{
public:
   WeeklyTaxPayer(string tname,string tSSN,double pay);
   ~WeeklyTaxPayer();

   double computeStateTax();
   double computeFederalTax();
};

WeeklyTaxPayer.cpp

#include "WeeklyTaxPayer.h"


WeeklyTaxPayer::WeeklyTaxPayer(string tname, string tSSN, double pay) :TaxPayer(tname, tSSN, pay)
{
}


WeeklyTaxPayer::~WeeklyTaxPayer()
{
}

double WeeklyTaxPayer::computeStateTax()
{
   double stateTax = 0;

   if (grossPay >= 0 && grossPay < 154)
   {
       stateTax = grossPay*0.0400;
   }
   else if (grossPay >= 154 && grossPay < 212)
   {
       stateTax = (grossPay - 154)*0.0450 + 6.15;
   }
   else if (grossPay >= 212 && grossPay < 250)
   {
       stateTax = (grossPay - 212)*0.0525 + 8.75;
   }
   else if (grossPay >= 250 && grossPay < 385)
   {
       stateTax = (grossPay - 250)*0.0590 + 10.77;
   }
   else if (grossPay >= 385 && grossPay < 1731)
   {
       stateTax = (grossPay - 385)*0.0685 + 18.71;
   }
   else if (grossPay >= 1731 && grossPay < 1923)
   {
       stateTax = (grossPay - 3462)*0.0764 + 110.92;
   }
   else if (grossPay >= 1923 && grossPay <2885)
   {
       stateTax = (grossPay - 1923)*0.0814 + 125.62;
   }
   else if (grossPay >= 2885)
   {
       stateTax = (grossPay - 5769)*0.0935 + 203.92;
   }

   return stateTax;
}

double WeeklyTaxPayer::computeFederalTax()
{
   double federealTax = 0;

   double allowance = 65.38;

   double pay = grossPay - allowance;

   if (pay>0 && pay < 51)
   {
       federealTax = 0;
   }
   else if (pay >= 51 && pay < 195)
   {
       federealTax = pay*0.1;
   }
   else if (pay >= 195 && pay < 645)
   {
       federealTax = (pay - 195)*0.15 + 14.40;
   }
   else if (pay >= 645 && pay < 1482)
   {
       federealTax = (pay - 645)*0.25 + 81.90;
   }
   else if (pay >= 1482 && pay < 3131)
   {
       federealTax = (pay - 1482)*0.28 + 291.15;
   }
   else if (pay >= 3131 && pay < 6763)
   {
       federealTax = (pay - 3131)*0.33 + 752.87;
   }
   else if (pay >= 6763)
   {
       federealTax = (pay - 6763)*0.35 + 1951.43;
   }

   return federealTax;
}

MonthlyTaxPayer.h

#pragma once
#include "TaxPayer.h"
class MonthlyTaxPayer:public TaxPayer
{
public:
   MonthlyTaxPayer(string tname,string tSSN,double pay);
   ~MonthlyTaxPayer();
   double computeStateTax();
   double computeFederalTax();
};

MonthlyTaxPayer.cpp

#include "MonthlyTaxPayer.h"


MonthlyTaxPayer::MonthlyTaxPayer(string tname, string tSSN, double pay) :TaxPayer(tname,tSSN,pay)
{
}


MonthlyTaxPayer::~MonthlyTaxPayer()
{
}

double MonthlyTaxPayer::computeStateTax()
{
   double stateTax = 0;

   if (grossPay >= 0 && grossPay < 667)
   {
       stateTax = grossPay*0.0400;
   }
   else if (grossPay >= 667 && grossPay < 917)
   {
       stateTax = (grossPay - 667)*0.0450 + 26.27;
   }
   else if (grossPay >= 917 && grossPay < 1083)
   {
       stateTax = (grossPay - 917)*0.0525 + 37.92;
   }
   else if (grossPay >= 1083 && grossPay < 1667)
   {
       stateTax = (grossPay - 1083)*0.0590 + 46.67;
   }
   else if (grossPay >= 1667 && grossPay < 7500)
   {
       stateTax = (grossPay - 1667)*0.0685 + 81.08;
   }
   else if (grossPay >= 7500 && grossPay < 8333)
   {
       stateTax = (grossPay - 7500)*0.0764 + 480.67;
   }
   else if (grossPay >= 8333 && grossPay < 12500)
   {
       stateTax = (grossPay - 8333)*0.0814 + 544.33;
   }
   else if (grossPay >= 12500)
   {
       stateTax = (grossPay - 12500)*0.0935 + 883.67;
   }

   return stateTax;
}

double MonthlyTaxPayer::computeFederalTax()
{
   double federealTax = 0;

   double allowance = 283.33;

   double pay = grossPay - allowance;

   if (pay>0 && pay < 51)
   {
       federealTax = 0;
   }
   else if (pay >= 51 && pay < 195)
   {
       federealTax = pay*0.1;
   }
   else if (pay >= 195 && pay < 645)
   {
       federealTax = (pay - 195)*0.15 + 14.40;
   }
   else if (pay >= 645 && pay < 1482)
   {
       federealTax = (pay - 645)*0.25 + 81.90;
   }
   else if (pay >= 1482 && pay < 3131)
   {
       federealTax = (pay - 1482)*0.28 + 291.15;
   }
   else if (pay >= 3131 && pay < 6763)
   {
       federealTax = (pay - 3131)*0.33 + 752.87;
   }
   else if (pay >= 6763)
   {
       federealTax = (pay - 6763)*0.35 + 1951.43;
   }

   return federealTax;
}

Main.cpp (To test all the TaxPayer classes)

#include<iostream>
#include "BiWeeklyTaxPayer.h"
#include "WeeklyTaxPayer.h"
#include "MonthlyTaxPayer.h"
using namespace std;

int main()
{
   BiWeeklyTaxPayer b("Jhon", "1554252", 700);

   cout << "State Tax for Jhon is: $" << b.computeStateTax() << endl;

   cout << "Federal Tax for Jhon is: $" << b.computeFederalTax() << endl;

   MonthlyTaxPayer m("Ross", "1554252", 700);

   cout << "State Tax for Ross is: $" << m.computeStateTax() << endl;

   cout << "Federal Tax for Ross is: $" << m.computeFederalTax() << endl;

   WeeklyTaxPayer w("Jerry", "1554252", 700);

   cout << "State Tax for Jerry is: $" << w.computeStateTax() << endl;

   cout << "Federal Tax for Jerry is: $" << w.computeFederalTax() << endl;

   system("pause");
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote