CS 1320 (Principles of Algorithm Design I):
Homework #3

Assigned:
February 4, 2000.
Due:
February 11, 2000, at start of class.
Credit:
20 points (10 points per problem).

Instructions

Write a C++ program to solve each of the problems below. Your code should begin with comments that describe what the program is supposed to do, in terms of its inputs and outputs. See the sample programs for examples.

Problems

Temperature conversion

Write a program that defines and tests a function to convert Fahrenheit temperatures to Celsius temperatures. Your program should include:

You may want to define additional functions as well. For each function you write, be sure to include comments describing its precondition(s) and postcondition(s).

To help make the results of this conversion more accurate, I have written a function divide_and_round that divides one integer by another and returns a rounded result (rather than the truncated result returned by the integer division operator "/"). To use this function, you will need to:

To see how to use the function, read its comments in divide.h.

Income tax estimate

U.S. income tax is a function of taxable income, calculated using a formula such as the following (adapted from the 1999 tax rate schedules for single taxpayers):

Write a program that prompts the user for a taxable income and computes and prints the tax due on that amount, based on the above formula. To do the computation, the program should use a function that takes taxable income (in dollars, i.e., an integer) as a parameter and returns the tax on that amount, also in whole dollars. Round to the nearest dollar. You can do the whole calculation using only integers; you may find the divide_and_round function, discussed in the previous problem, helpful.

What to turn in

Submit your source code as described in the guidelines for programming assignments. For this assignment: