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

Design a class that will determine the monthly payment on a home mortgage. The m

ID: 3548974 • Letter: D

Question

Design a class that will determine the monthly payment on a home mortgage. The monthly payment with interest compounded monthly is calculated as

Payment=(loan?(rate/12)?term)(term?1)

where term=(1+rate/12)12?years
Payment is monthly payment
Loan is dollar amount of loan
Rate is annual interest rate
Years is number of years of loan.

Your loan class should have member functions for setting the loan amount, interest rate, and number of years of the loan. It should also have member functions for returning the monthly payment amount and the total amount paid to the bank at the end of the loan period. In addition your loan class should have a print member function that outputs to standard out all relevant facts of the loan: loan amount, years, rate, payment, and total payments. Input validation: do not accept negative values for loan values or loans over 2,000,000.00. Use double precision numbers and be sure to sanity check payment calculation results. Incorrect numerical answers will lose at least half credit. You are not explected to be able to derive the loan payment formula only implement it in C++.

Create two loans: The first for $200,000.00, 15 years, with a 8% rate and the second for $600,000.00, 30 years, with a 9% rate and find the monthly payments for each

Explanation / Answer

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
class mortage
{
private:
double loan_amount;
double interest_rate;
int number_of_years;
public:
mortage(double l_n=0.0,double i_r=0.0,int n=0)
{
setLoan_amount(l_n);
setInterest_rate(i_r);
setNumber_of_years(n);
}
void setLoan_amount(double l_n)
{
if(l_n<=0 || l_n>2000000)
loan_amount = 0;
else
loan_amount = l_n;
}
void setInterest_rate(double i_r)
{
interest_rate = i_r;
}
void setNumber_of_years(int n)
{
number_of_years = n;
}
double monthly_payment()
{
double term = pow((1+ interest_rate/12),12*number_of_years);
double payment = (loan_amount*interest_rate/12*term)/(term-1);
return payment;
}
double amount_paid()
{
return number_of_years*12*monthly_payment();
}
// a print member function that outputs to standard out all relevant facts of the loan:
// loan amount, years, rate, payment, and total payments.
void print()
{
cout << "Loan Amount is " << loan_amount << endl;
cout << "Number of years is " << number_of_years << endl;
cout << "Interest Rate is " << interest_rate << endl;
cout << "Monthly Payment is " << monthly_payment() << endl;
cout << "Total Payment is " << fixed << setprecision(14) << amount_paid() << endl;
}
};

int main()
{
mortage Loan_1(200000,8/100.0,15);
mortage Loan_2(600000,9/100.0,30);
// print details for loan 1
Loan_1.print();
// print details for loan 2
Loan_2.print();
return 0;
}

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