Question
Use C++ Modify the program to use two parallel vectors named annualSalaries and taxesToPay, each with 10 elements. Vectors annualSalaries holds up to 10 annual
Use C++
Modify the program to use two parallel vectors named annualSalaries and taxesToPay, each with 10 elements. Vectors annualSalaries holds up to 10 annual salaries entered; vector taxesToPay holds up to 10 corresponding amounts of taxes to pay for those annual salaries. Print the total annual salaries and taxes to pay after all input has been processed.
The following program calculates the tax rate and tax to pay based on annual income.
Starter code:
#include
#include
using namespace std;
int main() {
const int MAX_ELEMENTS = 10;
int annualSalary = 0;
double taxRate = 0.0;
int taxToPay = 0;
int numSalaries = 0;
bool keepLooking = true;
int i = 0;
vector
vector
salaryBase.at(0) = 0;
salaryBase.at(1) = 20000;
salaryBase.at(2) = 50000;
salaryBase.at(3) = 100000;
salaryBase.at(4) = 99999999;
taxBase.at(0) = 0.0;
taxBase.at(1) = 0.10;
taxBase.at(2) = 0.20;
taxBase.at(3) = 0.30;
taxBase.at(4) = 0.40;
// FIXME: Define annualSalaries and taxesToPay vectors to hold 10 elements each.
// FIXME: Use the constant MAX_ELEMENTS to declare the vectors
cout << " Enter annual salary (0 to exit): " << endl;
cin >> annualSalary;
while (annualSalary > 0) {
i = 0;
keepLooking = true;
// Search for the appropriate table row for given annualSalary
while ((i < salaryBase.size()) && keepLooking) {
if (annualSalary <= salaryBase.at(i)) {
taxRate = taxBase.at(i);
keepLooking = false;
}
else {
++i;
}
} // End inner loop (search for appropriate table row)
taxToPay = static_cast
// FIXME: Insert code to include entries to the annual salaries and taxes to pay
// FIXME: tables. Replace the appropriate variables with the vector element.
cout << "Annual salary: " << annualSalary <<
"\tTax rate: " << taxRate <<
"\tTax to pay: " << taxToPay << endl;
// Get the next annual salary
cout << " Enter annual salary (0 to exit): " << endl;
cin >> annualSalary;
} // End outer while loop (valid annualSalary entered)
// FIXME: Challenge - add code to sum the annual salaries and taxes to pay
// and print the totals
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started