You are on page 1of 9

Bank Program

============================================
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
template <class type>

class List{

public:

List() { }
List(int s)
{
maxSize=s;
used=0;
a=new type[maxSize];
}

int getUsed(){return used;}


int getMaxSize(){return maxSize;}

bool isEmpty(){return used==0;}

bool isFull(){return used==maxSize;}

bool addObject(type obj)


{
if(!isFull())
{
a[used]=obj;
used++;
return true;
}
else
return false;
}

bool getObject(int index, type &obj)


{
if(!isEmpty())
{
if( (index>=0) && (index<used) )
{
obj=a[index];
return true;
}
else
return false;
}
else
return false;
}

bool setObject(int index, type obj)


{
if( (index>=0) && (index<used) )
{
a[index]=obj;
return true;
}
else
return false;
}

private:
type *a;
int maxSize;
int used;
};

/*======= Account Class =======*/

class Account{

public:
Account(){ }
Account(char *t, int no, double bal)
{
strcpy(title,t);
acNo=no;
balance=bal;
}

void setTitle(char *t){strcpy(title,t);}


void setAcNo(int no){acNo=no;}
void setBalance(double bal){balance=bal;}

char *getTitle(){return title;}


int getAcNo(){return acNo;}
double getBalance(){return balance;}

bool deposit(double amt)


{
if(amt>0)
{
balance+=amt;
return true;
}
else
return false;
}

bool withdraw(double amt)


{
if(amt<=balance)
{
balance-=amt;
return true;
}
else
return false;
}

private:
char title[30];
int acNo;
double balance;
};

/*======= Bank Class =======*/


class Bank{
public:

Bank(){}
Bank(int s):ls(s){}

/*======= Open Account =======*/

bool openAccount(Account obj)


{
if(ls.addObject(obj))
return true;
else
return false;

/*======= Search =======*/

int search(int key)


{
int i=0;
Account t;
ls.getObject(i,t);
while( (key!=t.getAcNo() ) && ( i<ls.getUsed() ) )
{
i++;
ls.getObject(i,t);
}
if(i<ls.getUsed())
return i;
else
return -1;
}

/*======= Account Status =======*/

double getBalanceStatus(int acNo)


{
int i=search(acNo);
if(i!=-1)
{
Account t;
ls.getObject(i,t);
return t.getBalance();

}
else
return -1;
}

/*======= Debit =======*/


bool debit(int acNo, double amt)
{
int i=search(acNo);
if(i!=-1)
{
Account t;
ls.getObject(i,t);
if(t.withdraw(amt))
{
ls.setObject(i,t);
return true;
}
else
return false;
}
else
return false;
}

/*======= Credit =======*/

bool credit(int acNo, double amt)


{
int i=search(acNo);
if(i!=-1)
{
Account t;
ls.getObject(i,t);
if(t.deposit(amt))
{
ls.setObject(i,t);
return true;
}
else
return false;
}
else
return false;
}

/*======= Show All =======*/

void showAll()
{
system("cls");

for(int i=0; i<ls.getUsed(); i++)


{
Account t;
ls.getObject(i,t);

cout<<"\n\n================================
============================================
===";
cout<<"\nTitle: "<<t.getTitle();
cout<<"\nAccount No: "<<t.getAcNo();
cout<<"\nBalance: "<<t.getBalance();

cout<<"\n==================================
============================================
=";

private:
List<Account>ls;
};

/*======= Client Program =======*/

void main()
{
int no,ch;
cout<<"\nEnter the no of Accounts you want to Open: ";
cin>>no;
Bank b(no);
do{
cout<<"\n[1] Open Account";
cout<<"\n[2] Get Account Balance";
cout<<"\n[3] Debit";
cout<<"\n[4] Credit";
cout<<"\n[5] Show Status of all Accounts";
cout<<"\n[6] Exit";
cout<<"\nEnter yr Choice: ";
cin>>ch;

switch(ch){

case 1:
{
char title[30];
int acNo;
double amt;
for(int i=0; i<no; i++)
{
system("cls");
Account t;
cout<<"\nEnter the Title: ";
cout.flush();
gets(title);
t.setTitle(title);
cout<<"\nEnter the Account no: ";
cin>>acNo;
t.setAcNo(acNo);
cout<<"\nEnter the Amount you want to
add in yr Account: ";
cin>>amt;
t.setBalance(amt);
b.openAccount(t);

break;
} // Case 1: End

case 2:
{

int acNo;
cout<<"\nEnter Account no: ";
cin>>acNo;
system("cls");

cout<<"\n\n================================
============================================
===";
cout<<"\nBalace in Account "<<acNo<<" is
"<<b.getBalanceStatus(acNo);

cout<<"\n==================================
============================================
=";
break;
} // Case 2: End

case 3:
{
int acNo;
double amt;
cout<<"\nEnter the Account no: ";
cin>>acNo;
cout<<"Enter the Amount that you want to
Withdraw: ";
cin>>amt;
if(b.debit(acNo,amt))
cout<<"\nAmount Withdraw
Successfully.....";
else
cout<<"Sorry";
break;
} // Case 3: End

case 4:
{

int acNo;
double amt;
cout<<"\nEnter the Account no: ";
cin>>acNo;
cout<<"Enter the Amount that you want to
Add: ";
cin>>amt;
if(b.credit(acNo,amt))
cout<<"\nAmount Added
Successfully....";
else
cout<<"\nSorry! Amount not added ";

break;
} // Case 4: End
case 5:
{
b.showAll();
break;
} // Case 5: End

case 6:
{
exit(0);
break;
}
default:
cout<<"\nInvalid Option";

} // End Switch
cout.flush();
getch();
system("cls");
}while(ch!=6);
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006