Sample C++ Program On Banking
Sample C++ Program On Banking
#include <fstream.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<dos.h>
void password(void)
int counter=0;
char username[20];
char password[15];
char str[20];
fstream user;
fstream pass;
user.open("username.dat",ios::binary|ios::in|ios::out);
pass.open("password.dat",ios::binary|ios::in|ios::out);
do
clrscr();
cout<<"\n\n\t\t ";
gets(username);
user.read((char*) &str,sizeof(str));
user.close();
if(strcmp(str,username)==0)
{
clrscr();
cout<<"\n\n\n\n\n\t\t\tPASSWORD ";
cout<<"\n\n\t\t ";
gets(password);
pass.read((char*) &str,sizeof(str));
pass.close();
if(strcmp(str,password)==0)
{ clrscr();
cout<<"\n\n\n\n\t\t\tACCESS ALLOWED....";
delay(1500);
return;
else
cout<<"\n\n\t\t\tACCESS DENIED!!!!";
delay(2500);
continue;
counter++;
}while(counter<3);
clrscr();
cout<<"\n\n\n\n\n\n\t\t\t";
for(int i=0;i<35;i++)
{ cout<<arr[i];
delay(50);
}
cout<<"....";
delay(2500);
exit(0);
class account
char first_name[50],last_name[50],address[100],city[50],state[50];
char phone_number[25],pincode[25];
public:
account()
amount=0.00;
deposit=0.00;
rate = 0.0;
ifstream fin;
fin.open("acctno.dat",ios::in);
fin>>acctno;
fin.close();
void addnewrecord();
void viewrecord();
void updaterecord();
void read();
int get_acctno();
void display();
};
/*
This method is for adding a new account record. The details are added in the dat file
accountdets.dat.
*/
void account::addnewrecord()
ofstream outfile;
outfile.open("accountdets.dat",ios::out|ios::binary|ios::app);
account person;
gets(person.first_name);
gets(person.last_name);
gets(person.address);
gets(person.city);
gets(person.state);
gets(person.phone_number);
cin>>person.deposit;
ofstream fout;
fout.open("acctno.dat",ios::out);
fout<<acctno;
fout.close();
outfile.close();
/*
This method is used for reading the account number input from the user.
*/
void account::read()
cin>>accno;
/*
This method returns the account number that is input by the user.
*/
int account::get_acctno()
return accno;
/*
This method is used for viewing the account details from the dat file, given a
specific account number as input.
*/
void account::viewrecord()
ifstream f2;
account t2,t02;
t02.read();
f2.open("accountdets.dat",ios::binary|ios::in);
f2.seekg(0,ios::beg);
int j=0;
while(!f2.eof())
f2.read((char*) &t2,sizeof(t2));
if(t2.acctno==t02.get_acctno())
j=1;
t2.display();
break;
}
}
if(j!=1)
f2.close();
getch();
/*
This method is used by the viewrecord method to output the specific account record
details.
*/
void account::display()
cout<<"\n";
<<"Address : "<<address<<"\n"
<<"City : "<<city<<"\n"
<<"State : "<<state<<"\n"
<<"Deposit : "<<deposit<<"\n";
/*
This method is used for updating an account record based on various options.
*/
void account::updaterecord()
int ch2,debit,credit;
do{
clrscr();
cout<<"\n\nPlease";
cin>>ch2;
clrscr();
switch(ch2)
case 1:
fstream f3;
account t3,t03;
t03.read();
cin>>debit;
f3.open("accountdets.dat",ios::binary|ios::in|ios::out);
f3.seekg(0,ios::beg);
while(!f3.eof())
{
f3.read((char*) &t3,sizeof(t3));
if(t3.acctno==t03.get_acctno())
j++;
break;
count++;
if(j!=0)
if(debit<=t3.deposit)
t3.deposit-=debit;
f3.seekp(count*sizeof(t3),ios::beg);
if(t3.deposit>=250)
else
else
}
f3.close();
getch();
break;
}//case 1
case 2:
fstream f4;
account t4,t04;
t04.read();
cin>>credit;
f4.open("accountdets.dat",ios::binary|ios::in|ios::out);
f4.seekg(0,ios::beg);
while(!f4.eof())
f4.read((char*) &t4,sizeof(t4));
if(t4.acctno==t04.get_acctno())
j++;
break;
count++;
}
if(j!=0)
t4.deposit+=credit;
f4.seekp(count*sizeof(t4),ios::beg);
else
f4.close();
getch();
break;
}//case 2
case 3:
fstream f6;
account t6,t06;
int j=0;
t06.read();
f6.open("accountdets.dat",ios::binary|ios::in|ios::out);
f6.seekg(0,ios::beg);
while(!f6.eof())
{
f6.read((char*) &t6,sizeof(t6));
if(t6.acctno==t06.get_acctno())
j++;
break;
if(j!=0)
cout<<"\n\nTheACCOUNT BALANCE is Rs
"<<t6.deposit;
else
f6.close();
getch();
break;
}//case 3
case 4:
fstream f5;
account t5,t05;
t05.read();
f5.open("accountdets.dat",ios::binary|ios::in|ios::out);
f5.seekg(0,ios::beg);
while(!f5.eof())
f5.read((char*) &t5,sizeof(t5));
if(t5.acctno==t05.get_acctno())
cin>>timeperiod;
rate=1.5*timeperiod;
interest=t5.deposit*timeperiod*(rate/100.0);
cout<<"\nInterest is Rs "<<interest;
amount=t5.deposit + interest;
cout<<"\nAmount is Rs "<<amount;
if(amount==0)
j=1;
break;
if(j==0)
break;
}//case 4
getch();
ch2=6;
break;
default:cout<<"\n\n\t\t\tinvalid entry!!!!";
getch();
break;
}//switch ch2
}while(ch2<6);
}//updaterecord
void main()
password();
char crep,cstr[20];
int irep;
l:clrscr();
if(crep=='y' || crep=='Y')
ofstream of;
cin>>irep;
switch(irep)
case 1:
of.open("username.dat",ios::binary|ios::out);
gets(cstr);
of.write((char*) &cstr,sizeof(cstr));
of.close();
break;
case 2:
of.open("password.dat",ios::binary|ios::out);
gets(cstr);
of.write((char*) &cstr,sizeof(cstr));
of.close();
break;
default:
goto l;
}
account obj;
int ch;
do
clrscr();
cout<<"\n\t\t\t ==========================";
cout<<"\n\t\t\t ==========================\n";
cout<<"\t4. Exit\n";
cin>>ch;
clrscr();
int in=0;
switch(ch)
case 1:
obj.addnewrecord();
break;
case 2:
obj.viewrecord();
break;
case 3:
obj.updaterecord();
break;
case 4:
clrscr();
for(in=0;in<6;in++)
{cout<<'.';delay(1500);}
clrscr();
cout<<"\n\n\n\n\n\t\t\t....Terminating....";
delay(2500);
exit(0);
default:
cout<<"\n\t\t\tinvalid entry!!!!";
getch();
break;
}while(ch<10);