Created
July 27, 2016 15:48
-
-
Save ravikiran0606/d04611ee6bb6818bedbbf4aeb40d7059 to your computer and use it in GitHub Desktop.
C++ program to create a bank class and implement some basic functions :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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