Answer to Question #193342 in C++ for Sivasurya

Question #193342

Develop a C++ programs on BANKING SYSTEM have Customer class with name, address and phoneno. Create derived class account class with data members like account number, name, deposit, withdraw amount and type of account. A customer can deposit and withdraw amount in his account. Develop a C++ program to display the details of a customer and the remaining balance amount. [Note: Use virtual function]


1
Expert's answer
2021-05-14T04:18:08-0400
#include <iostream>
#include <string>
using namespace std;




class Customer {
private:
	// name, address and phoneno.
	string name;
	string address;
	string phoneno;


public:	
	Customer(){}
	


	void getDetails(){
		cout<<"Enter the customer name: ";
		getline(cin,name);
		cout<<"Enter the customer address: ";
		getline(cin,address);
		cout<<"Enter the customer phone no: ";
		getline(cin,phoneno);
	}
	void virtual displayDetails(){
		cout<<"The customer name: "<<name<<"\n";
		cout<<"The customer address: "<<address<<"\n";
		cout<<"The customer phone no: "<<phoneno<<"\n";
	}


	~Customer(){


	}
};


class Account: public Customer{
private:
	// account number, name, deposit, withdraw amount and type of account.
	int accountNumber;
	string accountName;
	double amount;
	string type;




public:	
	Account(){
		this->amount=0;
	}


	void deposit(double am){
		this->amount=am;
	}
	void withdraw (double am){
		if(this->amount>am){
			this->amount-=am;
		}
	}
	void getDetails(){
		Customer::getDetails();
		cout<<"Enter the account number: ";
		cin>>accountNumber;
		cin.ignore();
		cout<<"Enter the account name: ";
		getline(cin,accountName);
		cout<<"Enter the account type: ";
		getline(cin,type);
	}
	void displayDetails(){
		Customer::displayDetails();
		cout<<"The account number: "<<this->accountNumber<<"\n";
		cout<<"The account name: "<<this->accountName<<"\n";
		cout<<"The account type: "<<this->type<<"\n";
		cout<<"The account balance amount: "<<this->amount<<"\n\n";


	}
	~Account(){


	}
};


int main(){
	
	Account* account=new Account();
	account->getDetails();
	account->displayDetails();


	account->deposit(500);
	account->withdraw(50);


	account->displayDetails();


	system("pause");
	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