Question #301807

Writing a small program for Bank Management System.

In this program, we are using the concept of C++ class and object, following basic

operations are being performed:

• Deposit

• Withdraw

In this program, we have created a class Bank with the following member functions:

• Deposit() – It will ask for the amount to be added in available balance, and deposit

the amount.

• Withdrawal() – It will ask for the amount to be withdrawn from the available, will

also check the available balance, if balance is available, it will deduct the amount

from the available balance.


Expert's answer



#include <iostream>
#include <iomanip>
using namespace std;




class Account{
private:
	double balance;
public:	
	Account(){
		this->balance=0;
	}
	void Deposit(double am){
		this->balance=am;
	}
	void Withdraw (double am){
		if(this->balance>=am){
			this->balance-=am;
		}
	}


	void displayDetails(){
		cout<<"The account balance is: "<<this->balance<<"\n\n";
	}
	~Account(){


	}
};


int main(){


	Account* account=new Account();
	int ch=-1;
	double amount;
	while(ch!=4){
		cout<<"1 - Deposit, 2 - Withdraw, 3 - Display balance, 4 - Exit: ";
		cin>>ch;
		switch(ch){
		case 1:{
			cout<<"Enter amount to deposit: ";
			cin>>amount;
			account->Deposit(amount);
			   }
			   break;
		case 2:{
			cout<<"Enter amount to withdraw: ";
			cin>>amount;
			account->Withdraw(amount);
			   }


			   break;
		case 3:{
			account->displayDetails();
			   }
			   break;
		case  4:{
			//exit
				}
				break;
		default:{


				}
				break;
		}
	}


	delete account;
	system("pause");
	return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS