Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The C++ Bank provides an on-line Mortgage Payment Calculator. This is the formula for calculating the monthly payment based on the amount of the loan,

The C++ Bank provides an on-line Mortgage Payment Calculator. This is the formula for calculating the monthly payment based on the amount of the loan, the annual interest rate, and number of years of the loan.

M=Pi / [q(1-[1+i/q)]^-nq)]

M = monthly payment i = interest rate (decimal) P = principal of the loan (amount borrowed)

n = number of years q = number of payments per year = 12

In this programs main function, first present your header, Header, and some explanation of the program. Declare the variables you will need in main. These will include the struct variable mortData. Start a Play Loop with a do while or while structure. Using a single ask function, AskForLoanInfo , ask the user to enter the information needed to calculate the monthly payment: amount borrowed, annual interest rate, and number of years of the loan. The start date and end date of the loan will be calculated elsewhere. Load the information into a struct variable called mortData, which is returned by reference.

Document in your MortCalc.h file, how you expect the interest to come into the function Is 5% 5, or 0.05??? Also be clear to your user when he/she enters percentage, is it 5 for 5% or 0.05 for 5%.

When you have collected the users input, call the Validate Function, passing in a reference to the struct variable. The maximum loan that the C++ Bank offers is $500,000, and the principal cannot be less than or equal to 0. The interest rate also cannot be less than or equal to 0 and the maximum is 10%. The only choices for the number of years are: 15, 25 and 30. If the user input falls in these ranges, return true. Else, return false.

In main, check the return from the Validate function. If true, call MortCalc, which determines the monthly payment. MortCalc also calculates the total amount of money paid over the life of the loan. It also calculates the total interest paid over the life of the loan. NOTE: the total cost of the loan is the monthly payment * number of payments. Total interest equals the total loan cost less the principal.

MortCalc calls the function CalcEndOfLoan so that it can display the end date of the loan. The function first gets todays date from the System date function of . This is the start date of the loan. The end date of the loan is the last day of the loan, or the last day of the month for the last month of the loan in the last year of the loan.

Create a nicely formatted string which summarizes the mortgage information: Principal of the Loan, Interest Rate, Years, Monthly Payment, Total Loan Paid, Total Interest Paid, the start date of the loan and the end date of the loan. Be sure the dollars are formatted to 2 decimal places and show the $ sign. MortCalc returns the nicely formatted string so that main can display the result to the user.

WriteMort writes the mortgage information to a file. It returns a bool, to indicate whether the file was opened and written. In main, after displaying the mortgage information, ask the user for a filename. Then call WriteMort, passing it the result from MortCalc and the filename. Check the bool return. If true, tell the user that the file was written. If false, report that to the user, too.

Ask the user if he/she would like to calculate another mortgage payment. Remember to tell the user the choices for an answer. If yes, loop up to the top of the Play Loop. When the user is done, present a good-bye message.

The struct can be declared in a separate .h file or in the Functions.h file:

struct MortInfo

{

float interest;

int principal;

int term;

//start date of loan

int monStart, dayStart, yearStart;

//end date of loan

int monEnd,dayEnd, yearEnd;

};

Functions in the MortCalc Program:

Return type

Function Name

Parameter List

What it Does

void

Header

( )

Writes the course header and program information

void

AskForLoanInfo

(MortInfo &mortData )

Gets user input for principal, interest rate, start date of loan and length of loan

bool

Validate

(MortInfo &mortData )

Validates user input

string

MortCalc

(MortInfo &mortData )

Calculates Monthly Payment, Total Loan and Total Interest, returns formatted string with summary of the loan information

bool

WriteMort

(string result, string filename)

Opens a file and writes the Mortgage information to the file.

void

CalcEndOfLoan

(MortInfo &mortData)

Uses system date to calculate the end date of the loan and assign it into the struct variable.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Do you have any foreign language proficiency?

Answered: 1 week ago