Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the above program or the ex63.cpp program to include constructors that help perform the same computation as requested in Exercise 6.3. Call your new

Modify the above program or the ex63.cpp program to include constructors that help perform the same computation as requested in Exercise 6.3. Call your new program ex64.cpp.

(NEED TO INCLUDE CONSTRUCTORS IN THESE CODE)

#include #include #include

using namespace std;

class Loan // creamos una clase de nombre Loan

{

public:

void set();

float payment();

void display();

float add_loans(Loan, Loan); // la funcion de add loans que pidio crear

float monthly_payment; // el data member que pidio crear

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

};

// function to set the parameters of the loan

void Loan::set()

{

// Initialize the loan1 object

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;

}

float Loan::add_loans(Loan loan1, Loan loan2)

{

return loan1.monthly_payment + loan2.monthly_payment;

}

float Loan::payment()

{

float monthly_rate = rate / 1200;

return monthly_payment = (amount * monthly_rate * (pow((monthly_rate + 1), term) / (pow((monthly_rate + 1), term) - 1)));

}

void Loan::display()

{ cout << endl; cout << " ID :" << ID; cout << endl; cout << fixed << setprecision(2) << " Amount : $" << amount; cout << endl; cout << " Annual Rate : " << fixed << setprecision(2) << rate << "%"; cout << endl; cout << " Term : " << term << " months";

}

int main() {

Loan loan1;

cout << "ID 1:"; cout << endl;

loan1.set();

loan1.display();

float p = loan1.payment(); cout << endl; cout << " Monthly payment : $" << fixed << setprecision(2) << p; cout << endl; cout << endl;

Loan loan2; cout << "ID 2:"; cout << endl;

loan2.set();

loan2.display();

p = loan2.payment(); cout << endl; cout << " Monthly payment : $" << fixed << setprecision(2) << p; cout << endl; cout << endl;

float total_mon_payment = loan1.add_loans(loan1, loan2); cout << "The total Monthly payment sum : $" << fixed << setprecision(2) << total_mon_payment ; cout << endl; cout << endl; return 0;

}

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago