0% found this document useful (0 votes)
66 views1 page

C++ - Mortgage Payment Calculation Program - CPP

The document contains C++ code for a Mortgage class that calculates monthly mortgage payments based on the principal amount, yearly interest rate, and number of years. It includes methods to compute the payment using the formula for an amortizing loan. The main function prompts the user for input values and outputs the calculated mortgage payment.

Uploaded by

soat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views1 page

C++ - Mortgage Payment Calculation Program - CPP

The document contains C++ code for a Mortgage class that calculates monthly mortgage payments based on the principal amount, yearly interest rate, and number of years. It includes methods to compute the payment using the formula for an amortizing loan. The main function prompts the user for input values and outputs the calculated mortgage payment.

Uploaded by

soat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <cstdio>

#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
class Mortgage
{
public:
Mortgage (float fAb, float fYI, int nYEARS)
: fAborrowed(fAb), fYint(fYI), nyears(nYEARS)
{}
float PMT ()
{ float fMint=(fYint/(12*100));
// A = D[i(1 + i)^n]/[(1 + i)^n - 1]
one_plus_i_to_n = pow( (1+fMint), (nyears*12) );
fPAmount = fAborrowed * (fMint * one_plus_i_to_n) /
(one_plus_i_to_n -1);
return (fPAmount);
}
private:
float fMint;
float fPAmount;
float fAborrowed;
float fYint;
float one_plus_i_to_n;
int nNM;
int nyears;
};

int main ()
{
float Principal =0;
float Yint=0;
int nY=0;
float Payment;
cout << "Enter Principal " << endl;
cin >> Principal;
cout << "Enter Yearly Interest Rate " << endl;
cin >> Yint;
cout << "Enter number of years " << endl;
cin >> nY;
Mortgage M (Principal, Yint, nY);
Payment=M.PMT();
cout << "Mortgage Payment --> " << M.PMT() << endl;
return 0;
}

You might also like