(Latest Revision: 04/21/2000)
04/21/2000 -- corrected a couple of typo's

THIRD CS 1500 SOLO PROGRAM: Figuring The Amount in a Savings Account


OBJECTIVE: The purpose of this programming assignment is to make sure you can use the C++ data type double in programs. In particular, this assignment is designed to give you practice using doubles in mathematical functions and doing appropriate formatting of the output of double values.


THE ASSIGNMENT:Your assignment is to write a program that computes the amount of money in a savings account earning compound interest.

The idea is that a person will put an amount of money called the principal into a savings account at a certain time, and then leave the money in the account for a certain number of years. We assume that no money is withdrawn or deposited after the original principal is placed in the account. The job of the program is to compute how much money is in the account after a certain number of years.


INPUT: Like many of the example programs we have been reading lately, this program must begin by writing some information explaining the purpose of the program and a general description of how to use the program.

The program must then prompt for and read the amount of principal, the interest rate, and the number of years (in that same order). It must print individual prompts for each of these three quantities.

The principal should be entered as a fixed-point decimal, denoting dollars and cents, without a dollar sign or commas, using the decimal point in the usual manner when the amount is not a whole number of dollars. For example: the user enters 1234.56 to mean 1234 dollars and 56 cents, or 1000 to mean 1000 dollars. The prompt you create for the principal must make these rules clear to the user of the program.

The interest rate must be entered as a decimal number of percentage points. For example: the user enters 9.75 to mean an interest rate of 9.75%. The prompt you create for the interest must make this rule clear to the user of the program.

The number of years must be entered as a positive integer. For example: the user enters 30 to mean thirty (whole) years. The prompt you create for the number of years must make this rule clear to the user of the program.

Make sure to write the program so that it inputs only the principal, interest rate, and number of years, in that order. If I decide I want to test a program I will want to use redirection from prepared files of input. This requires that you and I have a precise agreement on the form of the input.


OUTPUT: After the user enters the input, the program must compute the amount of money in the account by using the formula of example 5.19 on on page 266 of Shiflet, and the pow function described on page 265. (Note: If the interest rate that your program gets from the user is called iRate, then, iRate/100 is the interest rate your program must use in the formula. This format is used only internally. The interest rate is expressed as a number of percent both on input and on output.)

The program will then write to the user's screen a message saying what the amount is. The message must also tell what the input of the user was. For example, if the user enters 1000.00 for the amount of principal, 10 as the interest rate, and 1 as the number of years, then the program should output something like:

$1000.00 will grow to $1100.00 after earning 10.000 percent for 1 year.
Your program is required to format the numbers for output as shown above. The money must always appear in fixed point notation, preceded by a dollar sign, and with exactly two digits displayed after the decimal point. The interest rate must be displayed in fixed point notation, as a percentage, with exactly three digits displayed after the decimal point. The discussion on 225-228 of Shiflet describes the formatting commands you will need in order to get the displays right.


DESIGN: For this assignment, I am not giving you a structure chart to follow. You must create your own design of this program. I am expecting you to employ good principles of top-down design. Substantial credit will be withheld if you do not create a program that uses functions appropriately.


DETAILS: You need to do the following includes:

#include <math.h>
#include <iostream.h>
#include <iomanip.h>

EXAMPLE OUTPUT: Have a look at a sample script to get an idea of how it should look when you run the program.
WHAT TO TURN IN: Before midnight on the due date, e-mail the following two items to me:

  1. A copy of the source code, properly documented.
  2. A filtered script showing three test runs with different kinds of input.
My e-mail address is: john@ishi.csustan.edu

Please use the following subject lines exactly for the e-mails:

For the source file: CS1500Solo3source

and for the script file: CS1500Solo3script.

Note that there are no spaces in these subject lines. If you like, you can copy and paste the subject lines right from this document.

Thanks! Your use of these subject lines will really be a big help to me when I try to sort through the perhaps hundred e-mail messages that will be in my electronic mailbox!


WHEN IS THIS ASSIGNMENT DUE?

Look for the due date in the class schedule. (It's at the top level of the class directory.)