Topic Wise Solved Problems Question – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
CPP: Topicwise Exam Question: handling-binary-files siteicon
04B – Counting of object containing a particular string match in a binary file 2

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:

class TEACHERS
{
  int TID; char DEPT[20];
public:
  void GET()
  {
    cin>>TID;gets(DEPT);
  }
  void SHOW()
  {
    cout<<TID<<":"<<DEPT<<endl;
  }
  char *RDEPT(){return DEPT;}
};
CBSE12D-2017

04C 1

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.

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)<<endl;
  InFile.close();
}
CBSE12D-2017

Finding data match in binary file 3

Write a definition for function BUMPER( ) in C++ to read each object of a binary file GIFTS.DAT, find and display details of those gifts, which has remarks as “ÖN DISCOUNT”. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below:

class GIFTS
{
  int ID;char Gift[20],Remarks[20]; float Price;
  public:
  void Takeonstock()
  {
    cin>>ID;gets(Gift);gets(Remarks);cin>>Price;
  }
  void See()
  {
    cout<<ID<<":"<<Gift<<":"<<Price<<"":"<<Remarks<<endl;
  }
  char *GetRemarks(){return Remarks;}
};
CBSE12D-2016

Finding position in binary file using tellg() 1

Find the output of the following C++ code considering that the binary file MEM.DAT exists on the hard disk with a data of 1000 members.

class MEMBER
{
  int Mcode;char MName[20];
public:
  void Register();void Display();
};
void main()
{
  fstream MFile;
  MFile.open("MEM.DAT",ios::binary|ios::in);
  MEMBER M;
  MFile.read((char*)&M, sizeof(M));
  cout<<"Rec:"<<MFile.tellg()/sizeof(M)<<endl;
  MFile.read((char*)&M, sizeof(M));
  MFile.read((char*)&M, sizeof(M));
  cout<<"Rec:"<<MFile.tellg()/sizeof(M)<<endl;
  MFile.close();
}
CBSE12D-2016

04B 3

Write a definition for function Economic() in C++ to read each record of a binary file ITEMS.DAT, find and display those items, which costs less than 2500. Assume that the file ITEMS.DAT is created with the help of objects of class ITEMS, which is defined below:

class ITEMS
{
  int ID;char GIFT[20]; float Cost;
public :
  void Get()
  {
    cin>>CODE;gets(GIFT);cin>>Cost;
  }
void See()
  {
    cout<<ID<<":"<<GIFT<<":"<<Cost<<endl;
  }
  float GetCost() {return Cost;}.
};
CBSE12D-2015

Finding position in binary file using tellg() 1

Find the output of the following C++ code considering that the binary file CLIENTS.DAT exists on the hard disk with records of 100 members.

class CLIENTS
{
  int Cno;char Name[20];
public :
  void In(); void Out();
};
void main{)
{
  fstream CF;
  CF.open("CLIENTS.DAT",ios:: binary| ios::in) ;
  CLIENTS C;
  CF.read((char*)&C,sizeof(C));
  CF.read((char*)&C,sizeof(C));
  CF.read((char*)&C,sizeof(C));
  int POS=CF.tellg()/sizeof(C);
  cout<<"PRESENT RECORD:"<<POS<<endl;
  CF.close() ;
}
CBSE12D-2015

04C 1

Find the output of the following C++ code considering that the binary file SCHOOLS.DAT exists on the hard disk with the following records of 10 schools of the class SCHOOLS as declared in the previous question (4 b).

SCode SName NOT
1001 Brains School 100
1003 Child Life School 115
1002 Care Share School 300
1006 Educate for Life School 50
1005 Guru Shishya Sadan 195
1004 Holy Education School 140
1010 Rahmat E Talim School 95
1008 Innovate Excel School 300
1011 Premier Education School 200
1012 Uplifted Minds School 100

 

void main()
{
  fstream SFIN;
  SFIN.open("SCHOOLS.DAT",ios::binary|ios::in);
  SCHOOLS S;
  SFIN.seekg(5*sizeof(S));
  SFIN.read((char*)&S, sizeof(S));
  S.Display();
  cout<<"Record :"<<SFIN.tellg()/sizeof(S) + 1<<endl;
  SFIN.close();
}
CBSE12A-2018

04B 2

Write a definition for function TotalTeachers( ) in C++ to read each object of a binary file SCHOOLS.DAT, find the total number of teachers, whose data is stored in the file and display the same. Assume that the file SCHOOLS.DAT is created with the help of objects of class SCHOOLS, which is defined below:

 

class SCHOOLS
{
  int SCode; // School Code
  char SName[20]; // School Name
  int NOT; // Number of Teachers in the school
public:
  void Display()
  {cout<<SCode<<"#"<<SName<<"#"<<NOT<<endl;}
  int RNOT(){return NOT;}
};
CBSE12A-2018

04B 2

Write a definition for function COUNTPICS ( ) in C++ to read each object of a binary file PHOTOS.DAT, find and display the total number of PHOTOS of type PORTRAIT. Assume that the file PHOTOS.DAT is created with the help of objects of class PHOTOS, which is defined below:

class PHOTOS
{
  int PCODE;
  char PTYPE[20];//Photo Type as “PORTRAIT”,”NATURE”
public:
  void ENTER()
  {
    cin>>PCODE;gets(PTYPE);
  }
  void SHOWCASE()
  {
    cout<<PCODE<<":"<<PTYPE<<endl;
  }
  char *GETPTYPE(){return PTYPE;}
};
CBSE12A-2017

04C 1

Find the output of the following C++ code considering that the binary file CLIENTS.DAT exists on the hard disk with a data of 200 clients.

class CLIENTS
{
  int CCode;char CName[20];
public:
  void REGISTER();void DISPLAY();
};
void main()
{
  fstream File;
  File.open("CLIENTS.DAT",ios::binary|ios::in);
  CLIENTS C;
  File.seekg(6*sizeof(C));
  File.read((char*)&C, sizeof(C));
  cout<<"Client Number:"<<File.tellg()/sizeof(C) + 1;
  File.seekg(0,ios::end);
  cout<<" of "<<File.tellg()/sizeof(C)<<endl;
  File.close();
}
CBSE12A-2017

04B 3

Write a definition for function ONOFFER( ) in C++ to read each object of a binary file TOYS.DAT, find and display details of those toys, which has status as “ÖN OFFER”. Assume that the file TOYS.DAT is created with the help of objects of class TOYS, which is defined below:

class TOYS
{
  int TID;char Toy[20],Status[20]; float MRP;
  public:
  void Getinstock()
  {
    cin>>TID;gets(Toy);gets(Status);cin>>MRP;
  }
  void View()
  {
    cout<<TID<<”:”<<Toy<<”:”<<MRP<<””:”<<Status<<endl;
  }
  char *SeeOffer() { return Status; }
};
CBSE12A-2016

Binary file position determinations using tellg() 1

Find the output of the following C++ code considering that the binary file CLIENT.DAT exists on the hard disk with a data of 1000 clients.

class CLIENT
{
  int Ccode;char CName[20];
  public:
  void Register();void Display();
};
void main()
{
  fstream CFile;
  CFile.open(“CLIENT.DAT”,ios::binary|ios::in);
  CLIENT C;
  CFile.read((char*)&C, sizeof(C));
  cout<<”Rec:”<<CFile.tellg()/sizeof(C)<<endl;
  CFile.read((char*)&C, sizeof(C));
  CFile.read((char*)&C, sizeof(C));
  cout<<”Rec:”<<CFile.tellg()/sizeof(C)<<endl;
  CFile.close();
}
CBSE12A-2016

04B-2015 3

Write a definition for function COSTLY() in C++ to read each record of a binary file GIFTS.DAT, find and display those items, which are priced more that 2000. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below:

class GIFTS
{
  int CODE;char ITEM[20]; float PRICE;
public:
  void Procure()
  {
    cin>>CODE; gets(ITEM);cin>>PRICE;
  }
  void View()
  {
    cout<<CODE<<":"<<ITEM<<":"<<PRICE<<endl;
  }
  float GetPrice() {return PRICE;}
};
CBSE12A-2015

04C-2015 1

Find the output of the following C++ code considering that the binary file MEMBER.DAT exists on the hard disk with records of 100 members:

class MEMBER
{
  int Mno; char Name[20];
public:
  void In();void Out();
};
void main()
{
  fstream MF;
  MF.open("MEMBER.DAT”,ios::binary|ios::in);
  MEMBER M;
  MF.read((char*)&M,sizeof(M));
  MF.read((char*)&M,sizeof(M));
  MF.read((char*)&M,sizeof(M));
  int POSITION=MF.tellg()/sizeof(M);
  cout<<"PRESENT RECORD:"<<POSITION<<endl;
  MF.close();
}
CBSE12A-2015