For this assignment please complete the following exercise. Submit your complete
ID: 2247085 • Letter: F
Question
For this assignment please
complete
the
following exercise. Submit
your completed
source code
(*.cpp) and screenshots
demonstrating you successfully ran the program by the due date.
========
Mortgage Class
Design a class
that will represent a
home mortgage. The constructor should accept the loan
amount, interest
rate,
and
number of years
to pay off the loan.
The class
should have member
functions for returning the monthly
payment amount and
the
total
amount paid to the
bank at the end
of the loan period.
The monthly
payment with interest
compounded
monthly can be calculated as follows:
where
Payment = the monthly payment
Loan = the dollar amount of the loan
Rate
= the annual interest rate
Years =
the number of years
of the
loan
Utilize the class in a complete program. Run the
program at least
three times with
different
values to
demonstrate it works correctly.
Input Validation: Do not accept negative numbers for any of
the
loan values.
values to
demonstrate it works correctly.
Input Validation: Do not accept negative numbers for any of
the
loan values.
Explanation / Answer
/* *program : for calculating the mortgage loan. program uses constructor that accepts the loan amount, rate and years and the function to calculate the monthly payment, amount to be paid to bank at the end */
#include <cstdlib>
# include<math.h>
#include<iostream>
using namespace std;
/*
* Mortage calculator
*/
class Mortage{
public :
double payment, loan, rate, total, final_amount;
int years, term;
//parameterized constructor for accepting loan amount, rate, no.of years
Mortage(double x, double y, int z){
loan = x;
rate = y;
years = z;
}
/* month_pay() member function to calculate the compound interest of the
loan to be paid monthly*/
double month_pay(){
term = years*12;
total = ((loan * rate) / (1 - pow(1+rate,-term)));
return total;
}
/*total_amount() calculate the final amount to be paid for the bank*/
double total_amount(){
int term = years*12;
final_amount = term * month_pay();
return final_amount;
}
};
int main(int argc, char** argv) {
double l,r;
int yrs,choice;
// accept the loan amount, rate, no.of years
cout<<" Enter the loan Amount:";
cin>>l;
cout<<" Enter the Rate :";
cin>>r;
cout<<" Enter the No. of Years :";
cin>>yrs;
// perform the function if its positive values
if((l>0)and(r>-1)and(yrs>0)){
r = r/100;
Mortage m1(l,r,yrs);
cout<<" monthly amount to be paid : " <<m1.month_pay();
cout<< " final amount to be paid to bank : "<<m1.total_amount();
}
//if the value is negative display the comment
else
{
cout<<"For calculating the loan amount, enter positive values";
}
return 0;
}
sample output:
Enter the loan Amount:50000
Enter the Rate :4.5
Enter the No. of Years :8
monthly amount to be paid : 2283.37
final amount to be paid to bank : 219204
output 2:
Enter the loan Amount:40000
Enter the Rate :-5
Enter the No. of Years :6
For calculating the loan amount, enter positive values
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.