DELHI : 2007
4.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)); //Statement2
//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.
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.
Solution:
Ans) Dear Children, try this answer.
CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )