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

In this project, write a program to compute the taxes for an individual based on

ID: 3697799 • Letter: I

Question

In this project, write a program to compute the taxes for an individual based on their income, deductions, and filing status. This project focuses on files, vectors, and maps.

We want our program to be general and reusable, but tax rates often change from year to year, so to accommodate this we will read all of the tax bracket information from a file.

Examples Using 2009 Tax Brackets

The table below contains the tax brackets for 2009, using these rates we will demonstrate the process of calculating an individual's tax bill. As stated above your program will read the tax bracket information from a file, so you cannot hard code these values into your program. They will change when we test your program!

2009 U.S. Federal Personal Tax Rates

There are 4 filing statuses: Single (S), Married (M), married Filing separately (F), and Head of household (H). For someone with Single filing status and a taxable income of $10,000, the first $8,350 is taxed at 10% and the other $1,650 is taxed at 15%. The total tax bill would be $1,082.50:

= ($8,350.00 * 0.10) + (($10,000.00 - $8,350.00) * 0.15)

= $835.00 + ($1,650.00*0.15)

= $835.00 + $247.50

= $1,082.50

For someone with Head of Household filing status and a taxable income of $150,000, the total tax bill would be $33,329.00.

= ($11,950 * 0.10) + (($45,500 - $11,950) * 0.15) + (($117,450 - $45,500) * 0.25) + (($150,000 – $117,450) * 0.28)

= 1195 + 5032.50 + 17987.50 + 9114

= $33,329.00

Sample Program Execution

The user should be prompted for a file containing the tax bracket information and then a single uppercase letter indicating the filing status (S, M, F, or H). The user should then be prompted to enter a gross income followed by deductions on a single line. The taxable income (used above to compute the tax bill) is gross income – deductions.

Welcome to the CS1064 Tax Calculator program!

Enter the file storing the tax brackets: taxinfo2009.txt

Enter filing status (S/M/F/H): M

Enter Total Income and Deductions: 19700 3000

Total Tax: $1670.00

Would you like to calculate another person’s taxes? (yes/no): yes

Enter filing status (S/M/F/H): S

Enter Taxable Income and Deductions: 43444 4300

Total Tax: $5973.50

Would you like to calculate another person’s taxes? (yes/no): no

While this example only shows the Single (S) and Married (M) tax filing statuses, your program should be able to compute the correct tax bill for any of the 4 statuses (S, M, F, or H) listed above. After finishing each tax calculation, the user should be prompted as to whether they'd like to calculate another person's taxes. The program should continue until the user says "no" and should be able to compute an arbitrary number of tax bills. Make sure the prompts are as close as possible to the example above; also notice the formatting for the output. Note that the total tax includes a dollar sign and is printed to exactly 2 places.

Tax Brackets File Format

The file in the sample execution above (taxinfo2009.txt) contains the tax rates and tax brackets for a particular year, and formatted is like the text shown below:

10.0 15.0 25.0 28.0 33.0 35.0 S 8350 33950 82250 171550 372950 M 16700 67900 137050 208850 372950 F 8350 33950 68525 104425 186475 H 11950 45500 117450 190200 372950

The first line of numbers contains the tax rate for each bracket. After that, there will always be four filing statues in the file but their ordering may change. Each status is made up of a line with a letter (the status), and then a line with the tax bracket values. Further, there is a blank line between each filing status. Each number listed for a status is the upper bound for a bracket, for example: with filing status S, all income <= 8350 is taxed at 10% (10.0). Note: there's one upper bound "missing" from the file, there's no upper bound provided for the highest rate. Anything above the final upper bound should be taxed at the highest rate, i.e. anything less than infinity is taxed at the top rate. All input files will follow this format and your program will not be tested with improperly formatted files.

When testing your program there may be additional (or fewer) rates and brackets, but there will always be a consistent number of rates and brackets within a single file, e.g. 6 rates and 5 brackets or 7 rates and 6 brackets.

Figure out how to do the calculation for Single, $8,000 and write the code (and test it), then figure out the calculation for Single, $10,000 (and test it). Since the number of rates and brackets can change from program run to program run, it isn't possible to hardcode the bracket values into the program, and you won't be able to solve the problem with a giant if/elif/else statement. You will still need if/else statements though. Instead you'll want to store the rates and the brackets in vectors, and use them to compute the tax bill. Once you know the status, you want to move through the appropriate vector computing the tax as you go. As you move through the vector there will be two possibilities: (1) the taxable income is greater than the bracket upper bound (150000 > 11950.00) or (2) the bracket bound greater than (or equal to) the taxable income (190200.00 >= 150000). You're going to do something slightly different in each case and I'd review the examples at the beginning of this document for hints. Case 2 is your stopping point, when you reach that point you don't need to look at the next bracket. So you'll need some sort of loop (to move through the vector) and probably an if/else statement (for the 2 cases) to compute the taxes.

For this project, I'd recommend using string streams, vectors, and maps. For example, the function below will read the brackets from a line in the file and put them in a vector containing doubles. The code below that shows how you might use a map to store both the filing status and the brackets.

// Function to read the brackets from a line. vector get_brackets(string line)

{

double bound;

vector<double> brackets;

istringstream ss(line);

while (ss >> bound)

{

brackets.push_back(bound);

}

// Add an additional upper bound for infinity.

// Makes calculations a little easier...

brackets.push_back(numeric_limits::infinity());

return brackets;

}

// In the main() function, we use a map of char to vector: map > status_to_brackets;

// status and line come from the input file status_to_brackets[status] = get_brackets(line);

// Now I can I get the brackets using the map and the user provided // filing status:

cout << "Enter filing status: ";

cin << s;

// Iterate through the vector with the brackets. for (int b = 0; b < status_to_brackets[s].size(); b++)

{

// Do something with status_to_brackets[s][b]

}

Explanation / Answer

p3.py

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