Вы находитесь на странице: 1из 11

#include<iostream.

h>
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<iomanip.h>
#include<graphics.h>
//Defining Class Bank//
class bank_acc
{
private:
struct cust
{
char flag;
char acno[10];
char name[20];
char add[15];
char city[15];
char state[15];
int pin;
char tele1[15];
char tele2[15];
char fax[15];
char nomineel[15];
char nominee2[15];
char acc_type;
float balance;
}bank;
fstream file;
public:
bank_acc();
void welcome_screen();
void addrec();
void disprec();
float deposit();
float withdraw();
void modirec();
void del_t();
void del_p();
void searchrec();
void exit();
};
//Zero argument constructor
void bank_acc::bank_acc()
{
file.open("bank.dat",ios::binary|ios::in|ios::out);
if(!file)
{
cout<<endl;
cout<<"unable to open file";
exit( );
}
}
//adding records to the file at end
void bank_acc::addrec()
{
char ch;
file.seekp(0L,ios::end);
do
{
cout<<"Enter Data"<<endl;
cout<<"Enter Customer Name : ";
cin>>bank.name;
cout<<"Enter Account Number : ";
cin>>bank.acno;
cout<<endl<<"Enter Customer Address : ";
cin>>bank.add;
cout<<endl<<"Enter City and State Name : ";
cin>>bank.city>>bank.state;
cout<<endl<<"Enter Telephone No.(Office) : ";
cin>>bank.tele1;
cout<<endl<<"Enter Telephone No.(Res.) : ";
cin>>bank.tele2;
cout<<endl<<"Enter Fax No. : ";
cin>>bank.fax;
cout<<endl<<"Enter Account Type (S-Saving C-Current) : ";
cin>>bank.acc_type;
cout<<"Enter Balance : ";
cin>>bank.balance;
bank.flag='*';
file.write((char*)&bank,sizeof(bank));
cout<<"Do You Want To Add Another Record...(Y/N)? : ";
cin>>ch;
}while(ch=='y'||ch=='Y');
getch( );
}
//Modifies a given records from the file
void bank_acc::modirec()
{
char acc[10];
char ch;
int count=0;
long int pos;
do
{
cout<<"Enter Account No. : ";
cin>>acc;
//position get pointer at the beginning of file

file.seekg(0L,ios::beg);

//search for account number


while(file.read((char*)&bank,sizeof((bank))))
{
//if read is found
if(strcmp(bank.acno,acc)==0)
{
//Receive new record
cout<<endl<<"Enter new records"<<endl;
cout<<endl<<"Enter Customer Name : ";
cin>>bank.name;
cout<<"Enter Account Number : ";
cin>>bank.acno;
cout<<endl<<"Enter Customer Address : ";
cin>>bank.add;
cout<<endl<<"Enter City and State Name : ";
cin>>bank.city>>bank.state;
cout<<endl<<"Enter Telephone No.(Office) : ";
cin>>bank.tele1;
cout<<endl<<"Enter Telephone No.(Res.) : ";
cin>>bank.tele2;
cout<<endl<<"Enter Fax No. : ";
cin>>bank.fax;
cout<<endl<<"Enter Account Type (S-Saving C-Current) : ";
cin>>bank.acc_type;
cout<<"Enter Balance : ";
cin>>bank.balance;
bank.flag=' ';
//position put pointer such that the
//existing record is overwritten
pos=count*sizeof(bank);
file.seekg(pos,ios::beg);
file.write((char*)&bank,sizeof(bank));
count++;
}
}
if(bank.flag!=' ')
{
cout<<endl<<"No. Employees in the record with Account Number : "<<acc;
cout<<endl<<"press any key.....";
getch();
}
cout<<"Modify Another Record...(Y/N)? : ";
cin>>ch;
}while(ch=='y'|| ch=='Y');
file.clear( );
}

