Answer to Question #301807 in C++ for anoo

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.


1
Expert's answer
2022-02-23T12:18:10-0500


#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;
}

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