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().
Runtime Input :
1356
Nitin
6
#include<iostream>
#include<string>
using namespace std;
class Bank_ACC
{
private:
int accno;
string name;
public:
virtual void get(){
cout<<"Enter the accno of the account holder: ";
cin>>accno;
cin.ignore();
cout<<"Enter the name of the account holder: ";
getline(cin,name);
}
virtual void display()
{
cout<<"The accno of the account holder: "<<accno<<"\n";
cout<<"The name of the account holder: "<<name<<"\n";
}
};
class SB_ACC : public Bank_ACC
{
private:
float roi;
public:
void get(){
Bank_ACC::get();
cout<<"Enter the rate of interest of the account holder: ";
cin>>roi;
}
void display()
{
Bank_ACC::display();
cout<<"The rate of interest of the account holder: "<<roi<<"\n";
}
};
class CURR_ACC : public Bank_ACC
{
private:
int odlimit;
public:
void get(){
Bank_ACC::get();
cout<<"Enter the limit of the account holder: ";
cin>>odlimit;
}
void display()
{
Bank_ACC::display();
cout<<"The limit of the account holder: "<<odlimit<<"\n";
}
};
int main(){
//array of pointers
Bank_ACC** accounts=new Bank_ACC*[5];
for(int i=0;i<5;i++){
int choice=0;
while(choice<1 || choice>2){
cout<<"1. Add a new Saving Bank Account\n";
cout<<"2. Add a new Current Bank Account\n";
cout<<"Your choice: ";
cin>>choice;
cin.ignore();
}
if(choice==1){
SB_ACC* SBACC=new SB_ACC();
SBACC->get();
accounts[i]=SBACC;
}
if(choice==2){
CURR_ACC* CURRACC=new CURR_ACC();
CURRACC->get();
accounts[i]=CURRACC;
}
}
for(int i=0;i<5;i++){
accounts[i]->display();
delete accounts[i];
}
system("pause");
return 0;
}
Comments
Leave a comment