COMPUTER SCIENCE DATA FILE HANDLING

DELHI : 2005

4.a) Observe the program segment given below carefully, and answer the question that:

class Book
{ int Book_no :
char Book_name[20] ;
public ;
//function to enter Book details
void enterdetails( ) ;
//function to display Book details void showdetails( ) ;
//function to return Book_no int Rbook_no( ) {return Book_no ;}
} ; void Modify (Book NEW)
{ fstream File ;
File.open(“BOOK.DAT”, ios :: binary l ios :: in l ios :: out) ;
Book OB ;
int Record = 0, Found = 0 ;
while (!Found && File.read((char*) &OB, sizeof(OB) ) )
{ Recordsread++ ;
if (NEW.RBook_no( ) == OB.RBook_no( ))
{ ___________ //Missing Statement
File.write((char*) &NEW, size of(NEW)) ;
Found = 1 ;
}
else
File.write((char*) &OB, sizeof(OB)) ;
}
if (!Found)
cout << “Record for modification does not exist” ;
File.close( ) ;
}

If the function Modify( ) is supposed to modify a record in file BOOK.DAT with the values of Book NEW passed to its argument, write the appropriate statement for Missing Statement using seekp( ) or seekg( ), whichever needed, in the above code that would write the modified record at its proper place.

4.b) Write a function in C++ to count and display the number of lines starting with alphabet ‘A’ present in a text file “LINES.TXT”.

Example : If the file “LINES.TXT” contains the following lines,A boy is playing there. There is a playground.
An aeroplane is in the sky. Alphabets and numbers are allowed in the password. The function should display the output as 3

4.c) Given a binary file STUDENT.DAT, containing records of the following class Student type.

class Student
{ char
S_Admno[10] ; //Admission number of student
char
S_Name[30] ; //Name of student
int
Percentage ; //Marks Percentage of student
public :
void EnterData( )
{ gets(S_Admno) ;
gets(S_Name) ; cin >> Percentage ;
}
void DisplayData( )
{ cout << setw(12) << S_Admno ;
cout << setw(32) << S_Name ;
cout << setw(3) << Percentage << endl ;
}
int ReturnPercentage( ) {return Percentage ;}
} ;

Write a function in C++, that would read contents of file STUDENT.DAT and display the details of those Students whose Percentage is above 75.

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )