You are on page 1of 4

#include<iostream.

h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
class ATM{
private:
ifstream in;
ofstream out;
int pins[40];
char fname[40][20];
char lname[40][20];
char id[40][10];
int age[40];
char sex[40];
long pno[40];
long acn[40];
double balance[40];
public:
void loadData(){
in.open("customer.txt");
int i=0;
while(in>>fname[i]){
in>>lname[i];
in>>id[i];
in>>sex[i];
in>>age[i];
in>>pno[i];
in>>acn[i];
i++;
}
in.close();
in.open("pins.txt");
i=0;
while(in>>pins[i]){
i++;
}

in.close();
in.open("balance.txt");
i=0;
while(in>>balance[i]){
i++;
}
in.close();
}
int getPin(int index){
return pins[index];
}
void setPin(int index,int value){
pins[index]=value;
out.open("pins.txt");
for(int i=0;i<40;i++)
out<<pins[i]<<endl;
out.close();
}
double getBalance(int index){
return balance[index];
}
void setBalance(int index,double value){
balance[index]=value;
out.open("balance.txt");
for(int i=0;i<40;i++)
out<<balance[i]<<endl;
out.close();
}
void getName(char to_Fname[],char toLname[],int index){
strcpy(to_Fname,fname[index]);
strcpy(toLname,lname[index]);
}
int getAccountNoIndex(long accNo){
for(int i=0;i<40;i++){
if(accNo==acn[i]){
return i;
}
}
return -1;
}
int login(){
char pin[4];
for(int i=0;i<4;i++){
pin[i]=getch();
cout<<'*';
}
int n=atoi(pin);
for( i=0;i<40;i++){
if(n==pins[i])
return i;
}
return -1;
}
int menu(int index){
int c;
do{
clrscr();
cout<<"-------------------------------------------"<<endl;
cout<<" Welcome "<<fname[index]<<" "<<lname[index]<<endl;
cout<<" Enter your choice:@ "<<endl;
cout<<" 1.check balance \n2.withdraw \n3.deposit \n4.transfer \n5.change pin
\n6.exit "<<endl;
cout<<"-------------------------------------------"<<endl;
cin>>c;
}while(c<0||c>6);
return c;
}
};
int main(){
ATM myAtm;
myAtm.loadData();
cout<<"---------------------------------------"<<endl;
cout<<"Welcome to commercial bank of Ethiopia:"<<endl;

int index,recIndex,curPin,newPin;
int trial=0;
int choice;
double amount;
cout<<"Enter your pin to login:"<<endl;
cout<<"---------------------------------------"<<endl;
do{
index = myAtm.login();
cout<<endl;
if(index==-1){
trial++;
cout<<"Wrong pin Enter again:";
}else{
break;
}
}while(trial<3);
if(trial==3){
cout<<"To many trials your Account has been blocked"<<endl;
getch();
exit(0);
}
choice=myAtm.menu(index);
do{
switch(choice){
case 1:
cout<<"your current balance is "<<myAtm.getBalance(index)<<"
ETB."<<endl;
break;
case 2:
cout<<"Enter amount:"<<endl;
cin>>amount;
if(amount>myAtm.getBalance(index))
cout<<"You cannot withdraw with your current balance."<<endl;
else{
myAtm.setBalance(index,myAtm.getBalance(index)-amount);
cout<<"You have successfully withdrawn from your account"<<endl;
cout<<"your current balance is "<<myAtm.getBalance(index)<<"
ETB."<<endl;
}
break;
case 3:
//deposit
cout<<"Enter amount to save:"<<endl;
cin>>amount;
if(amount<50||amount>25000)
cout<<"Amount cannot be less than 50 ETB or greater than
25000."<<endl;
else{
myAtm.setBalance(index,myAtm.getBalance(index)+amount);
cout<<"You have successfully Deposited"<<endl;
}
break;
case 4:
//transfer
long acn;
cout<<"Enter account number:"<<endl;
cin>>acn;
recIndex=myAtm.getAccountNoIndex(acn);
if(recIndex==-1)
cout<<"Invalid account number."<<endl;
else{
cout<<"Enter amount:"<<endl;
cin>>amount;
if(amount>myAtm.getBalance(index))
cout<<"You cannot transfer with your current balance."<<endl;
else if(amount<100||amount>1000)
cout<<"Amount cannot be less than 100 or 1000 ETB."<<endl;
else{
char n[20],ln[20];
char confirm;
myAtm.getName(n,ln,recIndex);
cout<<"You are about to transfer "<<amount<<" ETB to "<<n<<"
"<<ln<<endl;
cout<<"ARE YOU SHURE?(Y/N)"<<endl;
cin>>confirm;
if(confirm=='y'||confirm=='Y'){
myAtm.setBalance(index,myAtm.getBalance(index)-amount);
myAtm.setBalance(recIndex,myAtm.getBalance(recIndex)+amount);
cout<<"You have successfully transfered from your account"<<endl;
cout<<"your current balance is "<<myAtm.getBalance(index)<<"
ETB."<<endl;
}else
cout<<"Transfer canceled"<<endl;
}
}
break;
case 5:
//change pin
cout<<"Enter your current pin:"<<endl;
cin>>curPin;
if(curPin==myAtm.getPin(index)){
cout<<"Enter new pin:"<<endl;
cin>>newPin;
if(newPin<0||newPin>9999)
cout<<"Enter 4 digit number"<<endl;
else{
myAtm.setPin(index,newPin);
cout<<"You have successfully changed your pin."<<endl;
}
}else{
cout<<"Invalid pin"<<endl;
}
break;
case 6:
exit(0);
}
cout<<"press any key for menu,6 to exit."<<endl;
char c=getch();
if(c=='6')
exit(0);

choice=myAtm.menu(index);
}while(choice!=6);
return 0;
}

You might also like