//searching a record
void bank_acc::searchrec()
{
char acc[10];
int count=0;
long int pos; cout<<"Enter Account Number To Be Searched : ";
cin>>acc;
//position get pointer at the beginning of the file
file.seekg(0L,ios:: beg);
//search for account number
while(file.read((char*)&bank,sizeof(bank)))
{
//if record is found
if(strcmp(bank.acno,acc)==0)
{
bank.flag='*' ;
// position put pointer
pos=count*sizeof(bank);
file.seekp(pos,ios::beg);
cout<<endl<<"ABC BANK PVT.LTD."<<endl;
cout<<endl<<"Customer Name : ";
cout<<bank.name;
cout<<endl<<"Account Number : ";
cout<<bank.acno;
cout<<endl<<"Customer Address : ";
cout<<bank.add<<"\t";
cout<< endl<<"City and State Name:";
cout<<bank.city<<", "<<endl;
cout<<bank.state;
cout<<endl<<"Telephone No. (Office) : ";
cout<<bank.tele1;
cout<<endl<<"Telephone No. (Residence) : ";
cout<<bank.tele2;
cout<<endl<<"Fax no : ";
cout<<bank.fax;
cout<<endl<<"Account Type : ";
cout<<bank.acc_type;
cout<<endl<<"Balance : ";
cout<<bank.balance;
cout<<"Press Any Key...";
getch();
return;
}
count++;
}
cout<<endl<<"No employee in the Record with Account Number : "<<acc;
cout<<endl<<"Press Any Key.....";
getch( );
file.clear();
}

//Display Records
void bank_acc::disprec()
{
//int j=0;
int a;
//Position get pointer at the beginning of the file
file.seekg(0L,ios:: beg);
//so long as end of file is reached,
//read each record and display it
while(file.read((char*)&bank,sizeof(bank)))
{
//if record is found
if(bank.flag=='*')
{
clrscr();
cout<<endl<<"ABC BANK PVT. LTD."<<endl;
cout<<"==================";
cout<<endl<<"Customer Name : ";
cout<<bank.name;
cout<<endl<<"Account Number : ";
cout<<bank.acno;
cout<<endl<<"Customer Address : ";
cout<<bank.add<<"\t";
cout<< endl<<"City and State Name:";
cout<<bank.city<<", "<<endl;
cout<<bank.state;
cout<<endl<<"Telephone No. (Office) : ";
cout<<bank.tele1;
cout<<endl<<"Telephone No. (Residence) : ";
cout<<bank.tele2;
cout<<endl<<"Fax no : ";
cout<<bank.fax;
cout<<endl<<"Account Type : ";
cout<<bank.acc_type;
cout<<endl<<"Balance : ";
cout<<bank.balance;
getch( );
return;
}
}
cout<<endl<<"Press Any Key...";
getch( );
file.clear( );
}

//To Deposit Amount


float bank_acc::deposit()
{
char acc[10];
int count=0;
float amount;
long int pos;
cout<<"Enter Account Number : ";
cin>>acc;
cout<<"\nEnter Amount : ";
cin>>amount;
//Position get pointer at the begining of File.
file.seekg(0L,ios::beg);
//Search for Account Number.
while(file.read((char*)&bank,sizeof(bank)))
{
//if record is found.
if(strcmp(bank.acno,acc)==0)
{
bank.flag='*';
bank.balance=bank.balance-amount;
//bank.balance=bank.balance+amount;
//position put pointer such that existing record is overwritten.
pos=count*sizeof(bank);
file.seekp(pos,ios::beg);
file.write((char*)&bank,sizeof(bank));
}
count++;
}
cout<<endl<<"No employee in the Record with Account Number : "<<acc;
cout<<"Press Any Key...";
getch( );
file.clear( );
return bank.balance;
}

//To withdraw amount.


float bank_acc::withdraw()
{
char acc[10];
int count=0;
float amount;
long int pos;
cout<<"Enter Account No. : ";
cin>>acc;
cout<<"\nEnter Amount : ";
cin>>amount;
//position get pointer at the begining of the file.
file.seekg(0L,ios::beg);
//Search for Account Number.
while(file.read((char*)&bank,sizeof(bank)))
{
//if record is found
if(strcmp(bank.acno,acc)==0)
{
bank.flag='*';
bank.balance=bank.balance+amount;
// bank.balance=(bank.balance)-(amount);
//position put pointer such that existing record is overwritten.
pos=count*sizeof(bank);
file.seekp(pos,ios::beg);
file.write((char*)&bank,sizeof(bank));
}
count++;
}
cout<<endl<<"No employee in the Record with Account Number : "<<acc;
cout<<"Press Any Key...";
getch( );
file.clear( );
return bank.balance;
}

