(
Latest Revision:
Saturday Oct 31, 2009
)
THIRD CS 1500 SOLO PROGRAM
Future Value of Periodic Savings
Figuring Out How Much a "Christmas
Club" Account Will Contain in the Future
OBJECTIVE:
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 (and order) 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:
P((r+1)N - 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
100((1.10)2 - 1)(1.10)
FV = -------------------------------- = $231.00
0.10
Another example: if P is 100, R is 9.25% and N is 50, then
100((1.001779)50 - 1)(1.001779)
FV = -------------------------------- = $5233.57
0.001779
Note that your program can use the pow function to calculate the
power:
(r + 1)N
For example pow(3,2) is 3 to the 2nd power (== 9) and pow(2,5) is 2 two to the
fifth power (== 32).
After computing the future value, the program will write a message to standard
output 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.57.
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 "magic formula" on page 56 of Savitch describes the formatting
commands you will need in order to get the displays of the output right. Keep
in mind that it is the parameter to cout.precision that controls the
number of digits after the decmial point.
You can examine a sample script of a program run
here.
DESIGN:
I suggest you design the program according to
this structure chart.
You can write the program by starting with a copy of
this program shell.
To finish the program using my design suggestion, fill in the definitions of
all the functions in the program shell (including "main"). Pay close
attention to the header comments for each function. They explain what each
function is supposed to do.
You do not have to use my design suggestion or program shell. However, I
expect you to employ good principles of top-down design. I will withhold
substantial credit if you do not create a program that uses functions
appropriately. As my design suggestion illustrates, there are plenty of jobs
for individual functions in this program Your program must have at least four
functions, including the main function.
DETAILS:
You should put the following lines at the top of your program::
#include <cmath>
#include <iostream>
using namespace std ;
WHAT TO TURN IN:
You will be sending me two e-mail messages. Please follow these
rules:
- Always send me e-mail as plain text in the main message body.
Never send me attachments.
- Always use the exact subject line I specify for each
message. (I often get hundreds of e-mail messages in a week. The
subject line allows me to find and sort messages.) You will lose a
significant number of points on the assignment if you use the wrong
subject line.
- Be very careful when you send the e-mail. You may use the
instructions in your
Hello World! lab excercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
filename.
- Always send yourself a copy of each e-mail message you send to me,
check immediately to see if you receive the message intact, and
check within a few minutes to see if you have received e-mail notifiying
you about an undeliverable message. You are
responsible for sending e-mail correctly.
Here is the list of things you have to turn in:
- At the start of class on the
due date
place the following item on the "counter" in front of me:
- a hardcopy (printed listing) of your program (the C++ source code).
Make sure all the code is properly formatted and that it all shows
on the paper.
- Before midnight on the the due
date send me the following by e-mail:
- A copy of the source code (C++ code) with subject line:
CS1500Solo3Source, and
- a (filtered) script showing the results of the program for the
following inputs
- P == 100, R == 520, N == 2;
- P == 100, R == 9.25, N == 50;
- P == 25.55, R == 2.375, N == 50;
For the script use the subject line: CS1500Solo3Script .
Note that there are no spaces in the subject lines given. It is important
that you do not insert any spaces. My e-mail address is:
john@ishi.csustan.edu
WHEN IS THIS ASSIGNMENT DUE?
Look for the due date in
the class schedule.
(It's at the top level of the class directory.)