Write a C++ program to create a class bank to deposit an amount,withdraw an amount,balance amount using multiple object.
#include<iostream>
using namespace std;
class bank{
private:
string customerName;
int accountNumber;
string account_type;
double bal;
public:
bank(string c, int number, string t, double b){
customerName = c;
accountNumber = number;
account_type = t;
bal = b;
}
void deposit(int amount){
bal = bal + amount;
cout<<"The amount deposited successfully. \nYour balance is: "<<bal;
}
void withdraw(int amount){
if(amount>bal){
cout<<"Insufficient funds in your account.\n";
}
else{
bal = bal - amount;
cout<<amount<<"Withdrawn successfully. \nYour balance is: "<<bal<<endl;
}
}
void viewBalance(){
cout<<"Your balance is: "<<bal;
}
};
int main(){
cout<<"Enter the customer name\n";
string customerName;
cin>>customerName;
cout<<"Enter the account number\n";
int accountNumber;
cin>>accountNumber;
cout<<"Account type\n";
string account_type;
cin>>account_type;
cout<<"Enter initial balance\n";
double bal;
cin>>bal;
bank b(customerName,accountNumber,account_type,bal);
int x;
do{
cout<<"\n\nSelect an option.\n1. Deposit.\n2. Withdraw.\n3.View Balance\n";
cout<<"0. Enter 0 to exit the program\n";
cin>>x;
if(x==1){
cout<<"Enter amount to deposit\n";
int amount;
cin>>amount;
b.deposit(amount);
}
else if(x==2){
cout<<"Enter amount to withdraw\n";
int amount;
cin>>amount;
b.withdraw(amount);
}
else if(x==3){
b.viewBalance();
}
}while(x !=0);
cout<<"Terminated successfully\n";
}
Comments
Leave a comment