Question

The program calculates a tax rate and tax to pay given an annual salary. The program...

The program calculates a tax rate and tax to pay given an annual salary. The program uses a class, TaxTableTools, which has the tax table built in. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay.

The output should be as follows:

Enter annual salary (-1 to exit):

10000

Annual Salary: 10000 Tax rate: 0.1 Tax to pay: 1000

Enter annual salary (-1 to exit):

50000

Annual Salary: 50000 Tax rate: 0.2 Tax to pay: 10000

Enter annual salary (-1 to exit):

50001

Annual Salary: 50001 Tax rate: 0.3 Tax to pay: 15000

Enter annual salary (-1 to exit):

100001

Annual Salary: 100001 Tax rate: 0.4 Tax to pay: 40000

Enter annual salary (-1 to exit): -1

1. Overload the constructor.

2. Add to the TaxTableTools class an overloaded constructor that accepts the base salary table and corresponding tax rate table as parameters.

3. Modify the main function to call the overloaded constructor with the two tables (vectors) provided in the main function. Be sure to set the nEntries value, too.

4. Note that the tables in the main function are different than the tables in the TaxTableTools class.

The updated output should be as follows:

Enter annual salary (-1 to exit):

10000

Annual Salary: 10000 Tax rate: 0.2 Tax to pay: 2000

Enter annual salary (-1 to exit):

50000

Annual Salary: 50000 Tax rate: 0.6 Tax to pay: 30000

Enter annual salary (-1 to exit):

50001

Annual Salary: 50001 Tax rate: 0.6 Tax to pay: 30000

Enter annual salary (-1 to exit):

1000001

Annual Salary: 1000001 Tax rate: 0.8 Tax to pay: 800000

Enter annual salary (-1 to exit): -1

main.cpp

#include
#include
#include
#include
#include "TaxTableTools.h"
#include "TaxTableTools.cpp"
using namespace std;

int main() {
const string PROMPT_SALARY = "\nEnter annual salary (-1 to exit)";
int annualSalary;
double taxRate;
int taxToPay;
vector salaryBase(5);
vector taxBase(5);

salaryBase.at(0) = 0;
salaryBase.at(1) = 10000;
salaryBase.at(2) = 40000;
salaryBase.at(3) = 80000;
salaryBase.at(4) = numeric_limits::max();

taxBase.at(0) = 0.0;
taxBase.at(1) = 0.20;
taxBase.at(2) = 0.40;
taxBase.at(3) = 0.60;
taxBase.at(4) = 0.80;

// FIXME: Use the overloaded constructor with the two tables.
TaxTableTools table;

// Get the first annual salary to process
annualSalary = table.GetInteger(PROMPT_SALARY);

while(annualSalary >= 0) {
taxRate = table.GetValue(annualSalary);
taxToPay = static_cast(annualSalary * taxRate); // Truncate tax to an integer amount
cout << "Annual Salary: " << annualSalary <<
"\tTax rate: " << taxRate <<
"\tTax to pay: " << taxToPay << endl;

// Get the next annual salary
annualSalary = table.GetInteger(PROMPT_SALARY);
}

return 0;
}

TaxTableTools.cpp

#include
#include
#include
#include "TaxTableTools.h"
using namespace std;

// Default constructor
TaxTableTools::TaxTableTools() {
search.push_back(0);
search.push_back(20000);
search.push_back(50000);
search.push_back(100000);
search.push_back(numeric_limits::max());
value.push_back(0.0);
value.push_back(0.10);
value.push_back(0.20);
value.push_back(0.30);
value.push_back(0.40);
nEntries = search.size(); // Set the length of the search table
}

// *************************************************************************

// Overloaded constructor

// FIXME: Add an overloaded constructor to load the search and value tables.
// FIXME: Be sure to set the nEntries value, too.
// Hint: Don't forget to change the header file too.

// **************************************************************************

// Function to prompt for and input an integer
int TaxTableTools::GetInteger(const string userPompt) {
int inputValue;

cout << userPompt << ": " << endl;
cin >> inputValue;

return inputValue;
}

// **************************************************************************

// Function to get a value from one table based on a range in the other table

double TaxTableTools::GetValue(int searchArgument) {
double result;
bool keepLooking;
int i;

keepLooking = true;
i = 0;

while ((i < nEntries) && keepLooking) {
if (searchArgument <= search[i]) {
result = value[i];
keepLooking = false;
}
else {
++i;
}
}

return result;
}

TaxTableTools.h

#ifndef TAXTABLETOOLS_H
#define TAXTABLETOOLS_H

#include
#include
#include
using namespace std;

class TaxTableTools {
public:
TaxTableTools();
double GetValue(int searchArgument);
int GetInteger(const string userPompt);
private:
vector search;
vector value;
int nEntries;
};

#endif

0 0
Add a comment Improve this question Transcribed image text
Answer #1

TaxTableTools.h

#ifndef TAXTABLETOOLS_H
#define TAXTABLETOOLS_H
#include<vector>

using namespace std;

class TaxTableTools {
   public:
       TaxTableTools();
       TaxTableTools(vector<int> search, vector<float> value);
       double GetValue(int searchArgument);
       int GetInteger(const string userPompt);
   private:
       vector<int> search;
       vector<float> value;
       int nEntries;
};

#endif

TaxTableTools.cpp

#include<vector>
#include<limits>
#include "TaxTableTools.h"
using namespace std;

TaxTableTools::TaxTableTools() {
   search.push_back(0);
   search.push_back(20000);
   search.push_back(50000);
   search.push_back(100000);
   search.push_back(std::numeric_limits<int>::max());
   value.push_back(0.0);
   value.push_back(0.10);
   value.push_back(0.20);
   value.push_back(0.30);
   value.push_back(0.40);
   nEntries = search.size();
}

