Implementing using
class Loan
Sample Run:
Enter yearly interest rate, for example 8.25: 10
Enter number of years as an integer, for example 5: 5
Enter loan amount, for example 120000.95: 300000
The monthly payment is 6374.11
The total payment is 382446.80
#include<iostream>
using namespace std;
class Loan{
private:
double rate;
int years;
double ammount;
public:
void enterRate(double r){
this->rate=r;
}
void enterYears(int y){
this->years=y;
}
void enterAmmount(double a){
this->ammount=a;
}
double getMonthlyPayment(){
return ammount*(1+rate/100)/years*12;
}
double getTotalPayment(){
return ammount*(1+rate/100);
}
};
int main(){
// test
Loan test;
int tempi; double tempd;
cout<<"Ammount:";
cin>>tempd;
test.enterAmmount(tempd);
cout<<"Rate:";
cin>>tempd;
test.enterRate(tempd);
cout<<"Years:";
cin>>tempi;
test.enterYears(tempi);
cout<<"Monthly payment is:"<<test.getMonthlyPayment()<<endl;
cout<<"Total payment is:"<<test.getTotalPayment()<<endl;
return 0;
}
Comments
Leave a comment