Because the tax owed on income depends on filing status, taxpayers may want to choose the status that incurs the least amount of tax.
To complete the assignment, change the program so that it works as follows:
% tax
Welcome to the tax calculator.
Enter income amounts from each of your income sources rounded
to the nearest dollar. Enter 0 (zero) when you are done.
Income: $10000
Income: $2500
Income: $0
Here is the tax on your income of $12500 for different statuses:
Married Filing Jointly : $1500
Head of Household : $1650
Single : $1800
Married Filing Separately : $1800
Filing Statuses:
0 = Single
1 = Married Filing Jointly
2 = Married Filing Separately
3 = Head of Household
Enter status: 0
You owe $1800 on your income of $12500
Note that the program must now print out the tax required on your income for all filing statuses. Moreover, they must be printed from lowest to highest order.
After these tax amounts are displayed, the user must enter which tax status they will use. Remember, they may only qualify for some of those statuses and they may or may not choose the one producing the lowest tax.
R.
-
Now, you must create an integer array, say
stat, of length
4, initially containing the numbers 0, 1, 2, 3:
Indices
0
1
2
3
stat
0
1
2
3
The numbers held in this array correspond to columns in the
tax table.
tax_table Column Indices
Row
Indices
0
1
2
3
0 600 500 600 550
1 1200 1000 1200 1100
2 1800 1500 1800 1650
... ... ... ... ...
You can use these numbers to look up taxes in the tax table, as in:
tax_table[R][stat[i]]
For example, if R is 2 and the stat array
contains 0,1,2,3, then using stat to access each column in
row R of the tax table corresponds to the list of values
1800, 1500, 1800, 1650.
-
Now, you must sort this array based on the amounts in the tax table.
So, if you rearrange the
stat array into the order 1,3,0,2:
Indices
0
1
2
3
stat
1
3
0
2
then for row R=2 this corresponds to the values 1500,
1650, 1800, 1800 (which are sorted in ascending order) in the tax table.
It is your job to write functions to sort the stat array
and use it to print out the tax values as the sample
output demonstrates.
Prepare this program, adding all appropriate comments and using
attractive and readable formatting conventions. Call the program
tax.cpp.