A. calls the constructor for derived class, then the constructor for base class.
B. calls the destructor for derived class, then the constructor for base class.
C. calls the constructor for base class, then the destructor for derived class.
D. calls the constructor for base class ,then the constructor for derived class.
It makes sense, as the constructor for the derived class is build upon the data members of the base class.
A. private inheritance.
B. public inheritance.
C. protected inheritance.
D. unprotected inheritance.
Deriving publicly is a way of saying, “ is a type of “.
A. public inheritance.
B. protected inheritance.
C. private inheritance.
D. constructor inheritance.
It simply reflects an implementation shortcut.
A. public members of the derived class.
B. private members of the derived class.
C. protected members of the derived class.
D. unprotected members of the derived class.
In privately derived class, data can be accessed only through member functions of the derived class.
A. private in derived class.
B. protected in derived class.
C. unprotected in derived class.
D. public in derived class.
Visibility mode specifies whether the features of the base class are privately derived, or publicly derived or protected derived.
A. non private members of the base class.
B. private members of the base class.
C. public members of the derived class.
D. protected members of the base class.
The derived class cannot access the private members of its super class.
A. single inheritance.
B. multilevel inheritance.
C. multiple inheritance.
D. hierarchical inheritance.
Multilevel inheritance is, when a subclass inherits a base class that itself inherited from another base class.
A. multiple inheritance.
B. hybrid inheritance.
C. binary inheritance.
D. hierarchical inheritance.
Hybrid inheritance is the combination of different form of inheritance.
A. single inheritance.
B. multilevel inheritance.
C. multiple inheritance.
D. hierarchical inheritance.
In hierarchical inheritance many subclasses inherited from a single base class.
A. derived class.
B. super class.
C. base class.
D. inheritable class.
Derived classes (sub-classes) inherit the properties of a base class (super class).
A. increases readability.
B. increases time, money and efforts to use the code again.
C. increases reliability of a program.
D. increases writability.
Reusability is the feature using which we can use the already tested code again and again. It saves development time and easy to maintain.
A. double functions.
B. global functions.
C. polymorphic functions.
D. direct functions.
In C++, Polymorphic functions can be implemented using overloading functions and virtual functions.
A. the base class also changes.
B. changes reflected in the base class only and derived class remains the same.
C. both the base class and derived class changes.
D. the derived class changes whereas base class remains unchanged.
A derived class inherits all the features of a base class, and can add new features to it. But, by adding new features to the derived class, base class remains the same.
A. fstream.
B. instream.
C. ofstream.
D. ifstream.
The ifstream function provides an interface to read data from files as input streams.
A. get( ) and getline( ).
B. read( ) and write( ).
C. get( ) and put( ).
D. getline( ) and get( ).
The function get( ) extracts a character from the stream and returns its value and the function getline( ) extracts more than one character from the stream.
A. clear().
B. int eof().
C. int fail().
D. rdstate().
The function rdstate() returns the current internal error state flags of the stream. The internal error state flags are automatically set by calls to input/output functions to signal certain types of error that happened during their execution.
A. get( ) and put( ).
B. get( ) and getline( ).
C. seekg( ) and seekp( ).
D. tellg( ) and tellp( ).
The get( ) function extracts a character from the stream and returns its value . The put( ) function writes one character to the output stream.
A. output and ios :: app.
B. input and trunc.
C. output and binary.
D. input and ate.
Once the file gets opened in ios :: app mode, the previous records are retained and new data gets appended to the file.
A. ios :: nocreate.
B. ios :: app.
C. ios :: noreplace.
D. ios :: out.
ios :: noreplace causes the open( ) function to fail if the file already exists. This is used when one wants to create a new file at the same time.
A. filebuf.
B. ostreambase.
C. istreambase.
D. fstreambase.
fstreambase provides operations common to fstream, ifstream and ofstream file streams. It also contains open() and close() functions.
A. int ios::precision( ).
B. int ios::precision(int n).
C. int ios::precision(char n).
D. int ios::previousprecision(n).
int ios::precision(int n) sets the floating-point precision to 'n'. and returns the previous precision.
A. showbase.
B. showpos.
C. unitbuf.
D. skipws.
When the skipws format flag is set, as many whitespace characters as necessary are read and discarded from the stream until a non-whitespace character is found before every extraction operation. Tab spaces, carriage returns and blank spaces are all considered whitespaces.
A. ios::app.
B. ios:: binary.
C. ios::nocreate.
D. ios::noreplace.
With ios::app, every output is appended at the end of the file.
A. polymorphism.
B. inheritance.
C. buffering.
D. encapsulation.
Typically, the data is stored in a buffer as it is retrieved from an input device (such as a keyboard) or just before it is sent to an output device (such as a printer).
A. ios::ate.
B. ios::app.
C. ios::nocreate.
D. ios::in.
The file ios:ate helps to go to the end of the file when opened.
A. serial file.
B. parallel file.
C. sequential file.
D. temporary file.
A sequential file is designed for efficient processing of records in a sorted order on some search key.
A. ios::app.
B. ios::ate.
C. ios::trunc.
D. ios::nocreate.
In ios::trunc, if the file does not exist, a new empty file is created. If the file exists, its content is deleted and it is treated as a new file.
A. sequential file.
B. serial file.
C. temporary file.
D. permanent file.
A serial file is one in which the records are stored in the order in which they occur. They are not sorted into any particular order.
A. fileobject.seekg(20,ios:: end);
B. fileobject.seekg(20,ios:: beg);
C. fileobject.ofstream(20,ios:: end);
D. fileobject.ifstream(20,ios:: end);
seekg( ) sets the position of the get pointer at the beginning of the file. 20 indicates the position of the byte in a file.
A. fileobject.seekg(0,ios::beg);
B. ofstream afile(0,ios::beg);
C. ifstream(0,ios::beg);
D. fstream(0,ios::beg);
seekg( ) sets the position of the get pointer at the beginning of the file.
A. ifstream afile(“ EMP.DAT ”);
B. ofstream afile(“ EMP.DAT ”);
C. fstream afile(“ EMP.DAT ”);
D. open afile(“ EMP.DAT ”);
ofstream provides an interface to write data to files as output streams.
A. int good( ).
B. int fail( ).
C. int eof( ).
D. clear( ).
The function returns true if none of the stream's error flags are set. This function is not exactly opposite of bad( ), which only checks whether the bad bit error flag is set.
A. int bad( ).
B. int eof( ).
C. int fail( ).
D. int good( ).
The fail() function returns true if an error has occurred with the current stream, otherwise false . This can be used for checking whether the previous operation has failed.
A. legal in C++ only.
B. illegal in C++.
C. not possible either in C++ or C.
D. valid in C and C++.
Even though, we cannot create an object of an abstract class, but we can create a pointer to an abstract class.
A. dynamic binding.
B. static binding.
C. late binding.
D. null binding.
The binding which is done at the compile time is called static binding or early binding.
A. global derivation.
B. final derivation.
C. initial derivation.
D. public, private and protected derivation.
A class can be derived publicly, privately or protectedly. All three types of inheritance are possible.
A. we cannot derive a class from the base class.
B. we can derive a class from the base class.
C. we can partially derive a class from the base class.
D. first we have to find the source code, then only the class can be derived.
We just want the base class declaration, to derive a class from a base class. The declaration is generally present in the header files.
A. only accept arguments for itself.
B. only accept arguments for its base class constructor.
C. accept arguments for itself as well as for its base class constructor.
D. not accept any arguments.
A derived class constructor can invoke base class constructor by passing appropriate arguments that it received for a base class constructor.
A. can add new members to it.
B. can not add new members to it.
C. have to add new members to it, otherwise the class can not be accessed.
D. have to redefine the base class variables and members.
When we derive a class, we may or may not add new members to it. But to construct new members, new constructor (s) must be written for the derived class.
A. only once.
B. only twice.
C. more than once.
D. which is illegal in C++.
It is valid when a derived class inherits an indirect base class more than once.
A. public members of the derived class.
B. private members of the derived class.
C. protected members of the derived class.
D. global members.
With privatly derived class, the protected members of the base class become private members of the derived class.
A. double functions.
B. global functions.
C. polymorphic functions.
D. direct functions.
Polymorphic functions can be implemented using overloading functions and virtual functions.
A. multiple levels of inheritance.
B. single inheritance.
C. hierarchical inheritance.
D. multiple inheritance.
When a subclass inherited from a class which, itself inherited from another class, this is known as multilevel inheritance.
A. only by using scope resolution operator.
B. only using virtual.
C. by either using virtual or scope resolution operator.
D. by nesting classes.
We can declare common ancestor as virtual, or use ::,i.e.,scope resolution operator.
A. destructor.
B. constructor.
C. malloc().
D. calloc().
Constructor is a special member function, that allows us to set up values while defining the object, without the need to make a separate call to a member function.
A. The private members of the base class are visible in the derived class but they are not directly accessible.
B. The private members of the base class are not visible in the derived class and not accessible.
C. The private members of the base class are not visible in the derived class but they are directly accessible.
D. The private members of the base class are visible and directly accessible in the derived class.
Private members of a base class are not directly accessible in the base class but this does not affects their visibility.
A. IS-
A.
B. HOLDS-
A.
C. HAS-
A.
D. HAVE-
A.
A similar relation between two classes is known as HOLDS-A relation. It is similar to HAS-A relationship but ownership is missing in HOLDS-A relation.
A. private derivation.
B. public derivation.
C. protected derivation.
D. unprotected derivation.
Private inheritance should be used when the derived classes cannot be viewed as a type of their base class.
A. derive publicly.
B. derive protectedly.
C. derive privately.
D. not use inheritance.
Protected inheritance should be used, when the situation requires the attributes of base class to be available only to the derived class members but not to the outside world.
A. contained class object.
B. enclosed class object.
C. Super class object.
D. Derived class object.
A class may contain objects of another class. This situation is called nesting of objects and in such situation, the contained objects are constructed first before constructing the objects of the enclosing class.
A. private visibility mode.
B. protected visibility mode.
C. public visibility mode.
D. unprotected visibility mode.
With publicly derived class, public members becomes the public members of derived class and protected becomes protected members of derived class.
A. public derivation.
B. protected derivation.
C. private derivation.
D. unprotected derivation.
In public derivation, the inherited members need not be re-defined in the derived class.
A. on mode.
B. off mode.
C. visibility mode.
D. access specifiers.
There are three visibility modes: private, protected, and public.
A. field.
B. record.
C. attribute.
D. token.
Field is the smallest unit of a file. Field is characterized by its size, length and type.
A. the syntax of cin is wrong.
B. undefined symbol infile.
C. integer array cannot read getl() function.
D. get( ) cannot return the reference twice.
We cannot use two get() simultaneously in cin. get() function returns a reference to istream. It cannot return the reference twice.
A. fileobject.seekg(“EMP.DAT”);
B. ofstream afile(“EMP.DAT”);
C. instream seekg(“EMP.DAT”);
D. instream afile(“EMP.DAT”);
ofstream is used for output to a file. For an ofstream object, the file open mode can be either ios::out to output data to a file or ios::app to append data to the end of file.
A. fileobject.seekg(ios::beg);
B. fileobject.seekg(1,ios::beg);
C. fileobject.seekg(0,ios::beg);
D. fileobject.seekg(ios::begin);
seekg() function sets the position of the get pointer. The get pointer determines the next location to be read in the source associated to the stream.
A. fileobject.seekg(ios::beg);
B. fileobject.seekg(20,ios::beg);
C. fileobject.seekg(21,ios::beg);
D. fileobject.seekg(ios::begin);
seekg( ) function sets the position of the get pointer. The get pointer determines the next location to be read in the source associated to the stream.
A. data.
B. waterfall.
C. stream.
D. class.
A stream is a general name given to a flow of data. Different streams are used to represent different kinds of data flow.
A. verify the record.
B. check if the record is present or not.
C. identify the record.
D. check the number of attributes in a field.
A key field is a field or set of fields of a database (typically a relational database) table, which together form a unique identifier for a database record (a table entry).
A. three.
B. four.
C. five.
D. two.
When two sorted files are merged into a third file, three stream objects are required.
A. openfil().
B. openfile().
C. openfl().
D. open().
open() is ofstream member function which opens the file and attaches the file to the ofstream object.
A. constructor and destructor.
B. constructor and read() function.
C. constructor and write() function.
D. constructor and open() function.
A file can be opened in C++ by two methods: (a) By using the constructor of the stream class (b) By using the open() function of the stream class
A. open the file for appending.
B. seek to end of file on opening it.
C. discard contents if file exists.
D. if file doesn’t exist, open fails.
ios::ate seeks to end-of-file upon opening of the file. I/O operations can still occur anywhere within the file.
A. two.
B. three.
C. four.
D. five.
A file can be opened in C++ in two ways: (a)By using the constructor of the stream class (b)By using the open() function of the stream class
A. int.
B. buf.
C. cin.
D. getline.
The above statement is invalid as integer array cannot be read using getline() function.
The prototype of getline() function is -
istream & getline(char * buf, int num, char delim ='n');
The getline() function reads characters from input stream and puts them in the array pointed to by buf until either num characters have been read, or the character specified by delim is encountered.
A. char.
B. cin.
C. get.
D. ch.
We cannot use two get() simultaneously in cin. The get() returns a reference to istream. It cannot return the reference twice.
A. open().
B. read().
C. write().
D. tellp().
The prototype of write function is -
ostream& write ( const char* s , streamsize n );
It writes the block of data pointed by s, with a size of n characters, into the output buffer. The characters are written sequentially until n have been written.
This is an unformatted output function and what is written is not necessarily a c-string, therefore any null-character found in the array s is copied to the destination and does not end the writing process.
A. open().
B. read().
C. write().
D. tellp().
The prototype of read function is - istream& read ( char* s, streamsize n ); It reads a block of data of n characters and stores it in the array pointed by s.
A. put()
B. read()
C. write()
D. getline()
The functions read() and write() are used for reading and writing class objects. These functions handle the entire structure of an object as a single unit, using the computer's internal representation of data.
A. fstream.
B. streambuf.
C. filebase.
D. fstreambase.
fstreambase class provides a set of common functions.
A. one
B. two
C. three
D. none
Two for reading and the third for writing.
A. ios::in file mode
B. ios::binary file mode
C. ios::noreplace file mode
D. ios::ate file mode
The ios::ate file mode seeks to end-of-file upon opening of the file. I/O operations can still occur anywhere within the file.
A. By default, in C++, files are considered to be binary files.
B. A file can be opened using the constructor of the stream class.
C. To close a file, we disconnect it from the stream.
D. After disconnecting the file, the stream still exists.
The data files are the files that store data pertaining to a specific application for later use. The data files can be stored in two ways: text files and binary files. When we work with files in C++, unless we specify, files are by default considered and treated as text files.
A. is used with the filename.
B. is generally used with output mode.
C. returns value zero at end of file.
D. returns non zero value at end of file.
The function eof() is used to detect when the end of file is reached. The prototype is : int eof(); It returns nonzero when the end of file has been reached, otherwise it returns zero.
A. removes the delimiting character from the stream.
B. does not remove the delimiting character from the stream.
C. can have only 'n' as delimiting character.
D. is used to read binary files.
The get ()does not extract the delimiter character from the input stream.
A. get().
B. getline().
C. read().
D. input().
The function read() is used to read blocks of binary data.This function handles the entire structure of an object as a single unit, using the computer's internal representation of data.
A. we can write anywhere in the file.
B. previous data is discarded.
C. the file can only be read.
D. we can write only at the end of the file.
The ios::app file mode causes all output to that file to be appended to the end. This value can be used only with files capable of output.
A. a new file,not to be created, if the file exists.
B. the file, not to be created as binary file.
C. open() function to fail.
D. all output to that file to be appended to the end.
ios::nocreate constant causes the open() function to fail if the file does not already exist. It will not create a new file with that name.
A. there is no character conversion.
B. a character can have one of 256 possible values.
C. data is stored as it is in the memory.
D. characters are stored in ASCII format.
A text file stores information in ASCII characters. In text files, each line of text is terminated(delimited) with a special character known as EOL(End Of Line) character. In text files, some internal translations take place when this EOL character is read or written.
A. output purposes.
B. input purposes .
C. input/output purposes.
D. close purposes.
If the data(after some processing) is to be sent from memory to file, then the link can be said to be Memory-to-File link. So it is used for output purposes.
A. ios::app.
B. ios::out.
C. ios::ate.
D. ios::binary.
The ifstream open() method and constructor use ios :: in (open for reading) as the default value for the mode argument, while the ofstream open() method and constructor use ios :: out (open for writing) as the default.
A. iostream.h.
B. fileio.h.
C. fstream.h.
D. ifstream.h.
The classes defined inside fstream.h derive from classes under iostream.h.
A. fstreambase.
B. ostream.
C. filebug.
D. streambase.
The file I/O system of C++ contains a set of classes that define the file handling methods. These classes, designed to manage the disk files, are declared in fstream.h. Therefore, we must include this file in a program that works with files.
A. use a file mode constant.
B. open another stream.
C. disconnect it from the stream.
D. open it in text mode.
A file is closed by disconnecting it with the stream it is associated with. The close() function accomplishes this task and takes the following general form:
stream_object.close();
A. ifstream, ofstream, iofstream.
B. ifstream, ofstream, fstream.
C. istream, ostream, fstream.
D. istream, ostream, iostream.
The classes I/O system of C++ contains a set of classes that define the file handling methods. These classes, designed to manage the disk files, are declared in fstream.h. Therefore, we must include this file in a program that works with files. To create an input stream, you must declare the stream to be of class ifstream. To create an output stream, you must declare it as class ofstream. Streams that will perform both input and output operations must be declared as class fstream.
A. buffer().
B. flush()
C. end().
D. close().
A file is closed by disconnecting it with the stream it is associated with. The close() function accomplishes this task and it takes the following general form : stream_object.close(); close() function flushes the buffer before terminating the connection of the file with the stream.
A. is like an interface between the program and the file.
B. provides data from the file into the program.
C. opens the file, by default, to take data.
D. cannot be used for sequential operations.
The stream that supplies data to the program is known as input stream. It reads the data from the file and hands it over to the program. The stream that receives data from the program is known as output stream.
A. writes data into the file.
B. reads data from the file.
C. reads bytes randomly.
D. exists only for binary files.
The stream that supplies data to the program is known as input stream. It reads the data from the file and hands it over to the program.
A. one
B. two
C. three
D. none
Two objects are needed for reading the two files and third object is needed to write to the third file.
A. ios::in file mode.
B. ios::binary file mode.
C. ios::noreplace file mode.
D. ios::ate file mode.
This function seeks to end-of-file upon opening of the file.
A. put().
B. read().
C. write().
D. getline().
This function handles the entire structure of an object as a single unit, using the computer's internal representation of data.
A. ifstream, ofstream, iofstream.
B. ifstream, ofstream, fstream.
C. istream, ostream, fstream.
D. istream, ostream, iostream.
All C++ compilers come with classes for streaming input from the console and output to the console. These classes are defined by putting the directive #include
Function get() reads one character at a time but read() can read chunks like structures and objects at a time.
Some member functions of fstream class are seekp(), seekg(), tellg() and tellp(). Functions seekg() and tellg() are used with the input stream. Common forms of these functions are –
a) ifstream & seekg(long);
b) ifstream & seekg(long, pos) ;
c) long tellg();
In form a) seekg() positions the get pointer at an absolute position given by the long integer.
In form b) seekg() positions the get pointer at a position given by the long integer and by the value of pos.
Position can be - ios :: beg // from beginning of file
ios :: cur // from current position
ios :: end // from the end
In form c) tellg() gives the byte position of the get pointer in the file as a long integer.
ios::ate - This seeks to end-of-file upon opening of the file. I/O operations can still occur anywhere within the file.
ios::app - This causes all output to that file to be appended to the end. This value can be used only with files capable of output.
Both get() and getline() can read characters from the input stream into a character array till the specified number of characters are entered or till the delimiting character is encountered( ‘n’ by default). The major difference is that get() does not extract delimiter newline character from the input stream. On the other hand, getline() does extract the delimiter newline character from input stream so that stream type is empty after getline() is over.
Text files are also called ASCII files. They store information in the form of ASCII characters. There are 128 different ASCII codes. Also, text files contain lines of text and each of these has an end-of-line (EOL) marker automatically appended whenever you indicate that you have reached the end of a line. When a file is opened in text mode, various character translations take place. In case of binary files, information is stored in the same format in which it is stored in the memory. No character translation takes place when a binary file is opened, because of which binary files can be read and written faster by the computer.
#include < fstream.h>
class Employee{
int empcode;
char empname[20];
char depart[20];
public:
void getdat(){
cout<<"nEmployee Code : ";
cin>>empcode;
char c=cin.get();
cout<<"nEmployee Name : ";
cin.getline(empname,20);
cout<<"nDepartment : ";
cin.getline(depart,20);
}
void dispdat(){
cout<<"nEmployee Code : "<< empcode;
cout<<"nEmployee Name : "<< empname;
cout<<"nDepartment : "<< depart;
}
};
void main(){
Employee e;
int num=0;
char fname[13];
cout<<"Enter file name ";
cin>>fname;
ifstream ifl;
ifl.open(fname, ios::in|ios::binary);
if(!ifl){
cout<<"Cannot open file "<< fname;
return;
}
while(ifl) {
ifl.read((char*)&e,sizeof(Employee));
e.dispdat();
}
ifl.close();
}
#include < fstream.h >
#include < string.h >
class Book
{
int bookcode;
char bookname[20];
public:
void getdat()
{
cout<<"nBook Code : ";
cin>>bookcode;
char c=cin.get();
cout<<"nBook Name : ";
cin.getline(bookname,20);
}
void dispdat()
{
cout<<"nBook Code : "<< bookcode;
cout<<"nBook Name : "<< bookname;
}
int match(int cd)
{
if(cd==bookcode)
return 1;
else
return 0;
}
};
void main()
{
Book b;
ifstream ifl;
ifl.open("Books.dat",ios::in|ios::binary);
if(!ifl)
{
cout<<"Unable to open file - Returning";
return;}
while(ifl)
{
ifl.read((char *)&b,sizeof(Book));
b.dispdat();
}
}