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

*******************This needs to written using functions and the Mortgage Table

ID: 3787345 • Letter: #

Question

*******************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.


I have it programmed, but I don't know how to account for the tax per year of $350, and which amount is which in the columns: I need to add the columns so they line up properly. How do you add , in the big amounts?

#include
#include
#include
#include

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 (in months): ";
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;
outFile.open("MortgageTablePgmV2_Results.txt");

outFile << "Principal $" << pV << " Payment $" << emi << endl;
outFile << "Annual Interest " << fixed << setprecision(1) << roI * 12 * 100 << "% Term " << noP << " Months" << endl;
outFile << "Monthly Payments Interest Principal PrincipalBalance" << 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 << " " << i + 1 << " " << fixed << setprecision(2) << interest << " " << principal << " " << pV << endl;
  
}
outFile << "Final Payment " << 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;

}

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

Explanation / Answer

You need to add two more variable for the Tax in the main program.

//double tax,tan_pm;

From the above program you have used the readInputs function to get the values from the user,just get tax also from the user by rewriting the function by adding one more parameter tax.Get the value of tax by using the cin and cout same like how you get other values.

we need write one more function now just to calculate the tax.say 'tax_calc'.

You can write the function easily by using the logic given below:

double No_of_Payments_in_years=numOfPayments/12

//To get the number of years we are going to pay the tax.

double totalTax = tax* No_of_Payments_in_years;

//To get the total amount of the tax we are going the pay.

double tax_pm = totalTax/NumOfPayments

//Now we know how much tax we are going to pay for each month.

thats it!!!....Now we just need to add them in table.

we must need to rewrite printtable functions.Just add one more parameter to the function 'tax_pm'.

Now we need to rerwrite a single line in the for loop inside.

rewrite \pV = pV - principal with \pV = pV - principal + tax.

Now to write in the out file we may need to couple of changes:

1.Rewrite '\outFile << "Monthly Payments Interest Principal PrincipalBalance" << endl;' with

'\outFile << "Monthly Payments Interest Principal Tax PrincipalBalance" << endl;'

-Here i am just adding one more column for the TAX.

2.Rewrite '\outFile << " " << i + 1 << " " << fixed << setprecision(2) << interest << " " << principal << " " << pV << endl;' with

'\outFile << " " << i + 1 << " " << fixed << setprecision(2) << interest << " " << principal << " " << tax_pm << "\t" << pV << endl;

-Here we just populating the tax variable.