One mark questions:
1. A ____ is a general name given to a flow of data.
a. bits b. stream c. Both a & b d. None
2. Each stream is associated with a ______.
a. Object b. class c. Both d. None
3. ____ is base class for all the iostreams.
a. Object b. iostream c. ios d. None
4. _______ is a technique that allows the user considerable flexibles in the way programs are
used.
a. Overloading b. redirection c. Both d.Overriding
5. Each file in C++ is an object of a ________
a. stream class b. bits class c. abstract d. None
6. ____ means existing in effect but not in reality.
a. abstract b. virtual c. Both d. None
7. _______ are used when invoking a program from DOS.
a. command line arguments b. parameters c. instructions d. None
8. _____ class includes all functions for input of data.
a. ofstream b. ifstream c. stream d. None
9. _____ class includes functions for output of data.
a. ofstream b. ifstream c. stream d. None
10. For working with files _____ header file is included.
a. stream.h b. fstream.h c. Both d. None
11. fstream.h incorporates _______ header file.
a. stream.h b. graphics.h c. iostream.h d. None
12. ______ are those files created by storing a block of memory.
a. ASCII b. binary c. non-ASCII d. Both b & c
13. ___ are those files created by storing each character.
a. ASCII b. binary c. non- ASCII d. None
14. The opening of files is automatically done by ____.
a. constructor b. initialiser c. Both d. None
15. EOF stands for ___
a. end of fstream b. end of file c. extra out file d. None
16. The ___ method of fstream class can open the file for reading/writing binary or text file.
a. constructor b. open( ) c. Both d. None
17. The parameters to read( ) are an pointer to the block and ____.
a. filename b. sizeof the block c. Both d. None
18. Each file object is associated with two integer values called ______
a. get pointer, put pointer b. show pointer, write pointer c. read, write d. None
19. The pointers specify the ____ number in the file.
a. byte b. bit c. file number d. None
20. The ____ functions are not part of the class but yet can access the private members of the
class.
a. virtual b. static c. friend d. None
21. Static polymorphism is also said to be ______ time polymorphism
a. compile b. interpreting c. run d. None
22. Dynamic polymorphism is also said to be ___ time Polymorphism
a. compile b. interpreting c. run d. None
23. Dynamic polymorphism is also said to be ____ binding
a. early b. late c. Both d. None
24. Static polymorphism is also said to be ___ binding
a. early b. late c. Both d. None
25. catch( ) is called as __________.
a.. exception handler b. throwing exception c. Both d. None
Two mark Questions
1. Which of the following functions belong to ifstream
i) get( ) ii) gets( ) iii) getline( ) iv) read( )
v) write( ) vi) put( )
a. I, ii, iii, iv b. I, iii, iv c. v, vi d. All
2. Which of the following functions belong to ofstream
i)get( ) ii) gets( ) iii) getline( ) iv) read( )
v)write( ) vi) put
a. I, ii, iii, iv b. I,iii, iv c. v, vi d. All
3. Which of the following are functions in fstream for binary reading and writing
i) get( ) ii) gets( ) iii) getline( ) iv) read( )
v) write( ) vi) put( )
a. iv, v b. I,ii,iii c. v, vi d. All
4. Which of the following are true for friend functions:
i) They do not belong to the class
ii) They belong to a class
iii) they are not transitive
iv) friendship can be inherited
a. ii, ii, iv b. I, iii, iv c. All d. None
5. seekg is for ____ and seekp is for _____
a) getpointer, putpointer b) putpointer,getpointer c) None
6. What is the prototype of the overloaded >> operator.
a. istream& operator>>(istream&, datatype&); b. ostream& operator<<(ostream&, datatype&);
c. istream& operator<<(istream&, datatype&); d. None
7. The feature of OOPs overrules the data – hiding concept are:
i) public members of a class
ii)friend functions and friend classes
a. only I b. only ii c. I, ii d. None
8. Which of the following are true for polymorphism
i) The ability to access different implementations of a function using the same name
ii) They overrule the concept of data-hiding
iii) There are two types of polymorphism : Dynamic & Static
a. only I b. I,iii c. All d. None
9. Which of the following is true for pointers to classes:
i) A pointer to base class can point to base class object as well as derived class object
ii) A pointer to derieved class can point to only its own object
a. Only I b. Only ii c. Both d. None
10. Which of the following are true for virtual functions:
i) The structure of virtual function in the base class and in the derived class is identical
ii) The keyword “virtual” is given only to base class function
iii) The “ virtual” keyword must be used even when redefining the function in the derived class
a. Only I,ii b. only I, iii c. All d. None
11. Give the syntax of declaring pure virtual functions:
a. virtual void fun()=0 b. pure virtual void fun( ){ } c. virtual void fun( ){ } d. None
12. Which of the following is true for pure virtual functions.
i) There is no implementation in the base class
ii) They are always initialized with 0
iii) The class containing this function becomes an abstract class
iv) when deriving the child class must override these functions.
a. only ii, iii b. I, iv c. All d. None
13. Which are the key words used in exception handling in C++:
i) try ii) throw iii) throws iv) catch
a. I, ii, iv b. I, ii c. All d. None
Four mark Questions
1. Which of the following is a valid program to open the file and write the contents to the file.
i) void main( )
{
ofstream outfile(“out.txt”);
outfile<<”Creating an ASCII file”<
ii) void main( )
{
ifstream outf(“out.txt”);
outf<<” Creating an ASCII test file<
iii) void main( )
{
ofstream outf;
outf<<”\n This is an ASCII file”;
outf<<”\n C++ is superset of C”;
}
iv) void main( )
{
ofstream outf(“out.txt”);
char text[]=” this is text line”;
int I=0;
while(text[I])
outf.put(text[I++]);
}
a. only ii b. I,iii c. I,iv d. None
2. Match the modes with their description:
1) in I) Opens the file for writing
2) out ii) Open file for binary data
3) ate iii) opens the file for reading
4) binary iv) erase file before reading or writing
a. 1- iii, 2- I, 3- iv, 4- ii b. 1- ii, 2-I, 3- iv, 4- iii c. 1-I, 2- ii, 3- iii,4- iv d.1- iv,2-iii, 3- ii, 4-1
3. What is the O/p:
void main( int argc,int *ss[])
{
int sum=0;
if (argc<3)
{
cout<<” Enter atleast two integers”; exit(0);
}
else
{
for(I=1;I
}
c:\> ss 10 20 30 40 50
a. 0 *b. 150 c. Error d. None
4.Give the O/P
class vehicle
{ public:
void message(){ cout<<”\n vehicle message”;}
};
class car:public vehicle
{ public:
void message ( ) { cout<<”\n car message”;}
};
void main()
{ vehicle *v;
v=new vehicle();
v->message();
v=new car( );
v-> message( );
}
a. vehicle message , car message b. vehicle message, vehicle message c. Error d. None
5.Give the O/P
class vehicle
{ public:
virtual void message(){ cout<<”\n vehicle message”;}
};
class car:public vehicle
{ public:
void message ( ) { cout<<”\n car message”;}
};
void main()
{ vehicle *v;
v=new vehicle();
v->message();
v=new car( );
v-> message( );
}
a. vehicle message , car message b. vehicle message, vehicle message c. Error d. None
6.Give the O/P
class vehicle
{ public:
virtual void message()=0;
};
class car:public vehicle
{ public:
void message ( ) { cout<<”\n car message”;}
};
void main()
{ vehicle *v;
v=new vehicle();
v->message();
v=new car( );
v-> message( );
}
a. vehicle message , car message b. vehicle message, vehicle message c. Error d. None
7. Which of the following is a valid program to open the file and read the contents to the file.
i) void main( )
{ ifstream infile(“out.txt”);
char buff[80];
while(infile)
{ infle.getline(buff,80);
cout<
}
ii) void main( )
{ ofstream infile(“out.txt”);
char buff[80];
while(infile)
{ infle.getline(buff,80);
cout<
}
iii) void main( )
{ ofstream outf;
outf<<”\n This is an ASCII file”;
outf<<”\n C++ is superset of C”;
}
iv) void main( )
{ ifstream outf(“out.txt”);
char c;
while(outf)
{
outf.get(ch); cout<
a. only ii b. I,iii c. I,iv d. None
8. Read the below program:
const int MAX=3;
class stack
{ int st[MAX],top;
public: class range{ };
stack(){ top=-1;}
void push(int var)
{ if(top>=MAX-1) throw range();
st[++top]=var;
}
int pop()
{ if(top<0) throw range();
return st[top--];
}
};
void main()
{ tack ss1;
try
{ s1.push(11);
s1.push(12);
s1.push(24);
cout<
}catch(stack::range)
{
cout<<”\n stack is full or empty”;
}
cout<<” arrived after catch”;
}
events :
i)The member function throws an exception ii) Code is executing normally outside a try block
iii) control transfers to the exception handler iv) control enters the try block
v) A statement inside try block causes an error in the member function
State the correct order of the events given
a. ii, iv, v, I, iii b. iii, iv, v, I, ii c. ii, iv, i, v, iii d. ii, iv, v, I, iii
Answer – 1 Marks
1. b 2. b 3. c 4.b 5.a 6.b 7.a 8.b 9.a
10.b 11.c 12.d 13.a 14.a 15.b 16.b 17.b 18.a
19.a 20.c 21.a 22.c 23.b 24.a 25.a
Answer – 2 Marks
1. b 2. c 3. a 4.b 5.b 6.a 7.c 8.b 9.c
10.a 11.a 12.c 13.a
Answer – 4 Marks
1. c 2. a 3. b 4.b 5.a 6.c 7.c 8.a