(
Latest Revision:
Monday October 27, 2014
)
FOURTH CS 1500 SOLO PROGRAM
Future Value of Periodic Savings
Figuring Out How Much a "Holiday
Club" Account Will Contain in the Future
NOTE:
No global variables are allowed in this program.
In other words, all variables must be declared inside main
or another function.
(See pages 221-224 of the nihth edition of Savitch.)
OBJECTIVE:
Practice top down design, the use of the data type double in
mathematical functions, and appropriate formatting of the output of
double values.
THE ASSIGNMENT:
Write a program that computes the future value of a "Holiday 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 holiday gifts. One
Friday, instead of depositing another payment, the owner of the account
withdraws all the money and spends it.
Naturally, people want to know the answers to questions like this:
"If I put $30.00 in the Holiday Club account 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:
The program must begin by writing information to explain the purpose of the
program, and a general description of how to use the program.
The program must then prompt for and input the following three items (in the
following order): the amount of the weekly payment, the annual interest rate,
and the number of weekly payments. It must print individual prompts for each
of the 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
where, r = R/5200, the decimal equivalent of the weekly interest
rate.
Of course, the formula above is in a format 'to be understood by humans,' and
does not have C++ syntax. Part of your job as programmer is to create
appropriate C++ expressions to perform the calculations.
Here is an outlandish example of a way to use the formula that may make it
more understandable: Suppose P is $100 per week, the annual interest rate R is
520% (ten percent per week) and the number of payments N is 2, then r =
520/5200 = 0.10, and
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 r = 9.25/5200 =
0.001779, and
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 it, the program must write a message to standard output (the
screen) 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
your program should output something very much like this:
The future value of 50 weekly payments 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" formatting directives
in the box at the bottom of page 56 of the ninth edition of Savitch
are the commands you will need. Keep in mind that it is the
parameter to cout.precision() that controls the number of digits
after the decimal point.
You can examine a sample script of a program run
here. Use it as a guide for writing the prompts
and other output statements of your program.
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 skeleton (shell).
To write the program using my design suggestion, fill in the definitions of
all the functions in the program skeleton (including "main").
Pay close attention to the header comments for each function.
They explain what each
function is supposed to do. If you want to rely on my design suggestion, then you have to conform to the directions in the header comments. You have to write the code for the functions in the skeleton exactly as the comments describe. The functions must do exactly what the comments say they do, no more and no less.
You do not have to use my design suggestion or program skeleton. 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:
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 exercise
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 notifying
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. (Each line of code must be less than 79
characters in length.)
- 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:
CS1500Solo4Source, and
- a (filtered) script showing the results of the program for the
following three sets of 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: CS1500Solo4Script .
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.)