COMPUTER SCIENCE DATA FILE HANDLING

4.b) Write a function in C++ to print the count of the word the as an independent word in a text file STORY.TXT.

For example,if the content of the file STORY.TXT is There was a monkey in the zoo.The monkey was very naughty. Then the output of the program should be .

2

Solution:Dear Children, try this answer.

 

4.c) Given a binary file SPORTS.DAT,containg records of the following structure type :

struct Sports
{ char Event[20] ;
char Participant[10][30] ;
} ;

Write a function in C++ that would read contents from the file SPORTS.DAT and creates a file named ATHLETIC.DAT copying only those records from SPORTS.DAT where the event name is “Athletics”.

Solution:

void AthletsList( )
{ ifstream
fin(“SPORTS.DAT’,ios::in,ios::binary););
ofstream fout(“ATHLETIC.DAT”,ios::out| ios::binary);
Sports S;
while(fin) // or while(!fin.eof( ))
{ fin.read((char*)&S,sizeof(Sports));
if(strcmp(S.Event,”Athletics”)= = 0)
fout.write((char*)&S,sizeof(S));
}
fin.close( );
fout.close( );
}

DELHI : 2006

4.a)

void main( )
{ char ch = ‘A’ ;
fstream fileout(“data.dat”, ios::out) ;
fileout<<ch ;
int p = fileout.tellg( ) cout<<p ;
}

What is the output if the file content before the execution of the program is the string “ABC”(Note that “ “ are not part of the file).

Ans) 1 (Since, the file is opened in out mode, it looses all the previous content, if the file mode is app, then result will be 4)

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( mrkdata@yahoo.com )


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling6.php on line 125

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling6.php on line 125

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling6.php on line 127

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling6.php on line 127