Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions