Sunday, October 11, 2009

Next week's assignment

What I'll be working on next...

Objectives
: Write a reusable C++ function
Write a reusable C++ class
Material from: Day 5, 6; String handouts starting on page 29.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Part 1)
Write a program that asks the user how much she will put into a savings account, what the annual interest rate is, and what period of time she plans to keep the money in the savings account. After these values are read in, report back to the user how much money she will have in her account at the end of the period.

The following formula calculates how an investmentAmount grows when left in a bank account for some years which compounds interest monthly at monthlyInterestRate:
futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate) years*12

Your program must define and use a function that performs this calculation.
Here is the prototype, and you must write the comment telling what the function does:

double futureInvestmentValue(double investmentAmount,
double monthlyInterestRate, int years);

Prompts and messages must be in CORRECT ENGLISH. The main() is the only one that reads and prints. There are no cin or cout statements inside the function that returns the futureInvestmentValue().

Plan of Attack
1) Write a function with the following prototype:
double futureInvestmentValue(double investmentAmount,
double monthlyInterestRate, int years);

First thing to do is write a comment for this function.
Before proceeding to step 2, you must have your main() call
futureInvestmentValue(1000, 3.25/100/12, 1)
An annual interest rate of 3.25% is equivalent to a monthlyInterestRate of 3.25/100/12.
The function call above must return 1032.99.

2) Now change only your main() to read values for initial Investment and annual interest rate using cin and cout.
3) Use the following values in the run that you turn into me:
Deposit = 1000, Annual Interest Rate = 4%
4) Be careful of whether your interest rate is monthly, and whether it needs to be divided by 100.


Part 2)
Write a class that can be used to create very short form letters concerning an election. One object represents one form letter, so name your class FormLetter. Each FormLetter object might have different values for these String fields:

• the name of the person the letter is addressed to (to)
• the name of the candidate you want the addressee to vote for (candidate)
• the name of the person the letter is from (from)

If you were to create a new FormLetter object and set the following values for the fields:
to: Hildegard
candidate: The Terminator
from: Brunhilda

And then you were to print that object, your output would look like this:
_____________________________________________

Dear Hildegard,

I would like you to vote for The Terminator
because I think he is best for this state.

Sincerely,
Brunhilda
_____________________________________________

Therefore, class FormLetter needs three member variables: to, candidate, and from.
And class FormLetter needs two member functions: setValues() and printLetter(). Note that the member function called setValues() must have three parameters to accept the new values for the three member variables. The member function printLetter() needs no parameters, because all the data is already inside the object when printLetter() is called.

In order to test this class FormLetter, you must write a main() outside of the class. Every time you write one reusable class, you will always write a main() that will simply declare an object of the reusable class, and call its member functions on the object to see if they work.

So inside main():
1. declare a variable of class FormLetter
2. call setValues() with your chosen values to store inside the object
3. call printLetter() to see if the letter looks right.

In order to receive full credit for this assignment:
• You must go through the above TEST TWICE in the same main(), so that you can see whether the member function setValues() can change the values inside an existing FormLetter object, based on values sent from main().
• This program gets no data from the user's keyboard, all data is included as string literals in the main().

No comments:

Post a Comment