1.

Write a function in C++ to search and display details, whose destination is “Cochin” from binary file “Bus.Dat”. Assuming the binary file is containing the objects of the following class:class BUS{ int Bno; // Bus Numberchar From[20]; // Bus Starting Pointchar To[20]; // Bus Destinationpublic:char * StartFrom ( ); { return From; }char * EndTo( ); { return To; }void input() { cin>>Bno>>; gets(From); get(To); }void show( ) { cout<<Bno<< “:”<<From << “:” <<To<<endl; }};

Answer»

void Read_File( )

{

BUS B;

ifstream Fin;

Fin.open(“Bus.Dat”, ios::binary);

while(Fin.read((char *) &B, sizeof(B)))

{

if(strcmp(B.EndTo(), “Cochin”)==0)

{

B.show( ) ;

}

}

Fin.close( );

}



Discussion

No Comment Found

Related InterviewSolutions