Skip to content

Instantly share code, notes, and snippets.

@ravikiran0606
Created July 27, 2016 15:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravikiran0606/d04611ee6bb6818bedbbf4aeb40d7059 to your computer and use it in GitHub Desktop.
Save ravikiran0606/d04611ee6bb6818bedbbf4aeb40d7059 to your computer and use it in GitHub Desktop.
C++ program to create a bank class and implement some basic functions :
#include<iostream>
#include<string>
using namespace std;
class bank{
string name;
int acno;
string actype;
int balance;
public:
void initialize(string n,int ano,string atype,int bal);
void deposit(int val);
void withdrawal(int val);
void display();
};
void bank:: initialize(string a,int b,string c,int d){
name=a;
acno=b;
actype=c;
balance=d;
}
void bank::deposit(int val){
balance+=val;
cout<<"\nThe new balance is "<<balance<<endl;
}
void bank::withdrawal(int val){
if(val>balance){
cout<<"\nSorry.. There is no sufficient balance..";
}
else{
balance-=val;
cout<<"\nThe new balance is "<<balance<<endl;
}
}
void bank:: display(){
cout<<"\nThe details of the Account is..";
cout<<"\nName : "<<name<<endl;
cout<<"\nAccount Number : "<<acno<<endl;
cout<<"\nAccount Type : "<<actype<<endl;
cout<<"\nBalance : "<<balance<<endl;
}
int main()
{
int i,n;
int ch,x,y;
string a,b;
cout<<"Enter the number of customers..";
cin>>n;
bank customer[n];
cout<<"\nEnter the customer details one by one ";
for(i=0;i<n;i++){
cout<<"\nCustomer : "<<i+1<<endl;
cout<<"\nEnter Name...";
cin>>a;
cout<<"\nEnter Account type...";
cin>>b;
cout<<"\nYour Account Number is.."<<i+1<<endl;
customer[i].initialize(a,i+1,b,0);
}
cout<<"\nWelcome to Bank Information Center :D ";
cout<<"\nChoice : \n1) Know your Account Inf. \n2) Deposit an amount. \n3) Withdraw an amount. \n4) Exit :P";
while(1){
cout<<"\nEnter your choice..";
cin>>ch;
if(ch==1){
cout<<"\nEnter your Account Number..";
cin>>x;
customer[x-1].display();
}
else if(ch==2){
cout<<"\nEnter the Account Number and the Amount to be deposited..";
cin>>x>>y;
customer[x-1].deposit(y);
}
else if(ch==3){
cout<<"\nEnter the Account Number and the Amount to be withdrawn..";
cin>>x>>y;
customer[x-1].withdrawal(y);
}
else{
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment