Lab Assignment 3

You are to write the following two programs. Once you are finished, you must do the following...
  1. Print out a copy of your source code for each program, complete with your name, date, lab assignment number (and everything else defined in the coding style we covered), and submit the printout to myself before you leave.
  2. Submit a copy of your program source code electronically, by emailing it to me (ryan.flannery@gmail.com).

Task 1: Calculating Debt (10 points)

As a starving student, you will no doubt have to take out many credit cards to survive (how else will you be able to afford food, rent, and iPods?). But after acquiring so many credit cards, you are having difficulty seeing how much debt you will accumulate. Your task is to write a simple program to help you see this easier.

Your program is to prompt the user for the following inputs
  1. How much money you currently have charged on your credit card. Call this amountCharged.
  2. What interest rate you have on that credit card. Call this interestRate. Note that if you have an interest rate of 6%, you'll probably want to represent this as 0.06 (and it's alright if the user must input the percent as this).
  3. How many years before you will start paying off the credit card. Call this numYears. For this, require a positive whole number (i.e. do not use a float or double to represent this).
Once you have these inputs, your program is to output the following... To calculate the amount owed for each year (call the year number simply year), you must use the following equation
amountOwed = amountCharged * (1 + interestRate)year

Where amountOwed is the amount owed after year year.

QUICK NOTE: To calculate powers, such as
xy

You'll want to do the following...
  1. Include the cmath library in your program, by adding
    #include <cmath>
    After you include iostream.
  2. After you add that to your program, you'll have various standard mathematical functions at your disposal. One of these is the pow function, which can be used to calculate xy by doing pow(x,y).
  3. So, to calculate something like (1 + interestRate)year, do the following...
    pow( 1.0 + interestRate, year )
Below is output from a run of such a program...
   Enter the amount charged: 3500
   Enter the interest rate as a decmial (E.g. for 6% enter 0.06): 0.07
   Enter the number of years before you'll start paying off: 10

       Year    Amount Owed
       ----    -----------
          1        3745.00
          2        4007.15
          3        4287.65
          4        4587.79
          5        4908.93
          6        5252.56
          7        5620.24
          8        6013.65
          9        6434.61
         10        6885.03

      After 10 year(s) you'll owe a total of $6885.03
      Press any key to exit the country...

Task 2: Revisiting Lab 2 (10 points)

You are to write a program that does the following...
  1. Prompt the user for a number (positive integer) that will indicate how many numbers will then be input from the user.
  2. Once the user has input such a number, say n, you will then prompt the user for n numbers.
  3. After these n numbers have been input from the user, you are to display the sum of the n numbers input, the maximum and minimum of the n numbers, and the average.
Now before you get started, think about what must be done. How are you going to calculate the sum, max/min, and average? With a little thought, it should be clear that you'll have to do this as you go.

Below is a sample run from such a program (the text in red is input from the user)...
   Please enter the number of numbers which you will be input for: 4

   Enter number 1: 2
   Enter number 2: 10
   Enter number 3: -3
   Enter number 4: 0

   Of the above 4 numbers...
         Sum: 9
     Maximum: 10
     Minimum: -3
     Average: 2.25