Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Mortgager Project objective: WRITE an C++ program with COMMENTS containing an am

ID: 3761319 • Letter: M

Question

Mortgager

Project objective: WRITE an C++ program with COMMENTS containing an amortization schedule for a loan, formatted according to directions below.

Given the principal P, or amount borrowed, annual interest rate R in percent form, and term of the loan T in years, write a modularized C++ program that will calculate the monthly mortgage payment MP according to:

MP = (( P * i ) / ( (1 + i)t – 1 / ( 1 + i )t)) = ( P * i )( 1 + i )t / (( 1 + i )t – 1)

where i is the monthly interest rate (as a decimal, not a percent) and t is the term of the loan in months.

Generate an amortization schedule of payments, and for each month (beginning with month 0 when the loan is taken out), output a table with the following column headings:

Month #

Balance Owed

Interest Accrued (over that month)

Payment Made (at end of the month)

For each month the interest paid should be the interest accrued during that month, and the payment made should be the payment made at the end of that month.

Determine the total cost of the mortgage (the sum of all the payments made), and the total interest paid over the term of the loan (the sum of all monthly interest accrued.

Prompt the user for P, R, and T (be careful with your use of R and T).

Output the results to a file and inform the user of the output file name. The output file should contain:

A summary of the input parameters and the monthly payment required, followed by the amortization table, then finally the total cost of the loan and the total interest paid.

YOU CAN ONLY USE THIS in the header

<iostream>

<iomanip>

<fstream>

<string>

<cmath>

<cstdlib>

<ctime>

<cctype>

<cstring>

DO NOT USE THS CODE ----- http://www.cplusplus.com/forum/beginner/5187/

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
ofstream outfile;
outfile.open("LoanAmortization.txt");   //Open a file.
double principal, paymentMade, principalPaymentMade, balanceOwed, interestAccrued, rate, r;
double totalCost = 0, totalInterestPaid = 0;
int term, month;
cout<<"Enter the principal amount: ";   //Read principal.
cin>>principal;
cout<<"Enter the rate of interest in percentage: ";   //Read rate of interest.
cin>>rate;
r = rate;
rate /= 100;
rate /= 12;   //Convert the percentage interest to monthly rate.
cout<<"Enter the term for remittance in months: ";   //Read term of remittance in months.
cin>>term;
cout<<"Month# BalanceOwed InterestAccrued PaymentMade "<<endl;
cout<<"0 "<<principal<<endl;
month = 1;
balanceOwed = principal;
while(month <= term)   //Calculate the required data, and print it to screen also to the output file.
{
cout<<setw(2)<<month<<" "<<fixed<<setprecision(2)<<balanceOwed<<" ";
outfile<<setw(2)<<month<<" "<<fixed<<setprecision(2)<<balanceOwed<<" ";
interestAccrued = balanceOwed * rate;
cout<<fixed<<setprecision(2)<<interestAccrued<<" ";
outfile<<fixed<<setprecision(2)<<interestAccrued<<" ";
paymentMade = (principal * rate * (pow(1+rate, term)
               /(pow (1+rate, term)-1)));
   cout<<fixed<<setprecision(2)<<paymentMade<<endl;
   outfile<<fixed<<setprecision(2)<<paymentMade<<endl;
   principalPaymentMade = paymentMade - interestAccrued;
   balanceOwed -= principalPaymentMade;
   totalCost += paymentMade;
   totalInterestPaid += interestAccrued;
   month++;
}
cout<<"The principal amount is: "<<fixed<<setprecision(2)<<principal<<endl;
outfile<<"The principal amount is: "<<fixed<<setprecision(2)<<principal<<endl;
cout<<"The rate of interest is: "<<fixed<<setprecision(2)<<r<<endl;
outfile<<"The rate of interest is: "<<fixed<<setprecision(2)<<r<<endl;
cout<<"The terms for remittance in months"<<setw(2)<<term<<endl;
outfile<<"The terms for remittance in months"<<setw(2)<<term<<endl;
cout<<"The equated monthly instalment is:"<<fixed<<setprecision(2)<<paymentMade<<endl;
outfile<<"The equated monthly instalment is:"<<fixed<<setprecision(2)<<paymentMade<<endl;
cout<<"The total cost of the loan is: "<<fixed<<setprecision(2)<<totalCost<<endl;
outfile<<"The total cost of the loan is: "<<fixed<<setprecision(2)<<totalCost<<endl;
cout<<"The total interest paid for the loan is: "<<fixed<<setprecision(2)<<totalInterestPaid<<endl;
outfile<<"The total interest paid for the loan is: "<<fixed<<setprecision(2)<<totalInterestPaid<<endl;
cout<<"You can find the data in the file named: LoanAmortization.txt"<<endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote