CSCI 1320 (Principles of Algorithm Design I), Fall 2008:
Homework 3
- Assigned:
- September 25, 2008.
- Due:
- October 7, 2008, at 5pm.
- Credit:
- 40 points.
Be sure you have read (or at least skimmed) chapter 5
of the textbook.
Do the following programming problems. You will end up with at
least one code file per problem.
Every code file should begin
with comments identifying you as the author and describing its
purpose. It should be readable to human readers as well as
to the compiler, so use consistent indentation and meaningful
variable names. Feel free to cut and paste code from any of
the sample programs on the course Web site.
Submit your program source (and any other needed files)
by sending mail to
bmassing@cs.trinity.edu,
with each file as an attachment.
Please use a subject line that mentions the course number and
the assignment (e.g., ``csci 1320 homework 3'').
You can develop your programs on any system that provides the
needed functionality, but I will test them on one of the department's
Linux machines, so you should probably make sure they work
in that environment before turning them in.
Note: The first problem looks longer and more complicated
than the second one, but I think it's more straightforward.
Feel free to do them in reverse order if you prefer!
- (20 points)
Write a C program to compute U.S. income tax given taxable income.
For single taxpayers, U.S. income tax is calculated
using the following formula
(adapted from the 2008 tax rate schedules):
- If taxable income is not more than $8,025,
tax is 10% of taxable income.
- If taxable income is more than $8,025 but not more than
$32,550,
tax is $802.50 plus 15% of the amount over $8,025.
- If taxable income is more than $32,550 but not more than
$78,850,
tax is $4,481.25 plus 25% of the amount over $32,550.
- If taxable income is more than $78,850 but not more than
$164,550,
tax is $16,056.25 plus 28% of the amount over $78,850.
- If taxable income is more than $164,550 but not more than
$357,700,
tax is $40,052.25 plus 33% of the amount over $164,550.
- If taxable income is more than $357,700,
tax is $103,791.75 plus 35% of the amount over $357,700.
Your program should prompt the user for a taxable income (in whole dollars)
and compute and print the tax due on that amount, based on
the above formula, rounded to the nearest dollar (round 50 cents
upward).
For example, the tax on $8,125 is $802.50 plus 15% of $100;
computing and rounding, this gives $818.
You could do the entire calculation
using only integers, or you may prefer to do the calculation
using floating-point numbers (preferably doubles)
and convert the final result to an int.
Hints:
- Results will be more accurate overall if you do the calculation
using int variables, calculating tax in pennies.
- One way to do the required rounding is to first
add 50 cents to the whatever value you compute and then
drop the fractional part of the result. (Try some examples
to convince yourself that this works!)
- (20 points)
Write a C program asks the user for three integers and prints them
in order from smallest to largest. (Sounds simple -- but be sure
you consider all possible cases. The user could enter the numbers
from smallest to largest, or vice versa, or in several other orders.
Your mission is to give the right answer for all possibilities.)
Berna Massingill
2008-10-01