|
|
Program 3 - January 24Writing and Using FunctionsFor some kinds of programs, it would be handy to have a set of financial functions to do the most common calculations. For this assignment you will write several such functions and a main program that tests them. Main ProgramYour main program should ask the user to solve one of two different kinds of problems. For each kind of problem, the user will be asked for certain information and then you will call the appropriate function and display the result.
Financial FunctionsThe prototypes for your functions are as follows:
You should include these prototypes in a separate header (.h) file and include that header in your main program. The header file should include comments that would help another programmer to use your functions. (For example, the is the rate in your function given as a percent or a decimal fraction?) The definitions of the functions should be included in a source (.cpp) file separate from your main program. You must add this file to your project in Visual Studio using the Project menu (or just try to compile it and say yes when asked if it should be added).
Perhaps you are a bit unsure of the formulas for calculating these amounts. There are a number of ways to do it, but the following pseudocode will work for this assignment:
Extra CreditIf this is all new to you, the above will be plenty. However, some of you may be bored by this. In that case, add two more functions to your main program:
Hint: You can do this by looping through all the periods adding the periodic investment and calculating the interest each time. The answer is different depending on whether you invest at the start of the period or the end, but you can do it either way for this assignment.
Hint: Figure out how much one dollar each period be worth at the end by calling the function for item 3. The answer is the ratio by which any amount would grow. Divide that ratio into the amount you want to have to get the amount you need to invest each month. |
|
Copyright © 2000 Charlie Poole. All rights reserved.
|