CS302 / Program 3

Sections 15 & 22
Instructor: Colby O'Donnell

Due Date: Friday, Oct 10, 8:30 AM


Functions

Program 3 will test your use and creation of functions as well as providing additional practice implementing control constructs. You will be modifying a program (Part I) and creating a second (Part II).

Part I

Modularize (functionalize) wages.cpp

You are to modify wages.cpp so that it exhibits modularity (i.e. putting some of the code into functions).

  • Copy, compile and run the program. See what it does. Look at the source code--figure out what it does. Here is an example of its output.
  • You are to take most of the code in the first and second case statements (case 'a' and case 'b') and put it in functions.

    You are to figure out:

    • What portions of the code are to be put into the functions,
    • What parameters should get passed into the function,
    • What the functions should return.

  • The extraction of data (cin) must be put in the function as well as the calculation of pay.
  • You should have two functions--one for the inexperienced section of code, and one for the experienced section of code.
  • The program should not execute any differently than it did before (from the user's perspective).
  • Read chapter 5 of your book for examples.
What to hand in

Part II

Compute Simple and Compound Interest

Background

You are to write a program, using functions and a menu, that will calculate interest rates. The menu should allow the user to change the Principal, Term and the Interest Rate. It should also allow the user to view how much interest he would earn using the given formulas for simple and compound interest. There should be a choice which allows the user to determine the difference between the two interest rates. Finally there should be an option to exit the program.

Program requirements

Just like last time, you'll be writing this program yourself.
The requirements for the program are as follows:

  • The menu itself should repeatedly print out the choices and then prompt the user to enter a number or character indicating their choice. One of the choices should be to exit the program (by quitting the loop). The menu might look something like this:

    Welcome to Interest Calculator

    Choices are:
    [P] Change the current principal
    [T] Change the current term
    [R] Change the current rate
    [S] Calculate Simple Interest for these values
    [C] Calculate Compound Interest for these values
    [D] Calculate Difference between interest rates
    [E] Exit this calculator

    Current Principal is $5062.32
    Current Term is 4 years.
    Interest Rate is 7.25%

    Enter your choice:

  • The formula for Simple Interest is

  • The formula for Compound Interest is

  • The difference between the interest rates is simply Compound Interest - Simple Interest.

  • The calculations for both types of interest must be put in a function. The printing out of the menu, Principal, Term, and Rate as a whole must be a function. It is your choice whether or not to have the menu input in this same function (as opposed to having the cin statement in main() ). Feel free to use additional functions.
  • The initial values for the variables should be set, their values are
    Principal = 0.00 dollars
    Term = 1 year
    Rate = 0.0%
  • Here is sample output. Your output does not have to look exactly like this, however, all your menu options must have the same letter to choose them, and all the calculated values must agree.

Hints and suggestions

  • This program will take time a significant amount of time to write so plan ahead.
  • Work on the menu first, if you create the 'dummy' functions than just return 0, you can get the menu perfected before writing the actual functions.
  • You can calculate the difference between the two types of interest simply by calling both functions with the same arguments and finding the difference.
  • You should read and store the values for interest rate in percentage (e.g. 5.67), however you must convert to the actual value for the formulas (e.g .0567)
  • Use parentheses to clarify your calculation code.
  • Use comments!

Handin Procedure

You should turn in the following four files:
  • wages.cpp
  • wages.exe
  • interest.cpp
  • interest.exe
To accomplish that, you will have Visual C++ projects. One called "Wages", which contains the source file wages.cpp and produces the executable wages.exe. The other project is called "Interest", containing the source file interest.cpp and producing the executable interest.exe.

The path to your turnin directory is: p:\course\cs302\handin\colbster\YOUR_USER_NAME\P3

Remember, each Visual C++ Project requires it's own folder (directory), so you will need a directory for each Project you create.

I will allocate points for correct handin. If you have questions or problems, ask me early on!


(Last modified: 10/02/97)