Answer to Question #173491 in C++ for praveenkumar.b

Question #173491

Develop a code for the hierarchical inheritance for banking account, 

·    The Bank_ACC base class consisting of data members such as accno and name, and member functions get() and display().

·    The SB_ACC derived class inherited from Bank_ACC class, consisting of data members such as roi, and member functions get() and display().

·  The CUR_ACC derived class inherited from Bank_ACC class, consisting of data members such as odlimit, and member functions get() and display().


1
Expert's answer
2021-03-28T08:05:40-0400
#include <iostream>
#include <string>
 
using namespace std;
 
class Bank_ACC
{
public:
	Bank_ACC(int accno_, string name_)
	{
		accno = accno_;
		name = name_;
	}
	string GetName() { return name; }
	int GetAccno() { return accno; }
	void Display();
private:
	int accno;
	string name;
};
 
void Bank_ACC::Display()
{
	cout << "Account number is: " << GetAccno() << endl;
	cout << "Account name is: " << GetName() << endl;
}
 
class SB_ACC : public Bank_ACC
{
public:
	SB_ACC(int accno_, string name_, double roi_);
	double GetRoi() { return roi; }
	void Display();
private:
	double roi;
};
 
SB_ACC::SB_ACC(int accno_, string name_, double roi_) : Bank_ACC(accno_, name_), roi(roi_)
{}
 
void SB_ACC::Display()
{
	Bank_ACC::Display();
	cout << "ROI is: " << GetRoi() << endl;
}
 
class CURR_ACC : public Bank_ACC
{
public:
	CURR_ACC(int accno_, string name_, string odlimit_);
	string GetOldimit() { return oldimit; }
	void Display();
private:
	string oldimit;
};
 
CURR_ACC::CURR_ACC(int accno_, string name_, string oldimit_) : Bank_ACC(accno_, name_), oldimit(oldimit_)
{}
 
void CURR_ACC::Display()
{
	Bank_ACC::Display();
	cout << "Oldimit is: " << GetOldimit() << endl;
}
 
int main()
{
	SB_ACC sb_acc(100, "Mike", 0.25);
	sb_acc.Display();
	cout << endl;
	CURR_ACC curr_acc(120, "Brian", "True");
	curr_acc.Display();
	cout << endl;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS