#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: "<
int main( )
{ double monthly_payment;
Loan loan1;
loan1.set( );
monthly_payment=loan1.payment( );
loan1.display( ):
cout<<"The payment of the loan is: "<
}
解法二:
#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: "<
int main( )
{ Loan loan1;
loan1.set( );
loan1.payment(loan1);
loan1.display( );
return 0;
}
作你这道题还需要有经济知识 不简单。