Important Questions

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

CBSE CLASS XII

DATA FILE HANDLING OUTSIDE DELHI : 2008

Q. 1. Observe the program segment given below carefully, and answer the question that follows :
class candidate
{ long Cid ; // Candidate’s Id
char CName[20] ; // Candidate’s Name
float Marks ; // Candidate’s Marks
public ;
void Enter( ) ;
void Display( ) ;
void MarksChange( ) ; //Function to change marks
long R_Cid( ) {return Cid ;}
} ;
void MarksUpdate (long Id)
{ fstream File ;
File.open (“CANDIDATE.DAT”, ios :: binary|ios::in|ios :: out) ;
Candidate C ;
int Record = 0, Found = 0 ;
while (!Found&&File.read((char*)&C, sizeof(C)))
{ if (Id = =C.R_Cid( ))
{ cout << “Enter new Marks” ;
C.MarksChange( ) ;
File.seekp(File.tellp( )-sizeof(C)); //Statement 1
//File.seekp(Record*sizeof(C));
File.write((char*)&C,sizeof(C)); //Statement 2
//File.write((char*)&C,sizeof(Candidate));
Found = 1 ;
}
Record++ ;
}
if (Found = = 1)
cout << “ Record Updated” ;
File.close( ) ;
}
Write the Statement to position the File Pointer at the beginning of the Record for which the
Candidate’s Id matches with the argument passed, and Statement 2 to write the updated Record at that
position.

Q. 1. b Write a function in C++ to count the number of uppercase alphabets present in a text file “ARTICLE.TXT”.

Solution:

void UpperLetters( )
{ clrscr( );
ifstream fin("ARTICLE.TXT",ios::in);
char ch;
int uppercount=0;
while(fin)
{ fin.get(ch);
if(isupper(ch))
uppercount++;
}
cout<<"\nTotal number of Uppercase alphabets in the file = "<<uppercount;
getch( );
}

Q. 1c. Given a binary file TELEPHON.DAT, containing records of the following class Directory :
class Directory
{ char Name[20] ;
char Address[30] ;
char AreaCode[5] ;
char phone_No[15] ;
public ;
void Register( ) ;
void Show( ) ;
int CheckCode(char AC[ ])
{ return strcmp(AreaCode, AC) ;
}
} ;
Write a function COPYABC( ) in C++, that would copy all those records having AreaCode as “123”
from TELEPHON.DAT to TELEBACK.DAT.

Solution:

void COPYABC( )
{ ifstream fin(“TELEPHON.DAT’,ios::in|ios::binary);
ofstream fout(“TELEBACK.DAT”,ios::out,ios|binary);
Directory D;
while(fin) // or while(!fin.eof( ))
{ fin.read((char*)&D,sizeof(D));
if(D.CheckCode(“123”)= = 0)
fout.write((char*)&D,sizeof(D));
}
fin.close( );
fout.close( );
}


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