Bank Project C++

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

#include<iostream>

#include <fstream>
#include<string>
#include<ctime>
using namespace std;
static int num=1000;
/***************************************
*
ACCOUNT CLASS
*
***************************************/
class account
{
protected:
double
double
double
string
public:
double

balance;
withdraw;
deposite;
type;
accno;

void random()
{
ofstream acc;
srand(time(0));
acc.open("ACCOUNT.txt",ios::app);
accno=rand()%num;
acc<<"\n"<<accno;
num++;
}
virtual void withdrawfunction()=0;

//virtual function

virtual void depositfuntion()=0;

//virtual function

virtual void display()=0;

//virtual function

double getrandom()
{
return accno;
}
};
/***************************************
*
CURRENTACC CLASS
*
***************************************/
class currentacc :public account
{
public:
string choice;
double pasword[100];
currentacc()
{
balance=0;
withdraw=0;

deposite=0;
}
void withdrawfunction()
{
cout<<"ENTER AMOUNT YOU WANT TO WITHDRAW"<<endl;
cin>>withdraw;
for(int i=0;i<100;i++)
{
if(withdraw<balance)
{
cout<<"AMOUNT WITHDRAWN"<<endl;
balance=balance-withdraw;
cout<<"NOW YOUR BALANCE IS="<<balance<<endl;
i=101;
}
else if(withdraw>balance)
{
cout<<"YOUR DONT HAVE THIS AMOUNT OF MONEY IN YOUR ACCOUNT"<<endl;
cin>>withdraw;
i=0;
}
}
}
void depositfuntion()
{
cout<<endl;
cout<<"****PROCESSING"<<endl;
cout<<endl;
cout<<"YOU HAVE ENTERED CURRENT ACCOUNT"<<endl;
cout<<"PLEASE ENTER YOUR DEPOSITE AMOUNT."<<endl<< "xx:WARNING YOUR AMOUNT SHOULD
NOT BE LESS THAN 2000:xx"<<endl;
cin>>deposite;
for(int i=0;i<100;i++)
{
if(deposite>=2000)
{
balance=balance+deposite;
cout<<"YOUR BALANCE IS"<<endl;
cout<<balance<<endl;
i=101;
}
else if (deposite<2000)
{
cout<<"YOUR DEPOSITE AMOUNT IS LESS THAN 2000"<<endl;
cin>>deposite;
i=0;
}
}
}
void settype1(string type)
{
this->type=type;
}
string gettype1()
{
return type;
}

void display()
{
cout<<"YOUR BALANCE="<<balance;
}
void accountpasword(int i)
{
{
try
//exceptional handling
{
cout<<"DO YOU WANT ATM CARD"<<endl;
cin>>choice;
if(choice=="yes")
{
throw choice;
}
cout<<"YOU CHOOSE NO ATM CARD"<<endl;
}
catch(string e)
{

cout<<"YOU CHOSE ATM CARD"<<endl;


cout<<"ENTER YOUR PASWORD"<<endl;
cin>>pasword[i];
}
}
}
void getpasword(int i)
{
if(choice=="yes")
{
cout<<"\nYOUR ATM PASWORD"<<endl;
cout<<pasword[i]<<endl;
}
}
};
/***************************************
*
SAVINGACC CLASS
*
***************************************/
class savingacc:public account
{
protected:
double profit;
public:
string choi;
double pasi[100];
savingacc()
{
balance=0;
withdraw=0;
deposite=0;
profit=0;

}
void withdrawfunction()
{
cout<<"ENTER AMOUNT YOU WANT TO WITHDRAW"<<endl;
cin>>withdraw;
for(int i=0;i<100;i++)
{
if(withdraw<balance)
{
cout<<"AMOUNT WITHDRAWN"<<endl;
balance=balance-withdraw;
cout<<"NOW YOUR BALANCE IS="<<balance<<endl;
i=101;
}
else if(withdraw>balance)
{
cout<<"YOUR DONT HAVE THIS AMOUNT OF MONEY IN YOUR ACCOUNT"<<endl;
cin>>withdraw;
i=0;
}
}
}
void depositfuntion()
{
cout<<endl;
cout<<"****PROCESSING"<<endl;
cout<<endl;
cout<<"YOU HAVE ENTERED SAVING ACCOUNT"<<endl;
cout<<"PLZ ENTER YOUR DEPOSITE AMOUNT WARNING YOUR AMOUNT SHOULD NOT BE
LESS THAN 2000"<<endl;
cout<<"YOU WILL GET 10% PROFIT AFTER EVERY MONTH"<<endl;
cin>>deposite;
for(int i=0;i<100;i++)
{
if(deposite>=2000)
{
balance=balance+deposite;
cout<<"YOUR BALANCE IS"<<endl;
cout<<balance<<endl;
i=101;
}
else if (deposite<2000)
{
cout<<"YOUR DEPOSITE AMOUNT IS LESS THAN 2000"<<endl;
cin>>deposite;
i=0;
}
}
}
double operator+(savingacc o)
//operator overloading
{
profit=balance+(o.balance*10)/100;
return profit;
}
void settype2(string type)
{
this->type=type;
}

string gettype2()
{
return type;
}
void display()
{
cout<<"YOUR BALANCE="<<balance;
}
void accountpasi(int i)
{
{
try
//exceptional handling
{
cout<<"DO YOU WANT ATM CARD"<<endl;
cin>>choi;
if(choi=="yes")
{
throw choi;
}
cout<<"YOU CHOOSE NO ATM CARD"<<endl;
}
catch(string e)
{
cout<<"YOU CHOSE ATM CARD"<<endl;
cout<<"ENTER YOUR PASWORD"<<endl;
cin>>pasi[i];

}
}
}
void getpasi(int i)
{
if(choi=="yes")
{
cout<<endl;
cout<<"\nYOUR ATM PASWORD"<<endl;
cout<<pasi[i]<<endl;
}
}
};
/***************************************
*
CUSTOMER CLASS
*
***************************************/
class customer
{
protected:
string name;
double age;
string address;
string id;
public:
currentacc s1;
savingacc s2;

//composition
//composition

public:
void setname(string name)
{
this->name=name;
}
void setage(double age)
{
this->age=age;
}
void setaddress(string address)
{
this->address=address;
}
void setid(string id)
{
this->id=id;
}
string getname()
{
return name;
}
double getage()
{
return age;
}
string getaddress()
{
return address;
}
string getid()
{
return id;
}
void set1(string a)
{
s1.settype1(a);
}
void set2(string b)
{
s2.settype2(b);
}
double operator+()
{
return(s2+s2);
}
};
/***************************************
*
ATM CLASS
*
***************************************/
class atm
{
public:
savingacc *n;
currentacc *l;

//aggregation
//aggregation

void setobject2(savingacc *o)


{
n=o;
}
void setobject(currentacc *k)
{
l=k;
}
void dis(int i)
{
l->accountpasword(i);
}
void dis1(int i)
{
n->accountpasi(i);
}
void go(int i)
{
l->getpasword(i);
}
void go2(int i)
{
n->getpasi(i);
}
double hell(int i)
{
return l->pasword[i];
}
double hell2(int i)
{
return n->pasi[i];
}
};

