Page 60 - C++
P. 60
(b) Write a function in C++ to search and display details, whose destination is (3)
“Cochin” from binary file “Bus.Dat”. Assuming the binary file is
containing the objects of the following class:
class BUS
{ int Bno; // Bus Number
char From[20]; // Bus Starting Point
char To[20]; // Bus Destination
public:
char * StartFrom ( ); { return From; }
char * EndTo( ); { return To; }
void input() { cin>>Bno>>; gets(From); get(To); }
void show( ) { cout<<Bno<< “:”<<From << “:” <<To<<endl; }
};
OR
(b) Write a function in C++ to add more new objects at the bottom of a binary
file "STUDENT.dat", assuming the binary file is containing the objects of
the following class :
class STU
{
int Rno;
char Sname[20];
public: void Enter()
{
cin>>Rno;gets(Sname);
}
void show()
{
count << Rno<<sname<<endl;
}
};
(c) Find the output of the following C++ code considering that the binary file (1)
PRODUCT.DAT exists on the hard disk with a list of data of 500 products.
class PRODUCT
{
int PCode;char PName[20];
public:
void Entry();void Disp();
};
void main()
{
fstream In;
In.open("PRODUCT.DAT",ios::binary|ios::in);
PRODUCT P;
In.seekg(0,ios::end);
cout<<"Total Count: "<<In.tellg()/sizeof(P)<<endl;
8