CSCI 1320 (Principles of Algorithm Design I), Fall 2008:
Homework 3

Assigned:
September 25, 2008.

Due:
October 7, 2008, at 5pm.

Credit:
40 points.

Reading

Be sure you have read (or at least skimmed) chapter 5 of the textbook.

Programming Problems

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!

  1. (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):

    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:

  2. (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