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

Assigned:
February 28, 2000.
Due:
March 13, 2000, at start of class. (Revised March 3: now due March 15, 2000, at start of class.)
Credit:
30 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

Problem: Number sequence

A sequence begins 0, 1, 1, 2, 3, 5, 8, 13. Write a C++ program producing the first thirty entries in this sequence. (You will need to figure out the rule for producing the next entry from the preceding entries.)

Problem: Exponentiation

Write a C++ program to compute the exponentiation function BE (B to the Eth power), where B is any non-zero number (not necessarily an integer) and E is an integer. Remember that B0 is 1 for all B, and B-E is 1/BE.

Examples:

You can assume that B is non-zero.

Your program must include:

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

Credit-card billing, revisited

Acme Bank's terms for its AcmeCard credit card were described in Homework #4.

Write a C++ program that computes information for an AcmeCard bill for several months. Your program should first read in an interest rate (as an annual percentage) and a starting balance, and then repeatedly read in a last month's payment and current charges, continuing until "end of file" (in Unix environments, signalled by the user pressing control-D). All amounts are to be entered in floating-point form (e.g., "12.34" for $12.34). As each month's information is entered, the program should print out interest due, new balance, and minimum payment. After "end of file" is detected on input, it should print out the total interest charged. All amounts should be printed out in dollars-and-cents form, e.g. "$12.34".

Here is a sample execution of the program:

$ credit_card 

Enter annual interest rate, as a percentage:
12
Enter initial balance, in dollars and cents:
100.00

Enter last payment and current month's charges, in dollars and cents (control-D to end):
100.00 200.00
Interest due = $0.00
New balance = $200.00
Minimum payment = $10.00

Enter last payment and current month's charges, in dollars and cents (control-D to end):
100.00 100.00
Interest due = $1.50
New balance = $201.50
Minimum payment = $10.08

Enter last payment and current month's charges, in dollars and cents (control-D to end):
101.50 100.00
Interest due = $1.50
New balance = $201.50
Minimum payment = $10.08

Enter last payment and current month's charges, in dollars and cents (control-D to end):
[ user presses control-D ]

Total interest = $3.00

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: