MENU
Question -

Write a function in C++ to search for a camera from a binary file “CAMERA.DAT” containing the objects of class CAMERA (as defined below). The user should enter the model no and the function should search and display the details of the camera,

class CAMERA {
 long ModelNo;
 float Megapixel; int Zoom;
 char Details[120];
 public:
 void Enter(){cin>>ModelNo>>Megapixel >> Zoom;
 gets (Details);}
 void Display( )



Answer -

void cameraSearch ()
 {
 fstreamFIL;
 FIL.openCCAMERA.DAT", ios::binary|ios :: in );
 CAMERA B;
 long bn; int Found = 0;
 cout<<"Enter the Model Number"; cin >> bn;
 while (FIL.read((char*)&B, sizeof (B)))
 {
 if (FIL.GetModelNo() = = bn)
 {
 B.Display();
 Found ++;
 }}
 if(Found = = 0)
 cout<<"Sorry ! Camera not found"<
 FIL.close( );
 }

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×