用C++编辑一个程序 计算贷款月还款额

来源:百度知道 编辑:UC知道 时间:2024/06/17 00:57:33
内容:一笔贷款包括以下部分:贷款金额(amount):目前假定是一个浮点数。利率(rate):目前也假定是浮点数。贷款期限(term):表示直至还清贷款的月数。编写一个程序计算月还款额。要求贷款金额,利率和贷款期限从外部输入。

最好有运行结果

#include <iosream.h>
#include<cmath>
class Loan
(public:
Loan( ):
void set( );
friend double payment( );
void display( );
private:
double amount:
double rate;
int term;
}
Loan::Loan( )
{ }
void Loan::set( )
{ cout<<"Input the amont of the loan: ";
cin>>amount;
cout<<"Input the rate of the loan: ";
cin>>rate;
cout<<"Input the term of the loan: ";
cin>>term;
}
double Loan::payment( )
{ rate=rate/1200;
return amount*rate*pow((rate+1),term)/(pow((rate+1),term)-1);
}
void Loan::display( )
{ cout<<"The amont of the loan is: "<<amount<<endl;
cout<<"The rate of the loan is: "<<rate<<endl;
cout<<"the term of the loan is: "<<term<<endl;
}
int ma