1.

Write a function in C++ to search for a laptop from a binary file “LAPTOP.DAT” containing the objects of classLAPTOP (as defined below). The user should enter the Model No and the function should search and display thedetails of the laptop.class LAPTOP { long ModelNo; float RAM,HDD; char Details[120];public: void StockEnter() { cin>>Modelno>>RAM>>HDD; gets(Details); } void StockDisplay() {  cout<<ModelNo<<RAM<<HDD<<Details<<endl; } long ReturnModelNo() { return ModelNo; }};

Answer»

void Search( ) {

LAPTOP L; 

 long modelnum;

cin>>modelnum;

ifstream fin;

fin.open("LAPTOP.DAT",ios::binary|ios::in); while(fin.read((char*)&L,sizeof(L)))

{

if(L.ReturnModelNo( )==modelnum) L.StockDisplay( );

}

fin.close(); //Ignore

}



Discussion

No Comment Found

Related InterviewSolutions