void
{

main()
int size=10;
int inc=0;
customer *s=new customer[size];
atm *f=new atm[size];
currentacc *m=new currentacc[size];
savingacc *p=new savingacc[size];
int choice;
string a,b,c,e;
double accountnum;
double d;
string dele;
do
{
cout<<"\t\t**********************************"<<endl;
cout<<"\t\t*
BANK OF BAROOD
*"<<endl;

cout<<"\t\t**********************************"<<endl;
cout<<" ========================================================"<<endl;
cout<<"| PRESS 1 TO OPEN A NEW ACCOUNT
|"<<endl;
cout<<"| PRESS 2 IF YOUR ACCOUNT ALREADY EXIST
|"<<endl;
cout<<"| PRESS 3 TO CLOSE ACCOUNT
|"<<endl;
cout<<"| PRESS 4 TO SEARCH YOUR ACCOUNT
|"<<endl;
cout<<"| PRESS 5 FOR ATM CARD
|"<<endl;
cout<<"| PRESS 6 TO READ FROM FILE
|"<<endl;
cout<<"| PRESS 7 TO EXIT
|"<<endl;
cout<<" ========================================================"<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
ofstream transaction;
transaction.open("ACCOUNT.txt",ios::app);
cout<<"NEW ACCOUNT"<<endl;
cout<<endl;
cout<<"PLEASE ENTER YOUR NAME"<<endl;
cin>>a;
transaction<<"\n"<<a;
s[inc].setname(a);
cout<<"PLEASE ENTER YOUR AGE"<<endl;
cout<<"(YOUR AGE SHOULD NOT BE LESS THAN 18)"<<endl;
cin>>d;
transaction<<"\n"<<d;
for(int i=0;i<100;i++)
{
if(d>=18)
{
s[inc].setage(d);
i=101;
}
else if(d<18)
{
cout<<"INVLAID AGE"<<endl;
cin>>d;
i=0;
}
}
cout<<"PLEASE ENTER YOUR ADDRESS"<<endl;
cin>>c;
transaction<<"\n"<<c;
s[inc].setaddress(c);
cout<<"PLEASE ENTER YOUR ID"<<endl;
cin>>b;
transaction<<"\n"<<b;
s[inc].setid(b);
cout<<"PLEASE ENTER TYPE OF ACCOUNT"<<endl;
cin>>e;
transaction<<"\n"<<e;
for(int i=0;i<100;i++)
{
if(e=="current")
{
cout<<endl;
s[inc].s1.random();

cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER IS"<<endl;
cout<<s[inc].s1.getrandom()<<endl;
cout<<"-----------------------"<<endl;
s[inc].set1(e);
s[inc].s1.depositfuntion();
cout<<endl;
f[inc].setobject(m);
cout<<endl;
f[inc].dis(inc);
i=101;
inc++;
}
else if(e=="saving")
{
cout<<endl;
s[inc].s2.random();
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER IS"<<endl;
cout<<s[inc].s2.getrandom()<<endl;
cout<<"-----------------------"<<endl;
s[inc].set2(e);
s[inc].s2.depositfuntion();
cout<<"YOUR BALANCE AFTER MONTH WILL BE"<<endl;
cout<<s[inc].operator+()<<endl;
cout<<endl;
f[inc].setobject2(p);
cout<<endl;
f[inc].dis1(inc);
i=101;
inc++;
}
else
{
cout<<"INVALID STATEMENT"<<endl;
cin>>e;
i=0;
}
}
if(size == inc)
{
customer *temp =new customer [size];
for(int i=0; i<inc; i++)
temp[i] = s[i];
delete[] s;
size += 2;
s =new customer[size];
for(int i=0; i<inc; i++)
s[i] = temp[i];
}
transaction.close();
}
break;
case 2:
cout<<"DO YOU WANT TO DEPOSITE OR WITHDRAW"<<endl;
cout<<"PRESS 1 FOR DEPOSITE"<<endl;
cout<<"PRESS 2 FOR WITHDRAW"<<endl;
cin>>choice;

if(choice==1)
{
cout<<"PLEASE ENTER YOUR ACCOUNT NUMBER"<<endl;
cin>>accountnum;
for(int i=0;i<size;i++)
{
if(accountnum==s[i].s1.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s1.gettype1()<<endl;
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s1.getrandom()<<endl;
cout<<"-----------------------"<<endl;
cout<<endl;
s[i].s1.depositfuntion();
}
else if(accountnum==s[i].s2.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s2.gettype2()<<endl;
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s2.getrandom()<<endl;
cout<<"-----------------------"<<endl;
cout<<endl;
s[i].s2.depositfuntion();
cout<<"YOUR BALANCE AFTER ONE MONTH WILL BE"<<endl;
cout<<s[i].operator+()<<endl;
}
}
}
else if(choice==2)
{
cout<<"PLEASE ENTER YOUR ACCOUNT NUMBER"<<endl;
cin>>accountnum;
for(int i=0;i<size;i++)
{
if(accountnum==s[i].s1.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s1.gettype1()<<endl;
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s1.getrandom()<<endl;
cout<<"-----------------------"<<endl;
cout<<endl;
s[i].s1.withdrawfunction();
}
else if(accountnum==s[i].s2.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s2.gettype2()<<endl;

cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s2.getrandom()<<endl;
cout<<"-----------------------"<<endl;
cout<<endl;
s[i].s2.withdrawfunction();
cout<<"YOUR BALANCE AFTER MONTH WILL BE"<<endl;
cout<<s[i].operator+()<<endl;
}
}
}
break;
case 3:
cout<<"YOU WANT TO CLOSE YOUR ACCOUNT"<<endl;
cout<<"PLEASE ENTER YOUR ACCOUNT NUMBER"<<endl;
cin>>accountnum;
for(int i=0;i<size;i++)
{
if(accountnum==s[i].s1.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR AGE="<<s[i].getage()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ADDRESS"<<s[i].getaddress()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s1.gettype1()<<endl;
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s1.getrandom()<<endl;
cout<<"-----------------------"<<endl;
cout<<"PRESS Y TO DELETE YOUR ACCOUNT"<<endl;
cin>>dele;
if(dele=="y")
{
s[i].setname("");
s[i].setage(0);
s[i].setid("");
s[i].setaddress("");
s[i].s1.settype1("");
s[i].s1.accno=0;
}
}
else if(accountnum==s[i].s2.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR AGE="<<s[i].getage()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ADDRESS"<<s[i].getaddress()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s2.gettype2()<<endl;
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s2.getrandom()<<endl;
cout<<"-----------------------"<<endl;
cout<<"PRESS Y TO DELETE YOUR ACCOUNT"<<endl;
cin>>dele;
if(dele=="y")
{

s[i].setname("");
s[i].setage(0);
s[i].setid("");
s[i].setaddress("");
s[i].s2.settype2("");
s[i].s2.accno=0;
}
}
}
break;
case 4:
{
cout<<"YOU WANT TO SEARCH YOUR ACCOUNT"<<endl;
cout<<"PLEASE ENTER YOUR ACCOUNT NUMBER"<<endl;
cin>>accountnum;
for(int i=0;i<size;i++)
{
if(accountnum==s[i].s1.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR AGE="<<s[i].getage()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ADDRESS"<<s[i].getaddress()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s1.gettype1()<<endl;
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s1.getrandom()<<endl;
cout<<"-----------------------"<<endl;
s[i].s1.display();
f[i].go(i);
cout<<endl;
}
else if(accountnum==s[i].s2.getrandom())
{
cout<<"YOUR ACCOUNT EXIST"<<endl;
cout<<"YOUR NAME="<<s[i].getname()<<endl;
cout<<"YOUR AGE="<<s[i].getage()<<endl;
cout<<"YOUR ID="<<s[i].getid()<<endl;
cout<<"YOUR ADDRESS"<<s[i].getaddress()<<endl;
cout<<"YOUR ACCOUNT TYPE="<<s[i].s2.gettype2()<<endl;
cout<<"-----------------------"<<endl;
cout<<"YOUR ACCOUNT NUMBER="<<s[i].s2.getrandom()<<endl;
cout<<"-----------------------"<<endl;
s[i].s2.display();
f[i].go2(i);
cout<<endl;
}
}
}
break;
case 5:
{
double pasn;
cout<<"ENTER YOUR ACCOUNT NUMBER"<<endl;
cin>>accountnum;

for(int i=0;i<size;i++)
{
if(accountnum==s[i].s1.getrandom())
{
cout<<"ENTER PASWORD"<<endl;
cin>>pasn;
if(pasn==f[i].hell(i))
{
s[i].s1.withdrawfunction();
}
}
else if(accountnum==s[i].s2.getrandom())
{
cout<<"ENTER PASWORD"<<endl;
cin>>pasn;
if(pasn==f[i].hell2(i))
{
s[i].s2.withdrawfunction();
}
}
}
}
break;
case 6:
string data;
// open a file in read mode.
ifstream infile;
infile.open("ACCOUNT.txt",ios::in||ios::beg);
cout << "Reading from the file" << endl;
infile.tellg();

int count = 1;
//reading file line by line
while(!infile.eof())
{
infile >> data;
//cout<<count<<endl;
cout << data << endl;

count++;
}
// close the opened file.
infile.close();
break;

}
}while(choice!=7);
}

You might also like