/**
   overloaded constructor
   @params:   vector<int> search : contains search value for base salary
               vector<float> value : contains tax rate on corresponding base salary
   @compute:    set search vector and value vector and nEntries of this object
**/
TaxTableTools::TaxTableTools(vector<int> search, vector<float> value)
{
   for(int i=0; i<search.size(); i++)
   {
       this->search.push_back(search[i]);
   }
   for(int i=0; i<value.size(); i++)
   {
       this->value.push_back(value[i]);
   }
   nEntries=this->search.size();
}

int TaxTableTools::GetInteger(const string userPompt) {
   int inputValue;
   cout << userPompt << ": " << endl;
   cin >> inputValue;
   return inputValue;
}

double TaxTableTools::GetValue(int searchArgument) {
   double result;
   bool keepLooking;
   int i;

   keepLooking = true;
   i = 0;

   while ((i < nEntries) && keepLooking)
   {
       if (searchArgument <= search[i])
       {
           result = value[i];
           keepLooking = false;
       }
       else
       {
           ++i;
       }
   }

   return result;
}

main.cpp

#include<iostream>
#include<vector>
#include<limits>
#include "TaxTableTools.h"
#include "TaxTableTools.cpp"
using namespace std;

int main() {
   const string PROMPT_SALARY = "\nEnter annual salary (-1 to exit)";
   int annualSalary;
   double taxRate;
   int taxToPay;
   vector<int> salaryBase(5);
   vector<float> taxBase(5);

   salaryBase.at(0) = 0;
   salaryBase.at(1) = 10000;
   salaryBase.at(2) = 40000;
   salaryBase.at(3) = 80000;
   salaryBase.at(4) = numeric_limits<int>::max();

   taxBase.at(0) = 0.0;
   taxBase.at(1) = 0.20;
   taxBase.at(2) = 0.40;
   taxBase.at(3) = 0.60;
   taxBase.at(4) = 0.80;

   TaxTableTools table(salaryBase, taxBase);
   annualSalary = table.GetInteger(PROMPT_SALARY);

   while(annualSalary >= 0) {
       taxRate = table.GetValue(annualSalary);
       taxToPay = static_cast<int>(annualSalary * taxRate);
       cout << "Annual Salary: " << annualSalary <<
       "\tTax rate: " << taxRate <<
       "\tTax to pay: " << taxToPay << endl;

       annualSalary = table.GetInteger(PROMPT_SALARY);
   }

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
The program calculates a tax rate and tax to pay given an annual salary. The program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write Java program ( see IncomeTaxOverloadClassTemplate) calculates a tax rate and tax to pay given an...

    Write Java program ( see IncomeTaxOverloadClassTemplate) calculates a tax rate and tax to pay given an annual salary. The program uses a class,(see TaxTableToolsOverloadTemplate), which has the tax table built in. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. Overload the constructor. Add to the TaxTableTools class an overloaded constructor that accepts the base salary table and corresponding tax rate table...

  • Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in....

    Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in. The main method prompts for a salary, then uses a TaxTableTools method to get the tax rate. The program then calculates the tax to pay and displays the results to the user. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. a. Modify the TaxTableTools class...

  • Separating calculations into methods simplifies modifying and expanding programs. The following program calculates the tax rate...

    Separating calculations into methods simplifies modifying and expanding programs. The following program calculates the tax rate and tax to pay, using methods. One method returns a tax rate based on an annual salary. Run the program below with annual salaries of 40000, 60000, and 0. Change the program to use a method to input the annual salary. Run the program again with the same annual salaries as above. Are results the same? This is the code including what I am...

  • Write a program that will compute the user annual salary. Prompt the user the enter (1)...

    Write a program that will compute the user annual salary. Prompt the user the enter (1) the weekly salary. Store the information in a double variable. Prompt the user to enter the number of weeks worked in a year. Use an int variable for that. Write code that will compute the user's Annual salary. Gross salary is salary before any deductions are taken. Update the code and prompt the user to enter the federal tax rate and the state's tax...

  • This C++ program will not let me put numbers in on address, just characters #include using namespace std; float paycalc(){ cout<<"Enter 1 if salary and 2 if hourly: "; int choice, hoursW...

    This C++ program will not let me put numbers in on address, just characters #include using namespace std; float paycalc(){ cout<<"Enter 1 if salary and 2 if hourly: "; int choice, hoursWorked, payrate; float salary; cin>>choice; if(choice == 1){ cout<<"Enter your salary per month: "; cin>>salary; }else{ cout<<"Enter hours worked: "; cin>>hoursWorked; cout<<"Enter pay rate: "; cin>>payrate; salary = hoursWorked * payrate; } return salary; } void printCheck(float sal, int id, char address[30]){ cout<<"Employee id: "<>id; cout<<"Enter address: "; char...

  • This is C++. The task is to convert the program to make use of fucntions, but...

    This is C++. The task is to convert the program to make use of fucntions, but I am am struggling to figure out how to do so. #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ];    char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ]; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID,...

  • 2-2 You borrow $20,000 at an annual interest rate of 8%. You will pay the loan...

    2-2 You borrow $20,000 at an annual interest rate of 8%. You will pay the loan back in two equal payments at the end of year 1 and year 4. a. Calculate the amount to be paid each year using the factor tables. b. Draw the fully labeled cash flow diagram. c. Complete the following table: BOY alanceamount BOY+Interest)Payment Interest Total Balance f) 3 4

  • Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...

    Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT