Develop a C++ program for the loan schemes of gold loan and car loan using pure virtual functions. The bank detail consists of data members such as bank name and branch name. The savings account consists of data members such as grams and price. The current account consists of data members such as salary and loan_limit. The member functions are getdetails() and display().
#include <iostream>
#include <string>
using namespace std;
class Bank {
private:
string name;
string branchName;
public:
Bank(){}
virtual void getDetails()=0 {//Pure Virtual Function
cout<<"Enter the bank name: ";
getline(cin,name);
cout<<"Enter the bank branch name: ";
getline(cin,branchName);
}
virtual void displayDetails()=0{
cout<<"The bank name: "<<name<<"\n";
cout<<"The bank branch name: "<<branchName<<"\n";
}
~Bank(){
}
};
class SavingsAccount: public Bank{
private:
double grams;
double price;
public:
SavingsAccount(){}
void getDetails(){
Bank::getDetails();
cout<<"Enter the savings account grams: ";
cin>>grams;
cin.ignore();
cout<<"Enter the savings account price: ";
cin>>price;
cin.ignore();
}
void displayDetails(){
Bank::displayDetails();
cout<<"The savings account grams: "<<this->grams<<"\n";
cout<<"The savings account price: "<<this->price<<"\n";
}
~SavingsAccount(){
}
};
class CurrentAccount: public Bank{
private:
double salary;
double loan_limit;
public:
CurrentAccount(){}
void getDetails(){
Bank::getDetails();
cout<<"Enter the current account salary: ";
cin>>salary ;
cin.ignore();
cout<<"Enter the current account loan limit: ";
cin>>loan_limit;
cin.ignore();
}
void displayDetails(){
Bank::displayDetails();
cout<<"The current account grams: "<<this->salary<<"\n";
cout<<"The current account loan limit: "<<this->loan_limit<<"\n";
}
~CurrentAccount(){
}
};
int main(){
Bank *bank;
cout<<"Savings account bank\n";
SavingsAccount savingsAccount;
bank = &savingsAccount;
bank->getDetails();
bank->displayDetails();
cout<<"\nCurrent account bank\n";
CurrentAccount currentAccount;
bank = ¤tAccount;
bank->getDetails();
bank->displayDetails();
system("pause");
return 0;
}
Comments
Leave a comment