Pages

Friday, September 9, 2016

C++ Program for Bank

Program-

#include<iostream>
using namespace std;

class Bank
{
class DOB
{
int dd,mm,yyyy;
public:
void getDate()
{
cout<<"\nEnter Birth Date\n";
cout<<"\nD ate [dd] ";
cin>>dd;
cout<<"Month [mm] ";
cin>>mm;
cout<<"Year [yyyy] ";
cin>>yyyy;
}
void showDate()
{
cout<<"\nBirth Date- "<<dd<<"/"<<mm<<"/"<<yyyy;
}
};
int acc_no;
char name[30],acc_type[20];
double balance;
DOB dt;

public:
static int no_of_acc;

void assignData(int acno)
{
acc_no=acno;
cout<<"Enter account type ";
cin>>acc_type;
cout<<"Enter name ";
cin>>name;
dt.getDate();
balance=0.0;
no_of_acc++;
}
int searchAccNumber(Bank b[],int acno)
{
for(int i=0;i<no_of_acc;i++)
{
if(b[i].acc_no==acno)
return i;
}
return -1;
}

void showData()
{
cout<<"\nAccount number "<<acc_no;
cout<<"\nAccount type "<<acc_type;
cout<<"\nNAme "<<name;
cout<<"\nCurrent Balance "<<balance;
dt.showDate();
}

void depositAmount()
{
double amt;
cout<<"Enter amount to deposit";
cin>>amt;
if(amt>0)
{
balance+=amt;
cout<<"amount deposited, current balance= Rs."<<balance;
}
else
cout<<"invalid amount ";
}

void withdrawAmount()
{
double amt;
cout<<"enter amt to withdraw";
cin>>amt;
if(amt<=balance && amt>0)
{
balance-=amt;
cout<<"amt withdrawn, current balance Rs."<<balance;
}
else
cout<<"invalid amt entered";
}

static void getTotalAccounts()
{
cout<<"Total number of a/c="<<no_of_acc;
}
};
int Bank::no_of_acc;

int main()
{
int flag=1,ch,i,acno;
Bank b[10];
cout<<"1. Open a/c \n2. Deposit money \n3. Withdraw amt \n4. A/c info and bal\n5. Total no. of A/c\n6. Exit";
while(flag==1)
{
cout<<"\nEnter choice ";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter A/c no.";
cin>>acno;
i=b[0].searchAccNumber(b,acno);
if(i==-1)
b[Bank::no_of_acc].assignData(acno);
else
cout<<"\n A/c no. already exists";
break;

case 2: cout<<"enter a/c no.";
cin>>acno;
i=b[0].searchAccNumber(b,acno);
if(i!=-1)
b[i].depositAmount();
else
cout<<"\nInvalid a/c no.";
break;

case 3: cout<<"enter a/c no.";
cin>>acno;
i=b[0].searchAccNumber(b,acno);
if(i!=-1)
b[i].withdrawAmount();
else
cout<<"\n Invalid a/c no";
break;

case 4: cout<<"enter a/c no.";
cin>>acno;
i=b[0].searchAccNumber(b,acno);
if(i!=-1)
b[i].showData();
else
cout<<"\n Invalid a/c no";
break;

case 5: Bank::getTotalAccounts();
break;

case 6: flag=0;

}
}
return 0;
}


Output-

1. Open a/c
2. Deposit money
3. Withdraw amt
4. A/c info and bal
5. Total no. of A/c
6. Exit
Enter choice 1
Enter A/c no.123
Enter account type saving
Enter name Rajesh

Enter Birth Date

D ate [dd] 26
Month [mm] 02
Year [yyyy] 1993

Enter choice 2
enter a/c no.123
Enter amount to deposit50000
amount deposited, current balance= Rs.50000
Enter choice 1
Enter A/c no.456
Enter account type saving
Enter name Divyam

Enter Birth Date

D ate [dd] 19
Month [mm] 08
Year [yyyy] 1994

Enter choice 4
enter a/c no.123

Account number 123
Account type saving
NAme Rajesh
Current Balance 50000
Birth Date- 26/2/1993
Enter choice 5
Total number of a/c=2
Enter choice 6

No comments:

Post a Comment