Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Question Need help getting program to compile. The results that need to be displayed are 111-22-4444. What we were supposed to do was define

C++ Question

Need help getting program to compile. The results that need to be displayed are 111-22-4444. What we were supposed to do was define a new namespace which in this case is "idclass1" and use it in the loan class. I'm not entirely sure how to implement this into the loan.h and loan.cpp file. Please fix my coding and implement the use of namespace "idclass1" into loan.h and loan.cpp and make sure it compiles with the main_prog.cpp. PS: this is for CS1 so don't use anything crazy and please leave small comments as to what it does. +

Here is the code:

########## Main_prog.cpp ##########

// This program is a driver written to demonstrate how we can use // namespaces #include #include "ID.h"; using namespace std; // This part will go to the main program, main_prog.cpp int main() { using namespace idclass1; ID id1; id1 = ID(111, 22, 4444); id1.display(); return 0; }

########## ID.cpp ##########

// File ID.cpp #include #include "ID.h" using namespace idclass1; 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; }

########## ID.h ##########

// File ID.h #ifndef ID_H #define ID_H #include namespace idclass1 { class ID { public: ID(); ID(int, int, int); void display(); private: int left; int middle; int right; }; } // end of idclass1 namespace #endif

########## Loan.cpp ##########

//Loan.cpp //header files #include #include "ID.h" #include "Loan.h" using namespace std; //Loan constructor 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; }

########## Loan.h ##########

//Loan.h #ifndef LOAN_H #define LOAN_H

#include #include "ID.h" using namespace std;

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 }; #endif LOAN_H

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions