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

2025-02-23 00:21:34
推荐回答(2个)
回答1:

#include
#include
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: "<cout<<"The rate of the loan is: "<cout<<"the term of the loan is: "<}
int main( )
{ double monthly_payment;
Loan loan1;
loan1.set( );
monthly_payment=loan1.payment( );
loan1.display( ):
cout<<"The payment of the loan is: "<return 0;
}
解法二:
#include
#include
class Loan
(public:
Loan( ):
void set( );
double payment(Loan&);
void display( );
private:
double amount:
double rate;
int term;
double monthly_payment;
}
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( Loan&l)
{ l.rate=l.rate/1200;
return l.amount*l.rate*pow((l.rate+1),l.term)/(pow((l.rate+1),l.term)-1);
}
void Loan::display( )
{ cout<<"The amont of the loan is: "<cout<<"The rate of the loan is: "<cout<<"The term of the loan is: "<cout<<"The payment of the loan is: "<}
int main( )
{ Loan loan1;
loan1.set( );
loan1.payment(loan1);
loan1.display( );
return 0;
}

回答2:

作你这道题还需要有经济知识 不简单。