You are on page 1of 4

#include<i ost r eam>

#include<f st ream>
#include<cst dl ib>
usingst d::cout ;
usingst d::cin;
usingst d::endl ;
usingst d::fst ream;
usingst d::of st ream;
usingst d::ifst ream;
usingst d::ios;
cl
assaccount _ quer y
{
private:
characcount _number [
20] ;
charf irstName[ 10];
charl ast Name[ 10] ;
fl
oatt ot al _Balance;
publ i
c:
voidr ead_ dat a();
voidshow_ data( );
voidwr ite_ rec();
voidr ead_ rec( );
voidsear ch_ rec( );
voidedi t_rec( );
voiddel ete_ r
ec( );
};
voidaccount _ quer y :
:read_ data( )
{
cout<<" \ nEnt erAccountNumber :";
cin>>account _number ;
cout<<" Ent erFi rstName: "
;
cin>>f i
rst Name;
cout<<" Ent erLastName: ";
cin>>last Name;
cout<<" Ent erBal ance: ";
cin>>tot al _Bal ance;
cout<<endl ;
}
voidaccount _ quer y :
:show_ dat a()
{
cout<<" AccountNumber : "<<account_number <<endl
;
cout<<" Fi rstName: "<<firstName<<endl ;
cout<<" LastName: "
<<l astName<<endl ;
cout<<" Cur rentBal ance: Rs. " <<tot
al_Balance<<endl;
cout<<" --------
--
-----
---
--
----
---
----"
<<endl;
}
voidaccount _ quer y :
:wr i
te_ r
ec( )
{
ofstream out file;
outfi
le.open( "recor d.bank" , i
os::
binary
|ios:
:app);
read_ dat a( );
outfi
le.wr ite(reint er
pr et_cast <char*>(t
his),si
zeof(*t
his)
);
outfi
le.cl ose( )
;
}
voidaccount _ quer y :
:read_ rec( )
{
i
fstream infile;
i
nfil
e.open( "
r ecord.bank",
ios:
:bi
nary);
i
f(!
infi
le)
{
cout<<" ErrorinOpening!Fil
eNotFound!!"
<<endl;
return;
}
cout<<"\n**** Dataf r
om fi
le**
**"<<endl
;
while(!
infil
e.eof())
{
if(
infil
e.read(reint
erpret
_cast<char
*>(
thi
s),
sizeof
(*t
his)
)>0)
{
show_ dat a()
;
}
}
i
nfil
e.close();
}
v
oidaccount _quer y::
sear ch_rec()
{
i
ntn;
i
fstream i nfil
e;
i
nf i
le.open("recor d.bank" ,ios::binary);
i
f(!i
nf i
le)
{
cout<<"\ nErrori nopeni ng!Fi leNotFound! !
"<<endl
;
return;
}
i
nf i
le.seekg( 0,i
os::end) ;
i
ntcount=i nf i
le.t
ellg( )
/sizeof(* t
his);
cout <<"\nTher ear e" <<count <<"r ecordinthefi
le";
cout <<"\nEnt erRecor dNumbert oSear ch:";
cin>>n;
i
nf i
le.seekg( (n-1)*sizeof (
* t
his)) ;
i
nf i
le.read(reinterpret _cast<char *>(thi
s),si
zeof(
* t
his)
);
show_ data();
}
v
oidaccount _quer y::
edit_rec()
{
i
ntn;
fstr
eam i ofile;
i
of i
le.open( "
recor d.bank" ,ios::i
n|ios::
binary
);
i
f(!i
of i
le)
{
cout<<"\ nErrori nopeni ng!Fi leNotFound! !
"<<endl
;
return;
}
i
of i
le.seekg( 0,ios::end) ;
i
ntcount=i of i
le.t
ellg( )
/sizeof( *t
his);
cout <<"\nTher ear e" <<count <<"r ecordinthefi
le";
cout <<"\nEnt erRecor dNumbert oedi t:
";
cin>>n;
i
of i
le.seekg( (n-1)*sizeof (
* t
his)) ;
i
of i
le.read(reinterpret _cast<char *>(thi
s),si
zeof(
* t
his)
);
cout <<"Recor d" <<n<<"hasf ol lowingdat a"
<<endl;
show_ data();
i
of i
le.close();
i
of i
l
e.open("
record.bank" ,i
os::
out |
i
os::
in|
ios::
binary)
;
i
of i
l
e.seekp((
n-1)*sizeof(*t
his))
;
cout<<"\
nEnterdat atoModi fy"<<endl;
read_data(
);
i
of i
l
e.writ
e(r
einter
pr et_cast<char*>(t
his)
,sizeof(*
this)
);
}
v
oidaccount _quer y :
:del ete_ rec( )
{
i
ntn;
i
fstream i nf il
e;
i
nf i
le.open( "recor d. bank" , i
os::binar y);
i
f(!i
nf il
e)
{
cout <<" \nEr rori nopeni ng!Fi leNotFound! !
"<<endl;
return;
}
i
nf i
le.seekg( 0,ios: :
end) ;
i
ntcount=i nf il
e. t
el lg() /sizeof (*this);
cout <<"\nTher ear e" <<count <<"r ecor di nt hefi
le";
cout <<"\nEnt erRecor dNumbert oDel ete:";
cin>>n;
fstr
eam t mpf ile;
tmpf ile.
open( "tmpf ile. bank" ,i
os: :
out |i
os::binary)
;
i
nf i
le.seekg( 0) ;
for(i
nti =0; i<count ;i++)
{
infi
le.read( reint erpr et _cast<char *>(this),
si
zeof (*
thi
s));
if(i
==( n-1) )
cont i
nue;
tmpf ile.wr ite(rei nter pr et_cast <char *>(thi
s),sizeof(
*thi
s))
;
}
i
nf i
le.close( );
tmpf ile.
close( );
remov e("recor d.bank" ) ;
rename( "tmpf ile.bank" , "record. bank" );
}
i
ntmain( )
{
account _quer yA;
i
ntchoi ce;
cout <<"*** AcountI nf or mat ionSy stem* *
* "
<<endl;
while( tr
ue)
{
cout <<" Sel ectoneopt ionbel ow" ;
cout <<" \n\ t1-->Addr ecordt of il
e";
cout <<" \n\ t2-->Showr ecordf rom f i
l
e";
cout <<" \n\ t3-->Sear chRecor df rom f i
le";
cout <<" \n\ t4-->Updat eRecor d" ;
cout <<" \n\ t5-->Del et eRecor d" ;
cout <<" \n\ t6-->Qui t";
cout <<" \nEnt ery ourchoi ce: "
;
cin>>choi ce;
swi t
ch( choi ce)
{
case1:
A. wr ite_rec( ) ;
break;
case2:
A.read_rec()
;
break;
case3:
A.search_rec()
;
break;
case4:
A.edit_
rec();
break;
case5:
A.delete_r
ec();
break;
case6:
exit(
0);
break;
defaul
t:
cout<<"\nEntercor
retchoi
ce"
;
exit(
0);
}
}
syst
em("
pause"
);
ret
urn0;
}

You might also like