//EXIT FUNCTION
void bank_acc::exit()
{
//close the data file
file.close();
}

//TEMPORARY DELETION OF RECORDS.


void bank_acc::del_t()
{
char acc[10];
long int pos;
int count=0;
cout<<"Enter Account No. : ";
cin>>acc;
//position get pointer at the beginning of file.
file.seekg(0L,ios::beg);
//search for the account number
while(file.read((char*)&bank,sizeof(bank)))
{
//if record is found
if (strcmp(bank.acno,acc)==0)
{
bank.flag='*';
//position put pointer
pos=count*sizeof(bank);
file.seekp(pos,ios::beg);
file.write((char*)&bank,sizeof(bank));
return;
}
count++;
}
cout<<endl<<"No employee in the Record with Account Number : "<<acc;
cout<<"Press Any Key...";
getch( );
file.clear( );
}

//Permanent deletion
void bank_acc::del_p()
{
ofstream outfile;
outfile.open("temp",ios::out);
//position get Pointer at the begining of file.
file.seekg(0L,ios::beg);
//search for the record marked for deletion.
while(file.read((char*)&bank,sizeof(bank)))
{
//if record is found
if(bank.flag != '.')
{
outfile.write((char*)&bank,sizeof(bank));
}
}
outfile.close();
file.close();
remove("bank.dat");
rename("temp","bank.dat");
file.open("bank.dat",ios::binary|ios::in|ios::out|ios::nocreate);
getch( );
}
//Welcome Screen Function.
void bank_acc::welcome_screen()
{
int gdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
setbkcolor(YELLOW);
setcolor(RED);
setlinestyle(DASHED_LINE,1,1);
rectangle(6,30,620,450);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,6);
outtextxy(200,40,"PROJECT");
outtextxy(270,160,"ON");
outtextxy(70,280,"BANK MANAGEMENT");
getch();
setbkcolor(RED);
setcolor(WHITE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
circle(300,250,200);
outtextxy(150,170,"PREPARED BY : ");
setlinestyle(1,0,3);
outtextxy(250,210,"SUDHANSHU CHAUHAN");
getch();
clrscr();
closegraph();
}
//MAIN PROGRAM
void main()
{
char choice;
bank_acc ba;
ba.welcome_screen();
do
{
clrscr( );
gotoxy(25,3);
cout<<"ABC BANK PVT. LTD. DEHRADUN";
gotoxy(25,4);
cout<<"===========================";
gotoxy(35,6 );
cout<<"MAIN MENU";
gotoxy(35,7);
cout<< "=========";
gotoxy(30,10);
cout<<"1. Add a New Account";
gotoxy(30,11);
cout<<"2. Modify an Account";
gotoxy(30,12);
cout<<"3. Search";
gotoxy(30,13);
cout<<"4. Temporary Deletion";
gotoxy(30,14);
cout<<"5. Permanent Deletion";
gotoxy(30,15);
cout<<"6. Deposit";
gotoxy(30,16);
cout<<"7. Withdraw";
gotoxy(30,17);
cout<<"8. Display";
gotoxy(30,18);
cout<<"0. Exit";
gotoxy(30,21);
cout<<"Enter your Choice : ";
cin>>choice;
clrscr( );
switch(choice)
{
case '1':
ba.addrec();
break;
case '2':
ba.modirec();
break;
case '3':
ba.searchrec();
break;
case '4':
ba.del_t();
break;
case '5':
ba.del_p( );
break;
case '6':
ba.withdraw();
break;
case '7':
ba.deposit();
break;
case '8':
ba.disprec();
break;
case '0':
ba.exit( );
break;
default:
gotoxy(20,20);cout<< "Invalid";
break;
}
}while (choice!='0');
}

Вам также может понравиться