Question: I need help with how to make this in my program : Modify the class Loan by including monthly_payment as a data member of the

I need help with how to make this in my program :

Modify the classLoanby includingmonthly_paymentas a data member of theLoanclass and by adding a new member function, calledadd_loans,defined as:

float add_loans(Loan loan1, Loan loan2);

The new function,add_loans,takes two loan objects and computes the total monthly payment, i.e., the sum of monthly payments of the two loans. Note that you still have thepaymentfunction that computes the payment.Since you include theadd_loansas a member function, you can directly set the value formonthly_paymentin that function and call thepaymentfunction if required.

#include

using namespace std;

class Loan {

public:

void set(); // This function will initialize the data members of an object

float payment();// This function will compute the monthly payment for a loan object

void display(); // This function will display a loan object

private:

int ID;// assume an unique integer between 1111-9999

float amount; // $ amount of the loan

float rate; // annual interest rate

int term;// number of months, length of the loan

float monthly_payment;

};

int main() {

float p;

float monthly_payment;

Loan loanl;

loanl.set();

loanl.display();// will display the data members of loan1

p = loanl.payment(); // will return the monthly payment of loan1

system("PAUSE");

return 0;

}

float Loan::payment()// function formula to compute payment

{

rate = rate / 1200;// To convert % yearly rate to monthly fraction

return amount * rate*(pow((rate + 1), term) / (pow((rate + 1), term) - 1));

}

void Loan::set()

{

cout << "Enter the ID of this loan ";

cin >> ID;

cout << "Enter the amount of this loan ";

cin >> amount;

cout << "Enter the annual interest rate of this loan (in %) ";

cin >> rate;

cout << "Enter the term (number of months, length of the loan) ";

cin >> term;

}

void Loan::display() {

cout << "The monthly payment for loan " << ID << " is: " << monthly_payment << ". The Rate will be: "

<< rate << ", the Term be: " << term << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!