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

Assigned:
September 27, 2007.

Due:
October 4, 2007, at 5pm. Not accepted later than 5pm October 5.

Credit:
40 points.

Reading

Be sure you have read (or at least skimmed) chapters 4 and 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.

  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 2007 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 $7,925 is $782.50 plus 15% of $100; computing and rounding, this gives $798.

    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.

  2. (20 points) Write a C program that finds the roots of the quadratic equation

    $\displaystyle ax^2 + bx + c = 0
$

    As you may (or may not!) recall from math courses, this equation has real roots exactly when

    $\displaystyle b^2 - 4ac \ge 0
$

    in which case the two roots are given by

    $\displaystyle \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$

    Your program should prompt the user for the three coefficients $ a$ , $ b$ , and $ c$ (in the form of floating-point numbers). If the equation has real roots, the program should compute and print them; otherwise it should print a message such as ``No real roots''. (So for example, for $ a$ , $ b$ , and $ c$ equal to 1, 0, and -1 respectively, it should print the two roots 1 and -1.)



Berna Massingill
2007-10-07