/. seekp(?osAsi=eof(#)) % O /.seekp(Asi=eof(#)* ios--cur)%
7.DATA FILE HANDLING DELHI 2010:
Observ ervee the pro progra gram m segm segment ent giv given en 4. (a (a)) Obs below carefully and fill the blanks marked as Statement 1 and Statement 2 using tellg() and seekp() seekp () func functions tions for perfo performin rming g the requi required red 1 task.
(b) Brite a function in #CC to count the words 3this8 and 3these8 present in a teDt file 3674#E+.7F78. 2 '&ote that the words 3this8 and 3these8 are complete words
include !fstream.h" class #lient $ long #no% char&ame'2*+mail', % public-
Ans) void #OG&7 ( ) $ ifstream /il% ifstream/il(3674#E+.7F7H)% /il. open(3674#E+.7F78)% char Bord'I *#h% int #l >* #2 > * 4>O% while(/il.get(#h)) $ if (#hJ > K K) Bord'4CC > #h% else $ Bord'4 > LM:% if (strcmp (Bord*3this8)>>) #lCC% else if (strcmp(Bord*3these8)>>) #2CC% 4>% cout!!3#ount of AthisA in file-H!!#l% cout!!3#ount of AtheseA in file-H!!#2% O cout!!3#ount of AthisA and N theseA in file- 3!!#lC#2% /il.close( )%
/unction to allow user to enter the #no* &ame*+mail
void +nter() % /unction to allow user to enter (modify) +mail
void 0odify() % long eturn#no() $ return #no% % void #hange+mail() $ #lient #% fstream /% /.open (34&/O.5678*ios--binary 9ios--in9ios--out)% long #noc% #lient:s no. whose +mail needs to be changed
cin""#noc% while (/.read((char;)<#* si=eof(#))) $ if (#noc> >#.eturn#no()) $ #.0odify()% Statement 1 int ?os > @@@@@@@@@@
(!) Br Brit itee a fu func ncti tion on in #C #CC C to se sear arch ch an and d display details of all flights* whose destination is 30umbai8 from a binary file 3/E4P 3/E 4P7.56 7.5678. 78. 6ssu 6ssumin ming g the bin binary ary file is containing contai ning the obQects of the following following class. "
7o find the current position of file pointer
class /E4P7 $ int /no% /light &umber char /rom'2% /light Starting ?oint char 7o'2% /light 5estination publicchar; et/rom( ) $return /rom% char; et7o( ) $return 7o% void +nter( ) $ cin""/no% gets(/rom)% gets(7o)%
@@@@@@@@@@@@@@@ Statement @@@@@@@@@@@@@@@ Statement 2 7o move the file pointer to write the modified record back onto the file for the desired #noc
/.write((char;)<#* si=eof(#))% /.close()% Ans) Statement 1: /. tellg ( )% Statement 2: ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
I
6ny 5oubtT mrkdataUyahoo.com
void 5isplay( ) $ cout!!/no!!3-8!!/rom!!3-8!!7o!!endl%
% void #hange0obile( ) $ #ustomer #% fstream /% /.open(3#O&76#7.5678*ios--binary9 ios--in9ios--out)% long #noc%
% Ans) void ead ( ) $ /E4P7 /% ifstream fin% fin.open(3/E4P7.5678*ios--binary)%
#ustomer no. whose mobile number needs to be changed
cin""#noc% while (/.read((char;)<#*si=eof(#))) $ if (#hoc>>#.et#no( )) $ #.0odify( )% int ?os>@@@@@@@@@@@@@ Statement 1 7o find the current position of file pointer @@@@@@@@@@@@@@ Statement 2
O ifstream ifstream fin (3/E4P7. 5678* ios- -binary) %
while(fin.read((char;)*si=eof(/))) $ if (strcmp(/. et7o()*30umbai8)) /.5isplay( ) % fin.close()% O void ead( ) $ /E4P7 /% ifstream fin% fin.open (3/E4P7. 5678* ios--binary) %
7o move the file pointer to write the modified record back onto the file for the desired #noc
/.write((char;)<#* si=eof(#))% /. close ( )% Ans)
O ifstream fin (3/E4P7. 5678* ios-- binary)%
if (fin) $ fin.read((char;)* si=eof (/))% (/))% while(Jfin.eof( )) $ if (strcmp(/. (strcmp(/. et7o( )*30umbai8)) /.5isplay( )% fin.read((char;)*si=eof(/)) fin.close( )%
Statement 2 /.seekp(?osAsi=eof(#))% O /ile.seekp(Al;si=eof(#)*ios--cur)% (b) Brite a function in #CC to count the words 3t$8 and 3the8 present in a teDt file 3?O+0.7F78. 2 '&ot '& otee th that at th thee wo word rdss 3to to88 an and d 3t 3the he88 ar aree complete words Ans) void #OG&7( ) $ ifstream /il% /il. open (3?O+0.7F78)%
O#TSIDE DELHI 2010: 4. (a (a)) Obs Observ ervee the pro progra gram m segm segment ent giv given en below carefully and fill the blanks marked as Statement 1 and Statement 2 using tellg() and seekp() seekp () func functions tions for perfo performin rming g the requi required red task. 1 include !fstream.h" class #ustomer $ long #no% char &ame'2*0obile'12% public-
O ifstream /ill(3?O+0.7F78)%
char Bord'IO* #h% int #l >* #2>* i>% while(/il.get(#h)) $ if (#hJ > L L) Bord'iCC > #h% else $ Bord'i > LM:% if (strcmp (Bord* 3 t$8) >>) #lCC% else if (strcmp (Bord* 3 the8) >>) #2CC% i>%
/unction to allow user to enter the #no* &ame*0obile
void +nter( )% /unction to allow user to enter
modify mobile number
void 0odify( )% /unction to return value of #no
long et#no( ) $ return #no% ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
Statement 1 /.tellg( ) %
IV
6ny 5oubtT mrkdataUyahoo.com
cout!!8#ount of At$A in file-8!!#l% cout!!8#ount of AtheA in file-8!!#2% O coutW8#ount of AtoA and AtheA in /il.close( )%
Eine 1 and Eine 2 using fstream functions for performing the required task. 1 include !fstream.h" class Stock $ long 4no % 4tem &umber char 4tem '2 % 4tem &ame int Xty % Xuantity publicvoid et(int)%
(!) Brite a function in #CC to search and display details. of all trains* whose destination is 35elhi8 . from a binary file 3764&.5678. 6ssuming the binary file is containing the obQects of the following class. ,
/unction to enter the content
void show( )% /unction to display the content
void ?urchase (int 7qty) $ Xty C > 7qty % /unction to increment in Xty long Rnow4no ( ) $ return 4no% % void ?urchaseitem(long ?4&o* int ?Xty)
class 764& $ int 7no% 7rain &umber char/rom'2% 7rain Starting ?oint char7o '2% 7rain 5estination publicchar; et/rom( ) $ return /rom% char; et7o( ) $ return 7o% void 4nput( ) $ cin""7no% gets(/rom)% gets(7o)% void Show( ) $ cout!!7no!!3-8!!/rom!!3-8!!7o!!endl% %
?4&o A" 4no of the item purchased ?Xty A" &umber of item purchased
$ fstream /ile% /ile.open(347+0S.5678* ios - binarylios --inlios -- out)% int ?os > N1 % Stock S % while (?os > > N1 << /ile.read((char;)
>?4&o) $ S. ?urchase (?Xty)% 7o update the number of 4tems
Eine 1- 7o place the file pointer to the required position
Ans) void ead ( ) $ 764& 7% ifstream fin% fin. open (3764&.5678*ios--binary)%
if (?os > > N1) cout!!3&o updation done as required 4no not found..8 % /ile.close ( ) %
while(fin.read((char;)<7* si=eof(7))) $ if(strcmp(7.et7o()*85elhi8)>>O) 7.Show( ) % fin.close( )%
Ans)
Statement 1: /ile.seekp(?os)% O /ile.seekp(Asi=eof(6)* ios-- cur)% Statement 2: /ile.write((char;)
DELHI 200%: 4. (a) Observe the program segment given below carefully and fill in the blanks marked as F44 #omputer #hap A
@@@@@@@@@@@@@@@@@@@% Eine 2- 7o write the obQect S on to the binary file
O ifstream fin (3764&.5678* ios--binary)%
?repared by- 0r.0.avi Riran
?os > /ile.tellg ( ) Asi=eof (S) % @@@@@@@@@@@@@@@@@@%
II
6ny 5oubtT mrkdataUyahoo.com
$ (b) Brite a function #OG&7@5O( ) in #CC to count the presence of a word L &$: in a teDt file 30+0O.7F78 2
return Status% %
E'ame: 4f the content of the file 30+0O.7F78 is as follows4 will &$ it* if you request me to &$ it. 4t would have been done much earlier. 7he function #OG&7@5O ( ) will display the following message#ount of AdoA in file - 2 &ote- 4n the above eDample* Ldo: occurring as a part of word done is not considered.
Ans) void 5isplay6ctive ( ) $ GS+ G% ifstream fin% fin.open (3GS+.5678* ios--binary)% O ifstream fin (3GS+.5678* ios--binary)%
while(fin.read((char;)>:6:) G.show( )% fin.close( )% O void 5isplay6ctive() $ GS+ G% ifstream fin% fin.open (3GS+.5678* ios--binary)%
Ans) void #OG&7@5O( ) $ ifstream /i1% /il.open(30+0O.7F78)% O ifstream /il(30+0O.7F78)% char Bord'I*#h% int #ount >*4>% while(/i1.get(#h)) $ if (#hJ > L L) Bord'4CC > #h% else $ Bord'4 > LM:% if (strcmp (Bord* 3do8) >>) #ountCC% 4>O% cout!!8#ount ofA &$A in file-8!!#ount% /il.close( )%
O ifstream fin(3GS+.5678*ios--binary)%
if (fin) $ fin.read((char;)>:6:) G.show( ) % fin.read((char;)
Y. (a) Observe the program segment given below carefully and fill the blanks marked as Eine 1 and Eine 2 using fstream functions for performing the required task. 1
(!) Brite a function in #CC to read and display the detail of all the users whose status is L6: (i.e. 6ctive) from a binary file 3GS+.5678. 6ssuming the binary file 3GS+.5678 is containing obQects of class GS+* which is defined as follows,
include !fstream.h" class Eibrary $ long 6no%
class GS+ $ int Gid % Gser 4d char Gname '2% Gser &ame char Status% Gser 7ype- 6 6ctive 4 4nactive
6no A 6ccession &umber of the Zook
char 7itle'2% 7itle A 7itle of the Zook
int Xty%
?ublicvoid egister ( )%
Xty A &umber of Zooks in Eibrary
publicvoid +nter (int)%
/unction to enter the content
void show ( ) %
/unction to enter the content
/unction to display all data members
void 5isplay()%
char etstatus ( )
/unction to display the content ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
I[
6ny 5oubtT mrkdataUyahoo.com
void Zuy(int 7qty) $ XtyC>7qty% /unction to increment in Xty long et6no( ) $ return 6no% %
N$te: 4n the above eDample* L t$: occurring as a part of word stop is not considered. Ans) void #OG&7@7O ( ) $ ifstream /il% O ifstream /i1(3&O7+S.7F78)%
/il.open(3&O7+S.7F78) char Bord'I*#h% int #ount >* 4>% while(/il.get(#h)) $ if (#hJ> L L) Bord '4CC > #h% else $ Bord'4 > LM:% if (strcmp (Bord* 3 t$8) >>) #ountCC% 4>O% /il.close( )% cout!!8#ount of AtoA in file- 3!!#ount%
void ZuyZook(long Z6&o*int ZXty) Z6&o A"\6no of the book purchased ZXty A"\&umber of books purchased $ fstream /ile% /ile.open(3S7O#R.5678 * ios--binary9ios--in9ios--out)% int position>Al% Eibrary E% while(?osition>>Al << /ile.read((char;)>Z6&o) $ E.Zuy(ZXty)% 7o update the number of Zooks
?osition > /ile.tellg()Asi=eof(E) % @@@@@@@@@@@@@@@@@@@@% Eine 1- 7o place the file pointer to the required position
(!) Brite a function in #CC to read and display the detail of all the members whose membership type is LE: or L0: from a binary file 3#EGZ.5678. 6ssume the binary file 3#EGZ.5678 contains obQects of class #EGZ* which is defined as follows, class #EGZ $ int 0no% 0ember &umber char 0name '2% 0ember &ame char 7ype% 0ember 7ype- E Eife 0ember 0
@@@@@@@@@@@@@@@@@@@@% Eine 2-7o write the obQect E on to the binary file
if (?osition>>Al) cout!! 3&o updation do-r$e as required 6no not found..8% /ile.close( )% Ans) Statement 1 /ile.seekp(?osition)% O /ile. seekp (Asi=eof (E)* ios--cur)%
0onthly 0ember uest
publicvoid egister( )% /unction to enter the content
void 5isplay( )%
Statement 2 /ile.write((char;)
/unction to display all data members
char Bhat7ype( ) $ return 7ype% %
(b) Brite a function #OG&7@7O( ) in #CC to count the presence of a word L t$: in a teDt file 3&O7+S.7F78. 2
Ans) void 5isplayE@0( ) $ #EGZ #% fstream fin% fin. open (3#EGZ.5678* ios--binary9ios--in)%
E'ame: 4f the content of the file 3&O7+S.7F78 is as follows4t is very important t$ know that smoking is inQurious t$ health. Eet us take initiative t$ stop it. 7he function #OG&7@7O( ) will display the following message#ount of AtoA in file- " ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
O ifstream fin (3#EGZ.5678* ios--binary)%
while(fin.read((char;)<#* si=eof(#)) $ [
6ny 5oubtT mrkdataUyahoo.com
if(#.Bhat7ype()>>:E:99#.Bhat7ype()>>:0:) # .5isplay ( )% fin.close( )% O void 5isp1ayE@0 ( ) $ #EGZ #% fstream fin% fin.open (3#EGZ.5678* ios--binary 9 ios--in)%
ecordCC % if (/ound > > 1) cout !! 3ecord Gpdated8 % /ile.close( ) % Brite the Statement1 to position the /ile ?ointer at the beginning of the ecord for which the 6pplicant:s 4d matches with the argument passed* and Statement 2 to write the updated record at that position.
ifstream fin (3#EGZ.5678*ios--binary)%
if(fin) $ fin.read((char;)<#* si=eof(#))% while(Jfin.eof()) $ if(#.Bhat7ype()>>:E:99#.Bhat7ype()>>:0:) #. 5isplay( )% fin.read((char;)<#* si=eof(#))% fin.close( )% *
Ans)
Statement 2 /ile.seekp(ecord;si=eof(6pplicant))% or /ile.write((char;)<6*si=eof(6))% 4.b) Brite a function in #CC to count the number of lowercase alphabets present in a teDt file 3ZOOR.7F78.
DELHI : 200+: Y.a)Observe the program segment given below carefully* and answer the question that follows
S$,ti$n: void EowerEetters( ) $ clrscr( )% ifstream fin(HZOOR.7F7H*ios--in)% char ch% int lowercount>% while(fin) $ fin.get(ch)% if(islower(ch)) lowercountCC% cout!!HMn7otal number of Eowercase alphabets in the file > H!!lowercount% getch( )% 4.!)iven a binary file ?PO&+.567* containing records of the following structure type
class 6pplicant $ long 6id % 6pplicant:s 4d char &ame'2 % 6pplicant:s &ame float Score % 6pplicant:s Score public % void +nroll( ) % void 5isp( ) % void 0arksScore( ) % /unction to change Score
long @6id( ) $ return 6id% ) % void ScoreGpdate (long 4d) $ fstream /ile % /ile.open (36??E4.5678 * ios -- binary 9 ios -- in 9 ios -- out) % 6pplicant 6 % int ecord > * /ound > % while (J/ound << /ile.read ( (char;)<#* si=eof(c) ) ) $ if (4d > > 6.@6id( ) ) $ cout !! 3+nter new Score8 % 6.0arksScore( ) % @@@@@@@@@@@@ Statement 1 @@@@@@@@@@@@ Statement 2 /ound>1% ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
Statement 1 /ile.seekp(/ile.tellp( )Asi=eof(6))%
class phonlist $ char &ame'2 % char 6ddress', % char 6rea#ode'] % char ?hone&o'1] % public % void egister( ) % void Show( ) % int #heck#ode(char 6#' ) $ return strcmp(6rea#ode*6#) % % [1
6ny 5oubtT mrkdataUyahoo.com
Brite a function 76&S/+( ) in #CC* that would copy all those records which are having 6rea#ode as 35+E8 from ?PO&+.567 to ?PO&Z6#R.567. S$,ti$n:
if (/ound > > 1) cout !! 3 ecord Gpdated8 % /ile.close( ) % Brite the Statement to position the /ile ?ointer at the beginning of the ecord for which the #andidate:s 4d matches with the argument passed* and Statement 2 to write the updated ecord at that position. Ans) Statement 1 /ile.seekp(/ile.tellp( )Asi=eof(#))% Or /ile.seekp(ecord;si=eof(#))%
void 76&S/+( ) $ ifstream fin(3?PO&+.567:*ios--in*ios--binary)% ofstream fout(3?PO&+Z6#R.5678* ios--out*ios--binary)% phonlist ?% while(fin) or while(Jfin.eof( )) $ fin.read((char;)*si=eof(?))% if(?.#heck#ode(35+E8)> > ) fout.write((char;)*si=eof(?))% fin.close( )% fout.close( )%
Statement 2 /ile.write((char;)<#*si=eof(#))% Or /ile.write((char;)<#*si=eof(#andidate))%
4.b)Brite a function in #CC to count the number of uppercase alphabets present in a teDt file 3674#E+.7F78.
O#TSIDE DELHI 200+: 4.a)Observe the program segment given below carefully* and answer the question that follows
S$,ti$n: void GpperEetters( ) $ clrscr( )% ifstream fin(H674#E+.7F7H*ios--in)% char ch% int uppercount>% while(fin) $ fin.get(ch)% if(isupper(ch)) uppercountCC% cout!!HMn7otal number of Gppercase alphabets in the file > H!!uppercount% getch( )% 4.!) iven a binary file 7+E+?PO&.567* containing records of the following class 5irectory -
class candidate $ long #id % #andidate:s 4d char #&ame'2% #andidate:s &ame float 0arks % #andidate:s 0arks public % void +nter( ) % void 5isplay( ) % void 0arks#hange( ) % /unction to change marks
long @#id( ) $ return #id% % void 0arksGpdate (long 4d) $ fstream /ile % /ile.open (3#6&54567+.5678* ios - binary9ios--in9ios -- out) % #andidate # % int ecord > * /ound > % while (J/ound< >#.@#id( )) $ cout !! 3+nter new 0arks8 % #.0arks#hange( ) % ------------ Statement1 @@@@@@@@@@@ Statement 2 /ound > 1 % ecordCC % ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
class 5irectory $ char &ame'2 % char 6ddress', % char 6rea#ode'] % char phone@&o'1] % public % void egister( ) % void Show( ) % int #heck#ode(char 6#' ) $ return strcmp(6rea#ode* 6#) % % Brite a function #O?^6Z#( ) in #CC* that would copy all those records having 6rea#ode as 312,8 from 7+E+?PO&.567 to 7+E+Z6#R.567. [2
6ny 5oubtT mrkdataUyahoo.com
4f the function 6llocate0arks( ) is supposed to 6llocate 0arks for the records in the file 06RS.567 based on their value of the member 7ime7aken. Brite #CC statements for the statement 1 and statement 2* where* statement 1 is required to position the file write pointer to an appropriate place in the file and statement 2 is to perform the write operation with the modified record.
S$,ti$n: void #O?^6Z#( ) $ ifstream fin(37+E+?PO&.567:*ios--in9 ios--binary)% ofstream fout(37+E+Z6#R.5678*ios--out*ios9 binary)% 5irectory 5% while(fin) or while(Jfin.eof( )) $ fin.read((char;)<5*si=eof(5))% if(5.#heck#ode(312,8)> > ) fout.write((char;)<5*si=eof(5))% fin.close( )% fout.close( )%
Ans) Statement 1 /ile.seekp(/ile.tellp( )Asi=eof(?))% /ile.seekp(ecord;si=eof(?))%
DELHI : 2007 4.a) Observe the program segment given below carefully* and answer the question that follows
4.b) Brite a function in #CC to print the count of the word is as an independent word in a teDt file 546EOG+.7F7. /or eDample*if the content of the file 546EOG+.7F7 is 7his is his book. Is this book good T 7hen the output of the program should be 2.
class ?rac/ile $ int ?racno % char ?rac&ame'2 int 7ime7aken % int 0arks % public void +nter?rac( ) %
S$,ti$n:
/unction to enter ?rac/ile details
Ans)
void Show?rac( ) /unction to display ?rac/ile details
void #OG&7@4S ( ) $ ifstream /il% O ifstream /i1(3&O7+S.7F78)% /il.open(3546EOG+.7F78) char Bord'I*#h% int #ount >* 4>% while(/il.get(#h)) $ if (#hJ> L L) Bord '4CC > #h% else $ Bord'4 > LM:% if (strcmp (Bord* 3 is8) >>) #ountCC% 4>O% /il.close( )% cout!!8#ount of A isA in file- 3!!#ount%
int 7ime( )function to return 7ime 7aken $ return 7ime7aken% void 6ssignmarks(int 0) /unction to assign 0arks
$ 0arks > 0 % % void 6llocate0arks( ) $ fstream /ile % /ile.open (306RS.5678* ios -- binary 9 ios -- in 9 ios -- out ) % ?rac/ile ? % int ecord > % while (/ile.read ( (char;) * si=eof (?) ) ) $ if (?.7ime( ) " ]) ?.6ssignmarks() else ?.6ssignmarks(1) -------------Statement 1
4.!)iven a binary file 60+.567* containing records of the following structure type struct ame $ char ame&ame'2 % char ?articipate'1', % %
@@@@@@@@@@@@@%Statement2
ecordCC % /ile . close( ) % ?repared by- 0r.0.avi Riran
Statement 2 /ile.write((char;)*si=eof(?))% /ile.write((char;)*si=eof(?rac/ile))%
F44 #omputer #hap A
[,
6ny 5oubtT mrkdataUyahoo.com
Brite a function in #CC that would read contents from the file 60+.567 and creates a file named Z6SR+7.567 copying only those records from 60+.567 where the game name is 3Zasket Zall8.
int ec> % while (/ile.read ( (char;) >:&:) E.6ssignmarks() else E.6ssignmarks (1) --------------- Statement 1
S$,ti$n:
void Z?layers( ) $ ifstream fin(360+.567:*ios--in*ios--binary)% ofstream fout(3Z6SR+7.5678*ios--out9 ios--binary)% ame % while(fin) or while(Jfin.eof( )) $ fin.read((char;)<*si=eof(ame))% if(strcmp(.ame&ame*8Zasket Zall8)> > ) fout.write((char;)<*si=eof())% fin.close( )% fout.close( )%
@@@@@@@@@@@@@@@@%Statement 2 ecCC % /ile.close( ) % 4f the function 0odify0arks ( ) is supposed to modify marks for the records in the file 06RS.567 based on their status of the member #hecked (containg value either L^: or L&:).Brite #CC statements for the statement 1 and statement 2*where* statement 1 is required to position the file write pointer to an appropriate place in the file and statement 2 is to perform the write operation with the modified record. Ans) Statement 1 /ile.seekp(/ile.tellp( )Asi=eof(E))% or /ile.seekp(ec;si=eof(E))%
O#TSIDE DELHI : 2007 4.a) Observe the program segment given below carefully*and answer the question that follows-
Statement 2 /ile.write((char;)
class Eabrecord $ int +Dpno% char +Dperiment'2 % char #hecked % int 0arks % public void +nter+Dp( ) % function to enter +Dperiment details viod Show+Dp( ) % function to display +Dperiment details char #hecked( ) function to return +Dpno $ return #hecked% void 6ssignmarks (int 0) function to assign 0arks $ 0arks > 0% %
4.b)Brite a function in #CC to print the count of the word the as an independent word in a teDt file S7O^.7F7.
/or e'ame*if the content of the file S7O^.7F7 is 7here was a monkey in the =oo.The monkey was very naughty. 7hen the output of the program should be 2 S$,ti$n: void #OG&7@7P+ ( ) $ ifstream /il% O ifstream /i1(3&O7+S.7F78)% /il.open(3S7O^.7F78) char Bord'I*#h% int #ount >* 4>% while(/il.get(#h)) $ if (#hJ> L L) Bord '4CC > #h% else $
void 0odify0arks( ) $ fstream /ile % /ile.open (30arks.5at8* ios -- binary l ios -- in l ios -- out) % Eabrecord E % ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
[Y
6ny 5oubtT mrkdataUyahoo.com
Bord'4 > LM:% if (strcmp (strupr(Bord)* 3 THE8) >>) #ountCC% 4>O% /il.close( )% cout!!8#ount ofAtheA in file- 3!!#ount%
(Since* the file is opened in out mode* it looses all the previous content* if the file mode is app* then result will be Y) 4.b)Brite a function to count the number of words present in a teDt file named 3?66.7F78. 6ssume that each word is separated by a single blankspace character and no blanksspaces in the beginning and end of the file.
4.!)iven a binary file S?O7S.567*containg records of the following structure type-
S$,ti$n: void Bords#ount( ) $ clrscr( )% ifstream fin(H?66.7F7H*ios--in)% char ch% int Bords>1% if(Jfin) $ cout!!8&o words at all in the file8% eDit()%
struct Sports $ char +vent'2 % char ?articipant'1', % % Brite a function in #CC that would read contents from the file S?O7S.567 and creates a file named 67PE+74#.567 copying only those records from S?O7S.567 where the event name is 36thletics8. S$,ti$n: void 6thletsEist( ) $ ifstream fin(3S?O7S.567:*ios--in* ios--binary)%)% ofstream fout(367PE+74#.5678* ios--out9ios--binary)% Sports S% while(fin) or while(Jfin.eof( )) $ fin.read((char;) > ) fout.write((char;)
while(fin) $ fin.get(ch)% if(ch> >: L) BordsCC% cout!!HMn7otal number of Bords in the file > H!!Bords% getch( )% 4.!)/ollowing is the structure of each record in a data file named 3#OEO&^.5678
struct #OEO&^ $ char #olony@#ode'1 % char #olony@&ame'1 int &o@of@?eople % % Brite a function in #CC to update the file with a new value of &o@of@?eople. 7he value of #olony@#ode and &o@of@?eople are read during the eDecution of the program.
DELHI : 200/ 4.a) void main( ) $ char ch > L6: % fstream fileout(3data.dat8* ios--out) % fileout!!ch % int p > fileout.tellg( ) cout!!p % Bhat is the output if the file content before the eDecution of the program is the string 36Z#8 (N$te that ae n$t at $ the ie). Ans) 1 ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
S$,ti$n: void Gpdate( ) $ fstream finout(3#OEO&^.5678*ios--in9 ios--out)% #OEO&^ #% finout.seekg()% while(finout) $finout.read((char ;)<#* si=eof(#))% cout!!8Mn7he #olony #ode is 3!!#.#olony@#ode% []
6ny 5oubtT mrkdataUyahoo.com
cout!!8Mn7he #olony &ame is8!!#.#olony@&ame% cout!!8Mn+nter the &umber of ?eople8% cin""#.&o@of@?eople% finout.seekp(finout.seekp( )Asi=eof(#))% finout.write((char ;)<#*si=eof(#))%
4.!) /ollowing is the structure of each record in a data file named 3?O5G#7.5678 .
struct ?O5G#7 $ char ?roduct@#ode'1 % char ?roduct@5escription'1 % int Stock % % Brite a function in #CC to update the file with a new value of Stock. 7he Stock and the ?roduct@#ode* whose Stock to be updated* are read during the eDecution of the program.
O#TSIDE DELHI : 200/ 4.a) void main( ) $ char ch > L6: % fstream fileout(3data.dat8* ios -- app)% fileout!!ch % int p > fileout.tellg( ) % cout !! p % Bhat is the output if the file content before the eDecution of the program is the string T 36Z#8 (&ote that 3 3 are not part of the file)
4.b)Brite a function to count the number of blanks present in a teDt file named 3?66.7F78 .
S$,ti$n: void Gpdate( ) $ fstream finout(3?O5G#7.5678* ios--in9ios--out)% ?O5G#7 ?% finout.seekg()% while(finout) $ finout.read((char ;)* si=eof(?))% cout!!8Mn7he ?roduct #ode is 3!!?.?roduct@#ode% cout!!8Mn7he ?roduct 5escription is8!! ?.?roduct@5escription% cout!!8Mn+nter the Stock- 3% cin""?.Stock% finout.seekp(finout.seekp( )Asi=eof(?))% finout.write((char ;)*si=eof(?))%
S$,ti$n:
DELHI : 2003
void Zlanks#ount( ) $ clrscr( )% ifstream fin(H?66.7F7H*ios--in)% char ch% int Zlanks>% if(Jfin) $ cout!!8&o words at all in the file. So no blank spaces8% eDit()% while(fin) $ fin.get(ch)% if(ch> >: L) ZlanksCC% cout!!HMn7otal number of Zlank Spaces in the file > H!!Zlanks% getch( )%
4.a) Observe the program segment given below carefully* and answer the question that
Ans)4
(Since* the file is opened in app mode* it retains the previous content also* if the file mode is out* then result will be since it will loose all the old content of the file.)
?repared by- 0r.0.avi Riran
F44 #omputer #hap A
class Zook $ int Zook@no char Zook@name'2 % public % void enterdetails( ) % function to enter Zook details void showdetails( ) % function to display Zook details int book@no( ) $return Zook@no % function to return Zook@no % void 0odify (Zook &+B) $ fstream /ile % /ile.open(3ZOOR.5678* ios -- binary 9ios -- in 9 ios -- out) % Zook OZ % [
6ny 5oubtT mrkdataUyahoo.com
int ecord > * /ound > % while (J/ound << /ile.read((char;) > OZ.Zook@no( )) $ @@@@@@@@@@@ 0issing Statement /ile.write((char;) <&+B* si=e of(&+B)) % /ound > 1 % else /ile.write((char;)
4.!)iven a binary file S7G5+&7.567* containing records of the following class Student type
class Student $ char S@6dmno'1 % 6dmission number of student char S@&ame', % &ame of student int ?ercentage % 0arks ?ercentage of student public void +nter5ata( ) $ gets(S@6dmno)% gets(S@&ame)% cin "" ?ercentage % void 5isplay5ata( ) $ cout !! setw(12) !! S@6dmno % cout !! setw(,2) !! S@&ame % cout !! setw(,) !! ?ercentage !! endl % int eturn?ercentage( ) $ return ?ercentage% %
4f the function 0odify( ) is supposed to modify a record in file ZOOR.567 with the values of Zook &+B passed to its argument* write the appropriate statement for issin5 Statement using seekp( ) or seekg( )* whichever needed* in the above code that would write the modified record at its proper place. Ans) /ile.seekp((ecordsreadA1);si=eof(&+B))% O /ile.seekp(Asi=eof(&+B)* ios--curr)% O /ile.seekp(/ile.tellg()Asi=eof(&+B))%
Brite a function in #CC* that would read contents of file S7G5+&7.567 and display the details of those Students whose ?ercentage is above V].
4.b)Brite a function in #CC to count and display the number of lines starting with alphabet L6: present in a teDt file 3E4&+S.7F78.
Ans) void 5istinction() $ Student S% fstream /in% /in.open(3S7G5+&7.5678* ios--binary9ios--in)% while(/in.read((char;)
E'ame : 4f the file 3E4&+S.7F78 contains the following lines* A boy is playing there. 7here is a playground. An aeroplane is in the sky. Alphabets and numbers are allowed in the password. 7he function should display the output as " Ans) void counter( ) $ char 6line'I% int #ount>% ifstream /in (3E4&+S.7F78)% while(/in.getline(6line*I* LMn:)) if (6line'>> L6:) #ountCC% /in.close( )% cout!!#ount!!endl% ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
O#TSIDE DELHI : 2003 4.a) Observe the program segment given below carefully * and answer the question that follows class 0ember $ int 0ember@no % char 0ember@name'2 % [V
6ny 5oubtT mrkdataUyahoo.com
public void enterdetails ( ) % function to enter 0ember details void showdetails ( ) % function to display 0ember details int 0ember@no( ) $ return 0ember@no% function to return 0ember@no %
alphabet L6: present 3S7O^.7F78.
teDt
Ans) void #OG&76E4&+S() $ ifstream /4E+(3S7O^.7F78)% int #6>% char E4&+'I% while (/4E+.getline (E4&+*I)) if (E4&+'J>:6:) #6CC% cout!!8&ot Starting with 6 counts to 3!!#6!!endl% /4E+.close( )% 4.!) iven a binary file 6??E^.567* containing records of the following class 6pplicant type ,
class 6pplicant $ char 6@no'1 % oll number of applicant char 6@&ame',% &ame of applicant int 6@Score% Score of applicant public void +nrol( ) $ gets(6@no)% gets(6@&ame)% cin "" 6@Score % void Status( ) $ cout !! setw(12) !! 6@6dmno % cout !! setw(,2) !! 6@&ame % cout !! setw(,) !! 6@Score !! endl % int eturnScore( ) $ return 6@Score% % Brite a function in #CC* that would read contents of file 6??E^.567 and display the details of those Students whose 6@Score is above V.
4f the function Gpdate( ) is supposed to modify a record in file 0+0Z+.567 with the values of 0ember &+B passed to its argument* write issin5 the appropriate statement for statement using seekp( ) or seekg( )* whichever needed* in the above code that would write the modified record at its proper place. Ans) /ile.seekp((ecordsreadA1);si=eof(O0))% O /ile.seekp(ecordsread;si=eof(O0))% O /ile.seekp(Al;si=eof(O0)*ios--curr)% O /ile.seekp(file.tellg()Asi=eof(O0))% 2.b) Brite a function in #CC to count and display the number of lines not starting with F44 #omputer #hap A
a
E'ame : 4f the file 3S7O^.7F78 contains the following lines* The rose is red. 6 girl is playing there. There is a playground. 6n aeroplane is in the sky. Numbers are not allowed in the password. 7he function should display the output as "
void Gpdate (0ember &+B) $ fstream /ile % /ile.open(30+0Z+.5678 * ios - binary 9ios -- in 9 ios -- out) % 0ember O0 % int ecordsread > * /ound > % while (J/ound << /ile.read((char;) < O0* si=eof(O0))) $ ecordsreadCC % if (&+B.0ember@no( ) >> O0.0ember@no( )) $ @@@@@@@@@@@ 0issing Statement /ile.write((char;) < &+B * si=eof(&+B) % /ound > 1 % else /ile.write((char;) < O0* si=eof(O0)) % if (J/ound) cout!!8ecord for modification does not eDist8 % /ile.close( ) %
?repared by- 0r.0.avi Riran
in
[I
6ny 5oubtT mrkdataUyahoo.com
file
DELHI : 2004
void Showonscreen( ) $ cout!!4dno!!8-8!!7ype!!endl !!5esc!!endl%
4.a)6ssuming that a teDt file named /4S7.7F7 contains some teDt written into it* write a function named 6$e$&s( )* that reads the file /4S7.7F7 and creates a new file named S+#O&5.7F7* to contain only those $&s from the file /4S7.7F7 which start with start with a lowercase vowel (i.e. with La:* :e:* :4:* Lo:* Lu:). /or eDample if the file /4S7.7F7 contains
8a9 ,mbea an& $6e!$at hen it ains 7hen the file S+#O&5.7F7 shall contain,mbea an& $6e!$at it
4.b) Brite a #CC program* which initiali=es a string variable to the content 37ime is a great teacher but unfortunately it kills all its pupils. Zerlio=8 and outputs the string one character at a time to the disk file OG7.7F7.^ou have to include all the header files if required.
% DELHI : 2002 4.a)Bhat is the difference between pub( ) and write( ) T
4.b) 6ssuming the class #omputer as followsclass computer $ char chiptype'1% int speed% publicvoid getdetails( ) $ get(chiptype)% cin""speed% void showdetails( ) $ cout!!8#hip8!!chiptype!8Speed > 3speed% %
DELHI : 2001
5istinguish 4.a) ios--app.
and
4.b) #onsider the class declaration class /E4P7 $ protectedint flight@no% char destination'2% float distance% publicvoid 4&?G7( )% 7o read an obQect from the keyboard void write@file(int)% 7o write & obQects into the file* Bhere & is passed as argument. void OG7?G7( )% 7o display the file contents on the monitor. % #omplete the member functions definitions.
DELHI : 200" 4.a) Brite a user defined function in #CC to read the content from a teDt file &O7+S.7F7* count and display the number of blank spaces present in it. 4.b)6ssuming a binary file /G&.567 is containing obQects belonging to a class E6GP7+ (as defined below).Brite a user defined function in #CC to add more obQects belonging to class E6GP7+ at the bottom of it.
2000: 4 (a) &ame two member functions of ofstream class
class E6GP7+ $ int 4dno% 4dentification number char 7ype']% E6GP7+ 7ype char 5esc'2]]%5escription public void &ewentry( ) $ cin""4dno%gets(7ype)%gets(5esc)% F44 #omputer #hap A
ios--out
Ans) 7he ios--out mode opens the file in output mode only. 7he ios--app mode opens the file in append mode* where the file can be appended.
4.!)Brite a function ea&ie( ) to read all the records present in already eDisting binary file SP4?.567 and display them on the screen* also count the number of records present in the file.
?repared by- 0r.0.avi Riran
between
4 (b) 6ssuming the class 54&RS defined below* write functions in #CC to perform the following(i)Brite the obQects of 54&RS to a binary file. (ii) ead the obQects of 54&RS from binary file and display them on screen when 5&60+ has value H4&5^ #OE6H. [[
6ny 5oubtT mrkdataUyahoo.com
class 54&RS $ int 5#O5+% char 5&60+'1,% &ame of the drink int 5S4_+*% Si=e in liters float 5?4#+% publicvoid getdrinks( ) $ cin""5#O5+""5&60+" "5S4_+""5?4#+% void showdrinks( ) $ cout!!5#O5+!!5&60+!!5S4_+!! 5?4#+!!endl% char ;getname( ) $return 5&60+% %
char +&60+'1% publicvoid +747( ) $ cin""+&O% gets(+&60+)% void SPOB47( ) $ cout! ! +&O!!+&60+!!endl% %
1%%%:
include !fstream.h" class 4tem $ int 4no% char 4tem'2% publicvoid Search(int )% /unction to search and display the content from a particular record number void 0odify(int)% /unction to modify the content of a particular record number % void 4tem--Search(int ec&o) $ fstream /ile% /ile.open(HS7O#R.567H*ios--binary9ios--in)% @@@@@@@@@@@@@@@@ Statement 1 /ile.read((char;)this*si=eof(4tem))% cout!!4no!!H>>"H!!4tem!!endl% /ile.close( )% void 4tem--0odify(int ec&o) $ fstream /ile% /ile.open(HS7O#R.567H*ios--binary9ios --in9ios--out)% cout""4no%cin.getline(4tem*2)% @@@@@@@@@@@@@@@@ Statement 2 /ile.write((char;)this*si=eof(4tem))% /ile.close( )%
200%;10 ODEL
4 (a) 5ifferentiate between functions read( ) and write( ). 4 (b) 6ssuming the class /EO??^ZOF* write a function in #CC to perform following(i) Brite the obQects of /EO??^ZOF to a binary file. (ii) eads the obQects of /EO??^ZOF from binary file and display them on screen.
class /EO??^ZOF $ int si=e% char name'1% publicvoid getdata() $ cin""si=e%gets(name)% void showdata()$cout!!si=e!!H !!name!!endl% % 1%%+: 4(a) Brite name of two member functions belonging to fstream class. 4(b) 6ssuming the class +0?EO^++ given below* write functions in #CC to perform the following (i) Brite the obQects of +0?EO^++ to a binary file. (ii) ead the obQects of +0?EO^++ from binary file and display them on the screen.
Ans)
Statement 2 /ile.seekp(ec&o;si=eof(4tem))%
class +0?EO^++ $ int +&O% ?repared by- 0r.0.avi Riran
Statement 1 /ile.seekg(ec&o;si=eof(4tem))%
F44 #omputer #hap A
1
6ny 5oubtT mrkdataUyahoo.com
b) Brite a function in #CC to count the number of lines present in a teDt file HS7O^.7F7H. 2
Statement 1 and Statement 2 using seekg() and tellg() functions for performing the required task. 1
Ans) void #ountEine() $ ifstream /4E(HS7O^.7F7H)% int E4&+S>% char S7'I% while (/4E.getline(S7*I)) E4&+SCC% cout!!H&o. of Eines-H!!E4&+S!!endl% f.close( )%
include !fstream.h" class +mployee $ int +no%char +name'2% public/unction to count the total number of records int #ountrec( )% % int 4tem--#ountrec( ) $ fstream /ile% /ile.open(H+0?.567H*ios--binary9ios--in)% @@@@@@@@@@@@@@@@@@ Statement 1 int Zytes >@@@@@@@ Statement 2 int #ount > Zytessi=eof(4tem)% /ile.close( )% return #ount% Ans) Statement 1 /ile.seekg(*ios--end)%
!) Brite a function in #CC to search for a Zook&o from a binary file HZOOR.567H*assuming the binary file is containing the obQects of the following class. ,
class $ int Zno% char 7itle'2% publicint Zno( ) $return Zno% void +nter( ) $cin""Zno%gets(7itle)% void 5isplay( ) $cout!!Zno!!7itle!!endl% %
Statement 2 /ile.tellg( )% b) Brite a function in #CC to count the number of alphabets present in a teDt file H&O7+S.7F7H. 2 Ans) void #ount6lphabet() $ ifstream /4E(H&O7+S.7F7H)% int #6E?P6>% char #P>/4E.get()% while (J/4E.eof()) $ if (isalpha(#P)) #6E?P6CC% #P>/4E.get( )% cout!!H&o. of 6lphabets-H!! #6E?P6!!endl%
Ans)
void ZookSearch() $ fstream /4E% /4E.open(HZOOR.567H*ios--binary9ios--in)% ZOOR Z% int bn*/ound>% cout!!H+nter Zook &o. to search`H% cin""bn% while (/4E.read((char;)>bn) $ S.5isplay()% /oundCC% if (/ound>>) cout!!HSorryJ Zook not foundJJJH!!endl% /4E.close( )%
!) Brite a function in #CC to add new obQects at the bottom of a binary file HS7G5+&7.567H* assuming the binary file is containing the obQects of the following class. , class S7G5 $ int no% char &ame'2% public-
200%;10 ODEL
F44 #omputer #hap A
11
6ny 5oubtT mrkdataUyahoo.com
void +nter( ) $ cin""no%gets(&ame)% void 5isplay( ) $ cout!!no!!&ame!!endl%
--in9ios--out)% cout""4no% cin.getline(4tem*2)% @@@@@@@@@@@@@@@@@ Statement 2 /ile.write((char;)this*si=eof(4tem))% /ile.close( )% Anse: Statement 1 /ile.seekg(ec&o;si=eof(4tem))%
% Ans) void 6ddnew( ) $ fstream /4E% /4E.open(HS7G5+&7.567H*ios--binary9 ios--app)% S7G5 S% char #P% do $ S.+nter()% /4E.write((char;)K^K)% /4E.close( )%
Statement 2 /ile.seekp(ec&o;si=eof(4tem))% (b) Brite a function in #CC to count the number of lines present in a teDt file 3S7O^.7F78. 2 Anse: void #ountEine( ) $ ifstream /4E(3S7O^.7F78)% int E4&+S>% char S7'I% while (/4E.getline(S7*I)) E4&+SCC% cout!!8&o. of Eines-8!!E4&+S!!endl% /4E.close( )%
200+;0% ODEL
!)Brite a function in #CC to search for a Zook&o from a binary file 3ZOOR.5678* assuming the binary file is containing the obQects of the following class. ,
include !fstream.h" class 4tem $ int 4no%char 4tem'2% publicvoid Search(int )% /unction to search and display the content from a particular record number void 0odify(int)% /unction to modify the content of a particular record number
class ZOOR $int Zno% char 7itle'2% publicint Zno( ) $ return Zno% void +nter( ) $ cin""Zno%gets(7itle)% void 5isplay( ) $ cout!!Zno!!7itle!!endl% % Anse: void ZookSearch() $ fstream /4E% /4E.open(3ZOOR.5678*ios--binary9ios--in)% ZOOR Z% int bn*/ound>% cout!!8+nter Zook &um to search`8% cin""bn%
% void 4tem--Search(int ec&o) $ fstream /ile% /ile.open(3S7O#R.5678*ios--binary9ios--in)% @@@@@@@@@@@@@@@ Statement 1 /ile.read((char;)this*si=eof(4tem))% cout!!4no!!8>>"8!!4tem!!endl% /ile.close( )% void 4tem--0odify(int ec&o) $ fstream /ile% /ile.open(3S7O#R.5678*ios--binary9ios ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
12
6ny 5oubtT mrkdataUyahoo.com
!) Brite a function in #CC to add new obQects at the bottom of a binary file 3S7G5+&7.5678* assuming the binary file is containing the obQects of the following class. , class S7G5 $ int no% char &ame'2% publicvoid +nter( ) $ cin""no% gets(&ame)% void 5isplay( ) $ cout!!no!!&ame!!endl% % Anse: void 6ddnew() $ fstream /4E% /4E.open(3S7G5+&7.5678*ios--binary9 ios--app)% S7G5 S% char #P% do $ S.+nter()% /4E.write((char;):^:)% /4E.close()%
while (/4E.read((char;)>bn) $ Z.5isplay( )% /oundCC% if (/ound>>) cout!!8SorryJ Zook not foundJJJ8!!endl% /4E.close( )% 200+;0% ODEL
include !fstream.h" class +mployee $int +no%char +name'2% public /unction to count the total number of records int #ountrec( )% % int 4tem--#ountrec( ) $ fstream /ile% /ile.open(3+0?.5678*ios--binary9ios--in)% @@@@@@@@@@@@@@ Statement 1 int Zytes > @@@@@ Statement 2 int #ount > Zytes si=eof(4tem)% /ile.close()% return #ount% 6nswer/ile.seekg(*ios--end)% Statement 1 /ile.tellg( )% Statement 2
DATA FILE HANDLING = I * /ound > % while (J/ound<
(b)Brite a function in #CC to count the number of alphabets present in a teDt file 3&O7+S.7F78. 2 Anse: void #ount6lphabet() $ ifstream /4E(3&O7+S.7F78)% int #6E?P6>% char #P>/4E.get( )% while (J/4E.eof( )) $ if (isalpha(#P)) #6E?P6CC% #P>/4E.get( )% cout!!8&o. of 6lphabets-8!!#6E?P6 !!endl% /4E.close( )% ?repared by- 0r.0.avi Riran
F44 #omputer #hap A
1,
6ny 5oubtT mrkdataUyahoo.com
$ if (4d > >#.@#id( )) $ cout !! 3+nter new 0arks8 % #.0arks#hange( ) % ------------ Statement1 @@@@@@@@@@@ Statement 2 /ound > 1 % ecordCC % if (/ound > > 1) cout !! 3 ecord Gpdated8 % /ile.close( ) % Brite the Statement to position the /ile ?ointer at the beginning of the ecord for which the #andidate:s 4d matches with the argument passed* and Statement 2 to write the updated ecord at that position. Ans) Statement 1 /ile.seekp(/ile.tellp( )Asi=eof(#))% Or /ile.seekp(ecord;si=eof(#))%
))%
".Brite a function in #CC to count the number of lowercase alphabets present in a teDt file 3ZOOR.7F78. S$,ti$n: void EowerEetters( ) $ clrscr( )% ifstream fin(HZOOR.7F7H*ios--in)% char ch% int lowercount>% while(fin) $ fin.get(ch)% if(islower(ch)) lowercountCC% cout!!HMn7otal number of Eowercase alphabets in the file > H !!lowercount% getch( )% 4. Brite a function to count the number of blanks present in a teDt file named 3?66.7F78 . S$,ti$n: void Zlanks#ount( ) $ clrscr( )% ifstream fin(H?66.7F7H*ios--in)% char ch% int Zlanks>% if(Jfin) $ cout!!8&o words at all in the file. So no blank spaces8% eDit()% while(fin) $ fin.get(ch)% if(ch> >: L) ZlanksCC% cout!!HMn7otal number of Zlank Spaces in the file > H !!Zlanks% getch( )%
Statement 2 /ile.write((char;)<#*si=eof(#))% Or /ile.write((char;)<#*si=eof(#andidate
2.Brite a function in #CC to count the words 3this8 and 3these8 present in a teDt file 3674#E+.7F78. '&ote that the words 3this8 and 3these8 are complete words Ans) void #OG&7 ( ) $ifstream /il% ifstream/il(3674#E+.7F7H)% /il. open(3674#E+.7F78)% char Bord'I *#h% int #l >* #2 > * 4>O% while(/il.get(#h)) $ if (#hJ > K K) Bord'4CC > #h% else $ Bord'4 > LM:% if (strcmp (Bord*3this8)>>) #lCC% else if (strcmp(Bord*3these8)>>) #2CC% 4>% cout!!3#ount of AthisA in file-H!!#l% cout!!3#ount of AtheseA in file-H!!#2% /il.close( )%
?repared by- 0r.0.avi Riran
F44 #omputer #hap A
3.Brite a function in #CC to read and display the detail of all the members whose membership type is LE: or L0: from a binary file 3#EGZ.5678. 6ssume the binary file 3#EGZ.5678 contains obQects of class #EGZ* which is defined as followsclass #EGZ $ int 0no% 0ember &umber char 0name '2% 0ember &ame char 7ype% 0ember 7ype- E Eife 0ember 0 0onthly 0ember uest publicvoid egister( )% /unction to enter the content 1Y
6ny 5oubtT mrkdataUyahoo.com
void 5isplay( )% /unction to display all data members char Bhat7ype( ) $ return 7ype% % Ans) void 5isplayE@0( ) $#EGZ #% fstream fin% fin. open (3#EGZ.5678* ios--binary9ios--in)% O ifstream fin (3#EGZ.5678* ios--binary)% while(fin.read((char;)<#* si=eof(#)) $ if(#.Bhat7ype()>>:E:99#.Bhat7ype()>>:0:) # .5isplay ( )% fin.close( )%
TEST 1.Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using tellg() and seekp() functions for performing the required task. include !fstream.h" class #ustomer $ long #no% char &ame'2*0obile'12% public/unction to allow user to enter the #no* &ame*0obile void +nter( )% /unction to allow user to enter (modify) mobile number void 0odify( )% /unction to return value of #no long et#no( ) $ return #no% %
/.iven a binary file 7+E+?PO&.567* containing records of the following class 5irectory class 5irectory $ char &ame'2 % char 6ddress', % char 6rea#ode'] % char phone@&o'1] % public % void egister( ) % void Show( ) % int #heck#ode(char 6#' ) $ return strcmp(6rea#ode* 6#) % % Brite a function #O?^6Z#( ) in #CC* that would copy all those records having 6rea#ode as 312,8 from 7+E+?PO&.567 to 7+E+Z6#R.567.
void #hange0obile( ) $#ustomer #% fstream /% /.open(3#O&76#7.5678*ios--binary9 ios--in9ios--out)% long #noc% #ustomer no. whose mobile number needs to be changed cin""#noc% while (/.read((char;)<#*si=eof(#))) $ if (#hoc>>#.et#no( )) $ #.0odify( )% int ?os>@@@@@@@@@@@@@ Statement 1 7o find the current position of file pointer @@@@@@@@@@@@@@ Statement 2 7o move the file pointer to write the modified record back onto the file for the desired #noc /.write((char;)<#* si=eof(#))% /. close ( ) %
S$,ti$n: void #O?^6Z#( ) $ ifstream fin(37+E+?PO&.567:*ios--in9 ios--binary)% ofstream fout(37+E+Z6#R.5678*ios--out*ios9 binary)% 5irectory 5% while(fin) or while(Jfin.eof( )) $ fin.read((char;)<5*si=eof(5))% if(5.#heck#ode(312,8)> > ) fout.write((char;)<5*si=eof(5))% fin.close( )% fout.close( )%
?repared by- 0r.0.avi Riran
F44 #omputer #hap A
2 Brite a function to count the number of words present in a teDt file named 3?66.7F78. 6ssume that each word is separated by a single blankspace character and no blanksspaces in the beginning and end of the file.
1]
6ny 5oubtT mrkdataUyahoo.com
".Brite a function in #CC to count the words 3this8 and 3these8 present in a teDt file 3674#E+.7F78. '&ote that the words 3this8 and 3these8 are complete words 4. Brite a function in #CC to search and display details. of all trains* whose destination is 35elhi8 from a binary file 3764&.5678. 6ssuming the binary file is containing the obQects of the following class.
class 764& $ int 7no% 7rain &umber char/rom'2% 7rain Starting ?oint char7o '2% 7rain 5estination publicchar; et/rom( ) $ return /rom% char; et7o( ) $ return 7o% void 4nput( ) $ cin""7no% gets(/rom)% gets(7o)% void Show( ) $ cout!!7no!!3-8!!/rom!!3-8!!7o!!endl % % 3. iven a binary file S?O7S.567*containg records of the following structure type-
struct Sports $ char +vent'2 % char ?articipant'1', % % Brite a function in #CC that would read contents from the file S?O7S.567 and creates a file named 67PE+74#.567 copying only those records from S?O7S.567 where the event name is 36thletics8.
?repared by- 0r.0.avi Riran
F44 #omputer #hap A
1
6ny 5oubtT mrkdataUyahoo.com