EECS168 09:Homework3
| Navigation | 
|---|
| Home | 
| Information | 
| Classwork | 
Overview
By now you have learned how to make function calls to some predefined functions such as sqrt() from the cmath library. In this homework you will write your own functions and make function calls to them. You are going to write a mortgage calculator program.
DUE DATE: The electronic submission of your homework must be received before 11:59 pm, Tuesday, 17th of February.
Problem Description
This program takes the initial amount of a loan (the principal), the annual interest rate, and the length of the loan (in YEARS) as input. It outputs the monthly payment, along with a mortgage table that shows the monthly interest, principal payment, and new principal balance.
Program Requirements
Name your source code file MortgageCalc.cpp In writing the program, you have to satisfy the following requirements:
- The main() function should have very little code and it will be mainly making function calls to the functions you will write.
 - Propperly comment each function, describing input to the function (precondition), the output from the function (postcondition), and the logic within the function.
 - It is the responsibility of the programmer to check for incorrect input of the user and handle it correctly. For example, you need to make sure that a user enters the interest rate as a number in the range of 1 to 100. The user should be prompted to re-enter incorrect input. The program should not hang or give ugly error messages, or worse proceed and produce incorrect output.
 - The output format should match what is shown below.
 
To write the Mortgage Calculator program, proceed as follows:
Write a function for receiving input from the user
- Use the function for getting three inputs from the user: 
- P: the principal, that is the initial amount of the loan
 - R: the annual interest rate (from 1 to 100 percent)
 - L: the length (in years) of the loan
 
 
We assume a typical conventional loan where the interest is compounded monthly.  Write a function that calculates and returns your monthly payment. First you should declare three more variables to make further calculations easier:
- J: monthly interest in decimal form = R / (12 x 100)
 - N: number of months over which loan is amortized = L x 12
 - M: the monthly payment
 
The monthly payment can be calculated using the following expression:
                            J
        M  =  P  x --------------------
                
                     1  - (1 + J)^-N
In this expression, ^ stands for power and you can implement it using the pow() function from the cmath library.
Write a function to calculate this value and display it to the user (as well as saving it for later calculations).
Write another function which takes care of several remaining calculations:
- The current monthly interest: this is J% of the total remaining balance, H = P x J
 - The amount of principal you pay for that month: this is your monthly payment minus your monthly interest, C = M - H
 - The new balance of the principal of your loan: Q = P - C
 - The function prints all three calculated values for the user
 - The function returns the new balance of the principal of your loan (Q)
 
To print out the complete amortization table you need to do some iteration (i.e. a simple loop) over the function that you just wrote
- After calling the function once, replace the previous principal with the new balance of your principal (set P equal to Q) for subsequent function call. You want to loop until the value Q (and hence P) goes to zero.
 
Example Execution
The formatting of the program's output should exactly match the following (user's input is shown in bold):
Please enter the principal of your loan: 1000 Please enter the annual interest rate: 20 Please enter the length of the loan in years: 1
Monthly payment: $92.63
Table of Mortgage Payments ----------------------------------------------------------------------------- Monthly Interest | Principal payment of the month | New principal balance $16.66 $75.97 $924.03 $15.40 $77.23 $846.79 $14.11 $78.52 $768.27 . . . . . . . . .
Notes
- Your source code files should have comments at the top with:
- your name
 - the class ("EECS 168")
 - the assignment name (i.e., "Homework 3")
 - the date
 - an explanation of what the code is supposed to do
 
 - You should have comments in the code that explain what the code is doing.
 - You should test your program including incorrect input handling. Show your testing output in a file called testing.txt, like you did in Homework 1.
 
Additional Requirements For EECS 169 Students
In addition to all the requirements for EECS168 students, students enrolled in EECS169 must also do the following:
- Have the program output the total interest paid over the life of the loan.
 - Determine what annualized percentage of the original loan balance was paid in interest.
 - Allow the user to do as many loan calculations as desired before exiting.
 
Submission
The files you should submit electronically are:
- Smith-1234567-Homework-03.tar.gz which is a tar file containing
- MortgageCalc.cpp: Your source code.
 - testing.txt: The testing you did on your finished program.
 
 
- The subject of your e-mail should be '[EECS 168] Homework 03'