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

Assigned:
February 16, 2000.
Due:
February 23, 2000, at midnight.
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

Distance between points

Given two points in three-dimensional space, expressed in terms of their x, y, and z coordinates, the distance between them is defined to be the square root of the following sum: the square of difference between their x coordinates plus the square of difference between their y coordinates plus the square of difference between their z coordinates.

Write a C++ program to compute distance between two three-dimensional points. Your program must include:

Remember to include, for each function you write, comments describing its precondition(s) and postcondition(s).

Credit-card billing

Acme Bank has decided to offer an AcmeCard credit card with terms as follows. Customers who pay off their previous month's bill will not be charged interest for the current month. For other customers, interest due this month will be the monthly interest rate times the "revolving balance" (previous month's balance minus payment) plus half the current month's charges. The minimum payment due each month will be 5 percent of the customer's new balance (previous balance minus payment, plus current month's charges plus interest).

Write a C++ program that computes information for an AcmeCard bill. Your program should read in interest rate (as an annual percentage, e.g., "12" for 12 percent per year), previous balance, last payment, and current month's charges. All amounts are to be entered in floating-point form (e.g., "12.34" for $12.34). It should then print out interest due, new balance, and minimum payment. All amounts should be printed out in dollars-and-cents form, e.g. "$12.34". Here are some examples:

Interest rate Previous balance Last payment Current charges Interest New balance Minimum payment
12 100.00 100.00 50.00 $0.00 $50.00 $2.50
12 200.00 100.00 40.00 $1.20 $141.20 $7.06

You do not need to worry about rounding. Use as many or as few functions as you choose.

What to turn in

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