Question
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
########## ID.cpp ##########
// File ID.cpp #include
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
########## Loan.cpp ##########
//Loan.cpp //header files #include
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started