Question: // This program is a driver written to demonstrate how we can use a // class inside another one. #include using namespace std; class ID

// This program is a driver written to demonstrate how we can use a // class inside another one. #include using namespace std;

class ID { public: ID( ); ID(int, int, int); void display(); private: int left; int middle; int right; };

class Loan // Loan is called structure tag { public: Loan( ); Loan(ID id, float amount, float rate, int term); void set( ); float payment( ); void display( ); private: ID 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 };

int main( ) { Loan loan1(ID(111,22,4444), 2300, 5.5, 48); // initialize to values given

Loan loan2;

cout << "Display loan1 "; loan1.display();

loan2.set( ); // set the values cout << "Display loan2 "; loan2.display();

return 0; }

ID::ID( ) { // use default values }

ID::ID(int l, int m, int r) { left = l; middle = m; right = r; }

void ID::display() { cout << right << "-" << middle << "-" << right << endl; }

Loan::Loan( ) { }

Loan::Loan(ID I, float am, float rt, int trm) { id = I; amount = am; rate = rt; term = trm; }

void Loan::set( ) { int l, m, r; ID temp_id; // Initialize the loan1 object cout << "Enter the left part of the loan ID "; cin >> l; cout << "Enter the middle part of the loan ID "; cin >> m; cout << "Enter the right part of the loan ID "; cin >> r;

id = ID(l, m, r);

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() { id.display(); cout << amount << endl; cout << rate << endl; cout << term << endl; }

Here is the list of file names:

1) main_prog.cpp This is the main program

2) ID.cpp This file keeps the implementation of class ID 3) ID.h This file keeps the definition of class ID 4) Loan.cpp This file keeps the implementation of class Loan 5) Loan.h This file keeps the definition of class Loan

Write the above program in five different files as described by the comments at the top of each section. Once you have created the 5 files, include the ID.h and Loan.h file in the main. Make the changes in the other .h files so they will be visited twice.

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 Databases Questions!