#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
static int count=0;
static long int accno=2009000;
class bank
{
public:
long int bal;
bank();
virtual void deposit(){};
virtual void withdraw(){};
virtual void view_bal(){};
};
class current : public bank
{
public:
current();
void deposit();
void withdraw();
void view_bal();
};
class savings : public bank
{
public:
savings();
void deposit();
void withdraw();
void view_bal();
};
bank::bank()
{
cout << "\nWelcome to the bank!" << endl;
cout << "Your account number : " << ++accno << endl;
}
current ::current()
{
long int temp;
cout<< "Current Account"<< endl;
cout<< "Enter the amount to be deposited. Minimum amount - Rs.20000" << endl;
cin >> temp;
while(temp<20000)
{
cout << "Amount insufficient!!, re-enter" << endl;
cin >> temp;
}
bal=temp;
cout << "\nAmount successfully deposited! " << endl;
cout << "Balance : " << bal << endl;
}
void current::deposit()
{
long int temp;
cout << "\nEnter the amount to be deposited. Minimum deposit - 5000" << endl;
cin >> temp;
while(temp<5000)
{
cout << "Amount insufficient!!, re-enter" << endl;
cin >> temp;
}
cout << "\nAmount successfully deposited" << endl;
cout << "Previous balance : " << bal << endl;
bal+=temp;
cout << "Current balance : " << bal << endl;
}
void current::withdraw()
{
long int temp;
cout << "\nEnter the amount to be withdrawn. No mimimum amount need to be maintained" << endl;
cin >> temp;
cout << "\nAmount successfully withdrawn" << endl;
cout << "Previous balance : " << bal << endl;
bal-=temp;
cout << "Current balance : " << bal << endl;
}
void current::view_bal()
{
cout << "\n Balance : " << bal << endl;
}
savings :: savings()
{
long int temp;
cout<< "Current Account"<< endl;
cout<< "Enter the amount to be deposited. Minimum amount - Rs.500" << endl;
cin >> temp;
while(temp<500)
{
cout << "Amount insufficient!!, re-enter" << endl;
cin >> temp;
}
bal=temp;
cout << "\nAmount successfully deposited! " << endl;
cout << "Balance : " << bal << endl;
}
void savings::deposit()
{
long int temp;
cout << "\nEnter the amount to be deposited. Minimum deposit - 100" << endl;
cin >> temp;
while(temp<100)
{
cout << "Amount insufficient!!, re-enter" << endl;
cin >> temp;
}
cout << "\nAmount successfully deposited" << endl;
cout << "Previous balance : " << bal << endl;
bal+=temp;
cout << "Current balance : " << bal << endl;
}
void savings::withdraw()
{
long int temp;
cout << "\nEnter the amount to be withdrawn. Minimum limit : 500" << endl;
cin >> temp;
while(bal-temp < 500)
{
cout << "Minimum balance needs to be maintained. Re-enter" << endl;
cin >> temp;
}
cout << "Previous balance : " << bal << endl;
bal-=temp;
cout << "Current balance : " << bal << endl;
}
void savings::view_bal()
{
cout << "\nBalance : " << bal << endl;
}
void main()
{
clrscr();
int choice;
long int acc;
char type;
bank *ptr[15];
do
{
cout << "Enter your choice\n1.Create\n2.Deposit\n3.Withdraw\n4.Check Balance\n5.Exit" << endl;
cin >> choice;
switch(choice)
{
case 1:
{
cout<< "\nWhich type of account would you prefer?" << endl;
cout << "C.Current\nS.Savings\n" << endl;
cin >> type;
while(type!='s' && type != 'S' && type != 'c' && type!='C')
{
cout << "Invalid entry, enter 'C' or 'S'\n" << endl;
cin >> type;
}
if(type=='c' || type=='C')
{
ptr[count++]=new current;
}
else if(type=='s' || type=='S')
{
ptr[count++]=new savings;
}
break;
}
case 2:
{
cout << "\nEnter your account number" << endl;
cin >> acc;
acc=acc-2009001;
while(acc<0 || acc>=count)
{
cout << "Account number doesn't exist, enter again" << endl;
cin >> acc;
acc-2009001;
}
ptr[acc]->deposit();
break;
}
case 3:
{
cout << "\nEnter your account number" << endl;
cin >> acc;
acc=acc-2009001;
while(acc<0 || acc>=count)
{
cout << "Account number doesn't exist, enter again" << endl;
cin >> acc;
acc-2009001;
}
ptr[acc]->withdraw();
break;
}
case 4:
{
cout << "\nEnter your account number" << endl;
cin >> acc;
acc=acc-2009001;
while(acc<0 || acc>=count)
{
cout << "Account number doesn't exist, enter again" << endl;
cin >> acc;
acc-2009001;
}
ptr[acc]->view_bal();
break;
}
case 5:
exit(0);
default:
{
cout << "Invalid entry, enter again" << endl;
choice=1;
clrscr();
}
}
}while(choice<=5);
getch();
}