This needs to written using functions and the Mortgage Table

*******************This needs to written using functions and the Mortgage Table and results needs to be outputted to a file******************************************************

Professor said not to use any arrays in this program.

You are to write a C++ program that will create an output showing a Mortgage Table for monies you have borrowed. Given the amount of a mortgage, the rate of interest being charged, the monthly payment, and the amount of tax due on the property (per year), produce a table of principal, interest, tax, payment, and principal left for each month of the mortgage’s existence. First you have to calculate the monthly payment amount before producing an ‘Amortization Schedule’. See the earlier assignment (warm up programs).

Below is how to calculate interest values; determining the breakdown of each monthly payment

Even though the monthly payment is fixed, the amount of money paid to interest varies each month. The remaining amount is used to pay off the loan itself. The complicated formula above ensures that after 360 payments, the mortgage balance will be $0.

For the first payment, we already know the total amount is $1,342.05. To determine how much of that goes toward interest, we multiply the remaining balance ($250,000) by the monthly interest rate: 250,000 x 0.416% = $1,041.67. The rest goes toward the mortgage balance ($1,342.05 - $1,041.67 = $300.39). So after the first payment, the remaining amount on the mortgage is $249,699.61 ($250,000 - $300.39 = $249,699.61).

The second payment\'s breakdown is similar except the mortgage balance has decreased. So the portion of the payment going toward interest is now slightly less: $1,040.42 .... ($249,699.61 * 0.416% = $1,040.42). I would also like a column that shows the ‘taxes’ paid each month and that the monthly payment has the taxes added to the monthly mortgage payment. Tax column not shown below.

For your program use the following: the principal is $22,500.00, the interest is 5.37% per year, the tax per year is $350.00, and the number of payments are for 8 years.

You are to produce a table with the appropriate values (the above example plus one column). Make sure you have labels, totals and all the values line up nicely. I like the commas in the big numbers and ‘$’ signs in the front of each number. All money values are to be shown in dollars and cents.

Monthy Amortization Schedule Payment Amount $1.342.05 $1,342.05 $1.342.05 $1,342.05 $1,342.05 Principal $300.39 $301.64 $302.90 $304.16 $305.43 nterest $1,041.67 $1,040.42 $1,039.16 $1,037.90 $1,036.63 Balan S249,699.61 $249,397.97 $249,095.08 $248,790.92 $248,485.49

Solution

Here is the code for you:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
//Reads the inputs principal amount, rate of interest, and number of payments.
void readInputs(double &presentValue, double &rateOfInterest, int &numOfPayments)
{
cout<<\"Enter the loan amount: \";
cin>>presentValue;
cout<<\"Enter the yearly rate of interest(as a percentage): \";
cin>>rateOfInterest;
rateOfInterest = (rateOfInterest/100)/12;
cout<<\"Enter the number of payments: \";
cin>>numOfPayments;
}

//Calculates the EMI per payment, given the inputs.
void EMICalc(double presentValue, double rateOfInterest, int numOfPayments, double &EMI)
{
EMI = (rateOfInterest * presentValue) / (1 - pow((1+rateOfInterest), (-1*numOfPayments)));
EMI = floor(EMI*100+0.5)/100;
}
void printTable(double pV, double roI, int noP, double emi)
{
ofstream outFile;
string fileName;
cout<<\"Enter the output file name to which you want to print the table: \";
cin>>fileName;
outFile.open(fileName);
outFile<<\"Principal\\t$\"<<pV<<\"\\tPayment\\t$\"<<emi<<endl;
outFile<<\"Annual Interest\\t\"<<fixed<<setprecision(1)<<roI*12*100<<\"%\\tTerm\\t\"<<noP<<\" Months\"<<endl;
outFile<<\"Payment\\tInterest\\tPrincipal\\tPrincipalBalance\"<<endl;
double interest, principal;
for(int i = 0; i < noP; i++)
{
interest = pV * roI;
if(interest < 0)
interest = 0;
principal = emi - interest;
if(principal < 0)
principal = 0;
pV = pV - principal;
if(pV < 0)
pV = 0;
outFile<<\"\\t\"<<i+1<<\"\\t\"<<fixed<<setprecision(2)<<interest<<\"\\t\"<<principal<<\"\\t\"<<pV<<endl;
//pV -= emi + pV*roI;
}
outFile<<\"Final Payment\\t\"<<interest+principal<<endl;
}
int main()
{
double presentValue, rateOfInterest, EMI;
int numOfPayments;
readInputs(presentValue, rateOfInterest, numOfPayments);
EMICalc(presentValue, rateOfInterest, numOfPayments, EMI);
printTable(presentValue, rateOfInterest, numOfPayments, EMI);
cout<<\"The monthly EMI is: \"<<EMI<<endl;
double totalInterest = EMI * numOfPayments - presentValue;
cout<<\"Total interest paid: \"<<totalInterest<<endl;
  
}

*******************This needs to written using functions and the Mortgage Table and results needs to be outputted to a file*************************************
*******************This needs to written using functions and the Mortgage Table and results needs to be outputted to a file*************************************

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site