Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By Ravi Kiran

CBSE CLASS XII

DELHI : 2007

Q. 1.a. Observe the program segment given below carefully, and answer the question that follows :
class PracFile
{ int Pracno ;
char PracName[20]
int TimeTaken ;
int Marks ;
public :
void EnterPrac( ) ;//Function to enter PracFile details
void ShowPrac( ) ://Function to display PracFile details
int RTime( ) //function to return Time Taken
{return TimeTaken;}
void Assignmarks(int M) //Function to assign Marks
{ Marks = M ;}
} ;
void AllocateMarks( )
{ fstream File ;
File.open (“MARKS.DAT”, ios :: binary l ios :: in l ios :: out ) ;
PracFile P ;
int Record = 0 ;
while (File.read ( (char*) &P, sizeof (P) ) )
{ if (P.RTime( ) > 50)
P.Assignmarks(0)
Else
P.Assignmarks(10)

File.seekp(File.tellp( )-sizeof(P)); //Statement 1
//File.seekp(Record*sizeof(P));
File.write((char*)&P,sizeof(P)); //Statement 2
//File.write((char*)&P,sizeof(PracFile));

Record++ ;
}
File . close( ) ;
}
If the function AllocateMarks( ) is supposed to Allocate Marks for the records in the file
MARKS.DAT based on their value of the member TimeTaken. Write C++ 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.

Q. 4.b. Write a function in C++ to print the count of the word is as an independent word in a text file DIALOGUE.TXT.
For example,if the content of the file DIALOGUE.TXT is
This is his book. Is this book good ?
Then the output of the program should be 2.

Q. 4.c. Given a binary file GAME.DAT, containing records of the following structure type
struct Game
{ char GameName[20] ;
char Participate[10][30] ;
} ;
Write a function in C++ that would read contents from the file GAME.DAT and creates a file named BASKET.DAT copying only those records from GAME.DAT where the game name is“Basket Ball”.

Solution:

void BPlayers( )
{ ifstream fin(“GAME.DAT’,ios::in,ios::binary););
ofstream fout(“BASKET.DAT”,ios::out|ios::binary);
Game G;
while(fin) // or while(!fin.eof( ))
{ fin.read((char*)&G,sizeof(Game));
if(strcmp(G.GameName,”Basket Ball”)= = 0)
fout.write((char*)&G,sizeof(G));
}
fin.close( );
fout.close( );
}


Paper By Mr. Ravi Kiran
Email Id : [email protected]