Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 salaryBase(5);

vector taxBase(5);

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(annualSalary * taxRate); // Truncate tax to an integer amount

// 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

What is meant by consumer surplus? How is it calculated?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago