Page 233 - C++
P. 233
(b) Write a definition for function COUNTDEPT( ) in C++ to read each object of a
binary file TEACHERS.DAT, find and display the total number of teachers in the
department MATHS. Assume that the file TEACHERS.DAT is created with the
help of objects of class TEACHERS, which is defined below : 2
class TEACHERS
{
int TID; char DEPT[20];
public:
void GET()
{
cin>>TID;gets(DEPT);
}
void SHOW()
{
cout<<TID<<":"<<DEPT<<end1;
}
char *RDEPT(){return DEPT;}
};
(c) Find the output of the following C++ code considering that the binary file
BOOK.DAT exists on the hard disk with a data of 200 books. 1
class BOOK
{
int BID;char BName[20];
public:
void Enter();void Display();
};
void main()
{
fstream InFile;
InFile.open("BOOK.DAT",ios::binary|ios::in);
BOOK B;
InFile.seekg(5*sizeof(B));
InFile.read((char*)&B, sizeof(B));
cout<<"Book Number:"<<InFile.tellg()/sizeof(B) + 1;
InFile.seekg(0,ios::end);
cout<<" of "<<InFile.tellg()/sizeof(B)<<end1;
InFile.close();
}
91/1 8