Important Questions

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

CBSE CLASS XII

DELHI : 2008

Q1.a. Observe the program segment given below carefully, and answer the question that follows :
class Applicant
{ long Aid ; // Applicant’s Id
char Name[20] ; // Applicant’s Name
float Score ; // Applicant’s Score
public ;
void Enroll( ) ;
void Disp( ) ;
void MarksScore( ) ; //Function to change Score
long R_Aid( ) {return Aid ;)
} ;
void ScoreUpdate (long Id)
{ fstream File ;
File.open (“APPLI.DAT” , ios :: binary l ios :: in l ios :: out) ;
Applicant A ;
int Record = 0, Found = 0 ;
while (!Found && File.read( (char*)&C, sizeof(c) ) )
{ if (Id = = A.R_Aid( ) )
{ cout << “Enter new Score” ;
A.MarksScore( ) ;

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

Found=1;
}
Record++ ;
}
if (Found = = 1)
cout << “Record Updated” ;
File.close( ) ;
}
Write the Statement1 to position the File Pointer at the beginning of the Record for which the
Applicant’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 lowercase alphabets present in a text file “BOOK.TXT”.

Solution:

void LowerLetters( )
{ clrscr( );
ifstream fin("BOOK.TXT",ios::in);
char ch;
int lowercount=0;
while(fin)
{fin.get(ch);
if(islower(ch))
lowercount++;
}
cout<<"\nTotal number of Lowercase alphabets in the file = "<<lowercount;
getch( );
}

Q. 1.c. Given a binary file PHONE.DAT, containing records of the following structure type
class phonlist
{ char Name[20] ;
char Address[30] ;
char AreaCode[5] ;
char PhoneNo[15] ;
public ;
void Register( ) ;
void Show( ) ;
int CheckCode(char AC[ ])
{ return strcmp(AreaCode, AC) ;
}
} ;
Write a function TRANSFER( ) in C++, that would copy all those records which are having
AreaCode as “DEL” from PHONE.DAT to PHONBACK.DAT.

Solution:

void TRANSFER( )
{ ifstream fin(“PHONE.DAT’,ios::in,ios::binary);
ofstream fout(“PHONEBACK.DAT”,ios::out,ios::binary);
phonlist P;
while(fin) // or while(!fin.eof( ))
{ fin.read((char*)&P,sizeof(P));
if(P.CheckCode(“DEL”)= = 0)
fout.write((char*)&P,sizeof(P));
}
fin.close( );
fout.close( );
}


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