Login


Lost your password?

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


Shop
CPP All : Handling Binary Files


Exam Papers Problems

04B #5686

( As In Exam - CBSE12A-2016 )

Write a definition for function ONOFFER( ) in C++ to read each object of a bi

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; }
};

Binary file position determinations using tellg() #5689

( As In Exam - CBSE12A-2016 )

Find the output of the following C++ code considering that the binary file C

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();
}

04B #5726

( As In Exam - CBSE12A-2018 )

Write a definition for function TotalTeachers( ) in C++ to read each object o

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;}
};

04C #5730

( As In Exam - CBSE12A-2018 )

Find the output of the following C++ code considering that the binary file SC

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();
}

04B #5788

( As In Exam - CBSE12A-2017 )

Write a definition for function COUNTPICS ( ) in C++ to read each object of a

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;}
};

04C #5793

( As In Exam - CBSE12A-2017 )

Find the output of the following C++ code considering that the binary file C

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();
}

04B #5892

( As In Exam - CBSE12D-2015 )

Write a definition for function Economic() in C++ to read each record of a b

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;}.
};

Finding position in binary file using tellg() #5895

( As In Exam - CBSE12D-2015 )

Find the output of the following C++ code considering that the binary file C

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() ;
}

04B-2015 #5977

( As In Exam - CBSE12A-2015 )

Write a definition for function COSTLY() in C++ to read each record of a bina

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;}
};

04C-2015 #5979

( As In Exam - CBSE12A-2015 )

Find the output of the following C++ code considering that the binary file M

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();
}

04B – Counting of object containing a particular string match in a binary file #6049

( As In Exam - CBSE12D-2017 )

Write a definition for function COUNTDEPT( ) in C++ to read each object of a

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;}
};

04C #6053

( As In Exam - CBSE12D-2017 )

Find the output of the following C++ code considering that the binary file B

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();
}

Finding data match in binary file #6182

( As In Exam - CBSE12D-2016 )

Write a definition for function BUMPER( ) in C++ to read each object of a bin

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;}
};

Finding position in binary file using tellg() #6184

( As In Exam - CBSE12D-2016 )

Find the output of the following C++ code considering that the binary file ME

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();
}



Exam Paper Problems:14 
×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Mult-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back