Determining Tax from a Table - Assignment


The Problem

Taxpayers sometimes have choices on what filing status they can choose. For example, a married couple might file jointly or separately. Likewise, a single person might qualify for head of household status.

Because the tax owed on income depends on filing status, taxpayers may want to choose the status that incurs the least amount of tax.


The Program

For this assignment, you will begin by completing the basic program discussed in lab.

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.


Your Task

You must add code that prints out the sorted tax amounts. To write out these sorted tax amounts...

  1. First, calculate the row that the income amount corresponds to in the tax table array and store this value in a variable, say R.

  2. 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_tableColumn Indices
    Row
    Indices
    0 1 2 3
    0600500600550
    11200100012001100
    21800150018001650
    ...............
    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.

  3. 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.


BU CAS CS - Determining Tax from a Table - Assignment
Copyright © 1993-2000 by Robert I. Pitts <rip@bu.edu> All Rights Reserved.