COMPUTER SCIENCE DATA FILE HANDLING

4.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( );
}

4.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( );
}

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( mrkdata@yahoo.com )


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling3.php on line 123

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling3.php on line 123

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling3.php on line 125

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/data_filehandling3.php on line 125