(Latest Revision: 10/28/2001)
THIRD CS 1500 SOLO PROGRAM: Figuring The Amount in
a Xmas Club 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 future
value of a "Christmas club" account.
The idea is that every week on friday a person deposits P dollars
into a special savings account. The weekly deposit is always the
same: P dollars. Before the first deposit is made, there is no
money in the account. Whatever money is in the account earns
interest at some particular fixed rate, compounded weekly. As
the weeks go by, there is more and more money in the account, and
so every week the amount of additional interest is larger and
larger. Eventually the time arrives for purchasing Christmas
presents. One friday, instead of depositing another payment, the
owner of the account withdraws all the money and spends it on
presents.
Naturally, people want to know the answers to questions like
this: "If I put 30 dollars in the Christmas club per week for 50
weeks, and if the annual interest rate is 9.73%, then how much
will be in the account when I withdraw all the money?" This
program will answer such questions.
PROGRAM INPUT AND OUTPUT:
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 the payment,
the annual interest rate, and the number of weekly payments (in that
same order). It must print individual prompts for each of these three
quantities.
The payment amount must be entered as a fixed-point decimal, denoting
dollars and cents, without a dollar sign or commas, using the decimal
point in the standard manner when the amount is not a whole number of
dollars. For example: the user enters 34.56 to mean 34 dollars and 56
cents, or 100 to mean 100 dollars. The prompt you create for the
payment must make these rules clear to the user of the program.
The interest rate must be entered as a fixed-point decimal number of
percentage points. For example: the user enters 8.125 to mean an
annual interest rate of 8.125%. The prompt you create for the interest
must make this rule clear to the user of the program.
The number of weekly payments must be entered as a positive integer.
For example: the user enters 45 to mean forty-five weekly payments.
The prompt you create for the number of weekly payments must make this
rule clear to the user of the program.
Make sure to write the program so that it inputs only
- the amount of the payment,
- the interest rate, and
- the number of payments,
in that order. If I decide I want to test a program I will want to use
redirection from prepared files of input. That won't work out unless
you and I have this precise agreement on the form of the input.
After the user enters the input (payment amount P, interest rate R, and
number of weekly payments N), the program must compute the amount of
money that will be in the account at the end of N weeks (the future
value FV) by using this formula:
N
P((r + 1) - 1)(r+1)
FV = ------------------------
r
(In the formula above, r = R/5200.)
For example, if P is 100, R is 520% (ten percent per week) and N
is 2, then
2
100((1.10) - 1)(1.10)
FV = -------------------------------- = $231.00
0.10
Another example: if P is 100, R is 9.25% and N is 50, then
50
100((1.001779) - 1)(1.001779)
FV = -------------------------------- = $5233.54
0.001779
(Note that your program can use the pow function described on page 265
of Shiflet to calculate the power:
N
(r + 1)
The program will then write to the user's screen a message saying
what the future value is. The message must also tell what the
input of the user was. For example, if the user enters 100 for
the amount of the payment, 9.25 as the interest rate, and 50 as
the number of weeks, then the program should output something
like:
The future value of 50 weekly paymements of
$100.00 at 9.250% is $5233.54.
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 of the output right.
DESIGN:
For this assignment, I am not giving you a structure chart to follow.
However, I expect you to create your own design of this program, and to
employ good principles of top-down design. I will withhold substantial
credit if you do not create a program that uses functions
appropriately. There are plenty of jobs for individual functions in
this program, for example: main function, function to get individual
inputs or all three inputs, function to calculate the future value, and
function to write the program output. Your program must have at least
four functions, including the main function.
DETAILS:
You need to do the following includes:
#include <math.h>
#include <iostream.h>
#include <iomanip.h>
WHAT TO TURN IN:
Before midnight on the due date, e-mail the following two items to
me:
- A copy of the source code, properly documented.
- 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.)