UNIT II- Operator Overloading and Inheritance
One mark questions:
________ are those that have been redefined within a C++ class.
a) Method Overloading b) Operator Overloading c) Both a & b d) None
The internal call to an object ss++ will be made as _______
a) ss. operator++( ) b) ss. operator++(0) c) ss. operator++(1) d) None
_______ is a special pointer that points to the current object.
a) This b) new c) Both d) None
To prevent the member wise copy, it is necessary to provide the ______.
a) Copy Constructor b) Constructor c) Operator Constructor d) None
______ provides explicit conversion between datatypes.
a) Conversion b) Casting c) Both d) None
Operator int( ) is said to be ___________.
a) Conversion Function b) Casting Function c) Both d) None
To convert from basic to Object we use ______ in the class.
a) Conversion Function b) Constructor c) Both d) None
To convert from Object to basic we use ______ in the class.
a) Conversion Function b) Constructor c) Both d) None
Functions with same name but differing in their signatures is said to be ____.
a) Operator Overloading b) Function Overloading c) Both d) None
The process of creating new classes from already existing classes is said to be ____.
a) Inheritance b) Polymorphism c) Exceptions d) None
The access specifiers used while inheriting is used for ________.
determining availability of base class members to derived class
determining availability of derived class members to base class
determining availability of base class members to subclass class
determining availability of super class members to derived class
12. A member function in the base class can be used by the objects of the derived class ,this is
said to be __________.
a. Accessibility b. Reusability c. Both a & b d. None
13. ___ member can be accessed by the classes derived from the base class.
a. private b. public c. protected d. None
14. ______ inheritance does not change the specifiers of base class members.
a. private b. public c. protected d. None
15. ______ inheritance changes the specifiers of base class members to private of derived class.
a. private b. public c. protected d. None
16. ______ inheritance changes the specifiers of base class members to protected of derived class.
a. private b. public c. protected d. None
17. We cannot create an instance of _________ classes
a. virtual b. abstract c. protected d. None
18. A class derived from more than one class is said to be _______.
a. Multilevel b. Hierarchical c. multiple d. Both b & c
19.Inheritance is ________ relationship.
a. kind- of b. has a c. Both d. None
20.containership is ________ relationship.
a. kind- of b. has a c. Both d. None
Two mark Questions
1. Which of the following operators cannot be overloaded:
i) ++ ii) :: iii) ?: iv) . v) + vi) >>
a. ii, iii, iv b. ii, iii, iv, vi c. All d. None
2. When converting class to class we need _____ in destination class and ______ in source class
a. conversion function, constructor b. constructor, conversion function
c. nothing, conversion function d. constructor, nothing
3. Which of the following are the precautions while overloading:
i)use similar syntax
ii) Avoid ambiguity
iii) Not all operators can be overloaded
a. I only b. ii , iii c. All d. None
4. Which of the following is advantages of Inheritance:
i) Code reusability
ii) The protection is decreased
iii) We can add data and functions to class without affecting the base class.
a. I, iii b. ii, iii c. All d. None
5. The accessibility can be done by :
i) calling the base class functions in derived class
ii) substituting base class constructors
iii) substituting base class member functions
iv) Hiding the base class members
a. I,ii,iii b. ii, iii c. All d. None
6. Which of the following statements are true for method overriding:
i)Functions must have same name
ii) Functions may be in same class
iii) Functions must have same parameters
iv) Functions must be in base and derived class
a. I, iii, iv b. I, iii c. I,iv d. All
7. Which of the following statements are true for method overloading:
i)Functions must have same name
ii) Functions may be in same class
iii) Functions must have same parameters
iv) Functions must be in base and derived class
a. I, iii, iv b. I, ii c. I,iv d. All
8. Which of the following are true to prevent objects of the derived class calling the base class
function.
i) Make a dummy function in derived class of the same name and structure and give an error
message whenever called
ii) Make the derived class private
a. only I b. only ii c. Both I,ii d. None
9. Which of the following are true about abstract classes:
i) We can create an instance of this class.
ii) We cannot create an instance of this class
iii) They must contain atleast one virtual function
iv) They must contain atleast one pure virtual function
v) They are used only for deriving other classes
vi) The derived class must override all the pure virtual functions
a. ii, iv v, vi b. ii, iii, iv, v, vi c. All d. I, iii,iv,v
Four mark Questions
1. Explain the O/P
class A
{
int a;
public:
A(int h=0) { a= h;}
Void show( ) { cout<<”\n a=”< Void operator++( ){ ++a; cout<<”\n ++ no arg called”;}
Void operator++( int g){ ++a; cout<<”\n ++ one arg called”;}
};
void main( )
{
A ss(100);
++ss;
getch();
}
a. ++ no arg called b. ++ one arg called c. Both a & b d. None
2. Explain the O/P
class A
{
int a;
public:
A(int h=0) { a= h;}
Void show( ) { cout<<”\n a=”< Void operator++( ){ ++a; cout<<”\n ++ no arg called”;}
Void operator++( int g){ ++a; cout<<”\n ++ one arg called”;}
};
void main( )
{
A ss(100);
ss++;
getch();
}
a. ++ no arg called b. ++ one arg called c. Both a & b d. None
3. When is the copy constructor called in the following prog:-
class string
{
char ss;
public:
string(char *s=NULL){ strcpy(ss,s);}
string(string &s){ ss=strdup(s.ss); cout<<”\n copy called”;}
void disp( ) { cout<<”\n ss=”<
{
ss=strdup(s.ss); cout<<”\n assignment called”;
return (*this);
}
};
void main( )
{
1. string ss1(“ACME”),ss2;
2. ss2=ss1;
3. string ss3(ss2);
4. string ss4=ss1;
}
a. at line nos., 3,4 b. at line nos., 2,3,4 c. at line no., 3 only d. line no. 2
4. When is the assignment operator method called in the following prog:-
class string
{
char *ss;
public:
string(char *s=NULL){ strcpy(ss,s);}
string(string &s){ ss=strdup(s.ss); cout<<”\n copy called”;}
void disp( ) { cout<<”\n ss=”<
{
ss=strdup(s.ss); cout<<”\n assignment called”;
return (*this);
}
};
void main( )
{
1. string ss1(“ACME”),ss2;
2. ss2=ss1;
3. string ss3(ss2);
4. string ss4=ss1;
}
a. at line nos., 3,4 b. at line nos., 2,3,4 c. at line no., 2,4 d. line no. 2
5. What is the output:-
const int MAX= 10;
class stack
{
protected: int st[MAX},top;
public:
stack() { top= -1; }
void push(int var)( st[++top]=var; }
int pop( ) { return st[top--]; }
};
class stack2:public stack
{
public:
void push(int var)(
if(top+1
else
{cout<<”\n Error: stack is full”; exit(1);}
}
int pop( ) {
if(top>=0) return stack::pop( );
else
{cout<<”\n Error : stack empty”; exit(1); }
}
};
void main( )
{
stack2 ss1;
ss1.push(10);
ss1.push(11);
ss1.push(12);
cout<<”\n”<
a. Error b. 10 11 12 error:stack is empty c. None d. 10 11 12
6. What is the o/p:
class A
{
public:
void show(){
cout<<”\n class A”;}
};
class B
{ public: void show(){
cout<<”\n class A”;}
};
class C: public A, public B { };
void main( )
{
C ss;
ss.show();
}
a. class A b. class B c. Error d. None
7. What is the o/p:
class A
{
public:
void show(){
cout<<”\n class A”;}
};
class B
{ public: void show(){
cout<<”\n class A”;}
};
class C: public A, public B { };
void main( )
{
C ss;
ss.A::show();
ss.B::show();
}
a. class A b. class B c. Error d. Both a & b
8. What is the O/p:
class string
{
char *ss;
public:
string(char *s=NULL){ strcpy(ss,s);}
~string( ){ delete ss;}
int operator==(string &s)
{
int a;
if(strcmp(ss,s.ss)==0)
return 1;
else
return 0;
}
void disp(){ cout<
void main()
{
string s1(“ACME”),s2(“ACME”);
clrscr();
s1.disp();
s2.disp();
if(s1==s2)
cout<<”\n both are equal”;
else
cout<<”\n both are not equal”;
}
a. both are equal b. both are not equal c. Error d. None
9. What is the o/p:
class A
{
int a;
public: A(int h=0){ a=h;}
void show(){ cout<<”\n a=”< };
class B: public A
{
int b;
public: B(int h=0){ b=h;}
void show(){ cout<<”\n b=”<};
void main()
{
B ss(20);
ss.show();
}
a) a= 20 b) b=20 c) Both a & b d. None
10.What is the O/p
class A
{
int a;
public: A(){ a=0;}
A(int h){ a=h;}
void show_a(){ cout<<”\n a=”< };
class B: public A
{
int b;
public: B(){ b=0;}
B(int h){ b=h;}
void show_b(){ cout<<”\n b=”< };
void main()
{
B ss,ss2(10);
ss.show_a();
ss.show_b();
ss2.show_a();
ss2.show_b();
}
a) a=0 b=0 a= 0 b= 10 b) a=0 b=0 a=10 b= 10 c) Error d. None
11.In the below program Whish statement must be used instead of ? do that the
O/P is a=10 b=10
class A
{
int a;
public: A(){ a=0;}
A(int h){ a=h;}
void show_a(){ cout<<”\n a=”< };
class B: public A
{
int b;
public: B(){ b=0;}
? { b=h;}
void show_b(){ cout<<”\n b=”< };
void main()
{
B ss2(10);
ss2.show_a();
ss2.show_b();
}
i. B(int h) ii. B(int h):A(h+2) iii. B(int h):A(a) iv B(int h):A(h) v)B(int h):A(1)
a. Only I b. ii, iv, v c. ii, iii, iv, v d. iv, ii
12. What is the order of constructors called in the below program:
class A
{
public:
A() { cout<<”\n constructor A called”; }
~A() { cout<<”\n Destructor A called”; }
};
class B: public A
{
public:
B() { cout<<”\n constructor B called”; }
~B() { cout<<”\n Destructor B called”; }
};
class C: public A
{
public:
C() { cout<<”\n constructor C called”; }
~C() { cout<<”\n Destructor C called”; }
};
class D: public B, public C
{
public:
D() { cout<<”\n constructor D called”; }
~D() { cout<<”\n Destructor D called”; }
};
void main()
{ D ss; }
i) constructor C called
ii) constructor A called
iii) constructor D called
iv) constructor B called
a. ii, iv, I, iii b. ii, iv, ii, I, iii c. iii, I, iv, ii d. iii, I, ii, iv, ii
13. What is the order of destructors called in the below program:
class A
{
public:
A() { cout<<”\n constructor A called”; }
~A() { cout<<”\n Destructor A called”; }
};
class B: public A
{
public:
B() { cout<<”\n constructor B called”; }
~B() { cout<<”\n Destructor B called”; }
};
class C: public A
{
public:
C() { cout<<”\n constructor C called”; }
~C() { cout<<”\n Destructor C called”; }
};
class D: public B, public C
{
public:
D() { cout<<”\n constructor D called”; }
~D() { cout<<”\n Destructor D called”; }
};
void main()
{ D ss; }
i) Destructor C called
ii) Destructor A called
iii) Destructor D called
iv) Destructor B called
a. ii, iv, I, iii b. ii, iv, ii, I, iii c. iii, I, iv, ii d. iii, I, ii, iv, ii
Answers
One mark
1. b 11.a
2. b 12.a
3. a 13.c .
4.a 14.b
5.b 15.a
6.a 16.c
7.b 17.b
8.a 18.c
9.b 19.a
10.a 20.b
two marks
1. a
2. b
3. c
4.a
5.b
6.a
7.b
8.c
9.a
four marks
1. a 11.b
2. b 12.b
3. a 13.d
4.d
5.b
6.c
7.d
8.a
9.b
10.a
UNIT III- Templates, Pointers and Graphics
One mark questions:
1. ____ is a variable that holds the address of a data item.
a. reference b. pointers c. Both a& b d. None
2.Graphics mode require a graphics monitor and _______.
a. CGA b. EGA c. VGA d. All
3. To include a user-defined header file you use ____.
a. “ “ b. < > c. Both d. None
4. Templates are also known as ___________.
a. abstract data types b. Parameterized data types c. Both a & b d. None
5. When the class derives another class, ______ template is written for derived class.
a. different b. same c. Cannot be done d. None
6.Addresses are basically starting with _______
a. 0 b. 1 c. –1 d. None
7.If 640K memory then ___ is max address.
a. 0 b. 65535 c. 65534 d. 65536
8. _______ operator is used to allocate memory.
a. malloc( ) b. new c. Both a & b d. None
9. ______ operator is used to deallocate memory
a. free ( ) b. delete c. Both d. None
10. At the ___________ data structure is concerned with the actual storage location of data and
the relationship of different data items.
a. Physical level b. Logical level c. Both d. None
11. At the ____ data structure is concerned with the defined data relationships.
a. Physical level b. Logical level c. Both d. None
12. Data structures have _______ levels.
a. 1 b. 2 c. 4 d. 0
13. Inside the class, we can create _____ of its own type but we cannot create ___ of its own
type.
a. Object, Pointer b. Pointer, Object c. array, object d. None
14. How do you declare array of pointers.
a. *p b. (*p)[2] c. *p[2] d. None
15. How do you declare pointer to pointers.
a. **p b. (*p)[2] c. *p[2] d. None
16. What is the meaning of **p ____
a. the address of a pointer is a pointer to a integer
b. the address of a pointer is a pointer to a pointer c. Not available d. None
17. ____ function erases the text window.
a. clrscr( ) b. cleardevice( ) c. Both d. None
18. _____ header file is included for working with graphics.
a. stdio.h b. graphics.h c. windows.h d. None
19. _____ function positions the cursor within the text window.
a. move( ) b. gotoxy( ) c.moveto( ) d. None
20. _____ function releases the memory of graphics system.
a. close ( ) b. closegraph( ) c. Both a & b d. None
21. ____ function fills a bounded region with color.
a. setcolor( ) b. floodfill c. fillcolor( ) d. None
22. The viewports arguments are given in _____ coordinates
a. absolute screen b. graphics c. Cartesian d. None
23. If the value of the setviewport “clip” argument is set to ___, then all drawings will be clipped
the current viewport.
a. 0 b. non- zero c. Both d. None
Two mark Questions
1. Turbo C++ graphics functions can be categorized as
a) text mode only b. graphics mode only c. Both text and graphics d. None
2. Which of the following are true for template classes:-
i) Use the statement “template
ii) Use the statement “template
iii) T stands for new class
iv) T is name given instead of the data type for declaring private variables of the class.
a) I, iii b. I, iv c. ii, iii d. ii, iv
3. Which of the following are advantages of “new” operator:
i) It is superior to malloc in C
ii) Its return value needs to be casted
iii) it returns a pointer to appropriate data type
a. I,ii b. I , iii c. All d. None
4. Which of the following is true for “delete” operator.
i) It deletes the pointer that points to it
ii) It does not change the address value in the pointer
iii) The address is no longer valid
iv) the memory it points to holds the same value as before.
a. ii, iii b. I, ii, iii c. All d. None
5. Which of the following is true about linked list:
i) It is a data structure
ii) Each element is said to be a node
iii) Every element (node) contains data and pointer to next location
iv) the last node pointer contains NULL
a. only ii, iii b. Only I, iv c. All d. None
6. Which of the following are advantages of using linked list
i) It can be allocated when required
ii) It has fixed memory allocation
iii) It is more flexible storage
a. I, iii b. ii. iii c. All d. iii
7. Which of the following operations can be performed with single linked list:
i) create list ii) insert iii) delete iv) change
v) move forward vi) move backward
a. I, ii, iii, v b. I, ii, iii, iv, v c. All d. None
8. Which of the following can be performed with double linked list
i) create list ii) insert iii) delete iv)change
v) move forward vi) move backward
a. I, ii, iii, v b. I, ii, iii, iv, v c. All d. None
9. Which of the following are the valid attributes for the fillstyle patterns:
i) SOLID_FILL ii) SOLID_LINE iii) SLASH_FILL iv) HATCH_FILL
v) USER_FILL vi) DOT_FILL
a. I, iii, iv, v b. I, iii, iv, v, vi c. All d. None
10. Which of the following are valid values for settextjustify vertical alignments:
i) LEFT_TEXT ii) CENTER_TEXT iii) RIGHT_TEXT
iv) BOTTOM_TEXT v) TOP_TEXT
a. I, ii, iii b. ii, iv, v c. All d. None
11. Which of the following are valid values for settextjustify horizontal alignments:
i) LEFT_TEXT ii) CENTER_TEXT iii) RIGHT_TEXT
iv) BOTTOM_TEXT v) TOP_TEXT
a. I, ii, iii b. ii, iv, v c. All d. None
Four mark Questions
1. In which of the following areas pointers are used:
i) Accessing array elements
ii) Passing address arguments to functions when the function needs to modify the original
arguments
iii) passing arrays and strings to functions
iv) obtaining memory from the system- Dynamic memory allocation.
v) creating data structures such as linked list
a. ii, iii, iv b. I, ii, v c. All d. None
2. Read the program
template
class stack
{
T st[MAX];
Int top;
Public:
stack(){ top= -1;}
void push(T var){ st[++top]=var; }
T pop( ){ return st[top--]); }
};
void main( )
{
? ss;
ss.push(‘G’);
}
To create an object which can take characters what statement should be replaced for ?
a. stack b. stack
3. Match the following:
1) cleardevice ( ) I) positions the cursor at a position in graphics screen
2) clrscr( ) ii) clears the graphical screen
3) gotoxy( ) iii) positions the cursor in text window
4) moveto ( ) iv) clears the text window
a. 1- ii, 2- iv, 3- iii, 4- I b. 1- iii, 2- iv 3- ii, 4 – I c. 1- I, 2- ii, 3- iii, 4- iv d. 1- iv, 2- iii, 3- ii,4-I
4.Which of the following is the correct syntax of circle()
a. circle( int col, int row, int radius)
b. circle( int row,int col, int radius)
c. circle( int col, int row,int radius, int color)
d. circle(int row, int col, int radius, int color)
5. Match the functions with number of their arguments
1) line( ) I) int col, int row, int haxis, int vaxis
2) arc( ) ii) int col, int row, int stangle, int e_angle,int hor_rad,int ver_rad
3) ellipse( ) iii) int col,int row, int stangle, int eangle, int rad
4) fillellipse( ) iv) int col,int row,int col, int row
a. 1-ii, 2-iv, 3- iii, 4- I b. 1-iii, 2- iv,3- ii, 4-I c. 1-I,2-ii, 3-iii, 4- iv d. 1-iv,2-iii, 3- ii,4-I
6.Match the functions with their functionality
1) getx( ) I) returns the number of pixels in each row
2) getpixel( ) ii) returns the x coordinate
3) getmaxx( ) iii) plots the pixel at the specified location
4) putpixel( ) iv) returns an integer representing the colour of the pixel
a. 1- ii, 2- iv, 3- I, 4- iii b. 1-I, 2-ii, 3- iii, 4- iv c.1- iii, 2- I, 3-iv, 4- ii d. 1- iv,2- iii, 3- ii, 4- I
7. Match the functions with their functionality
1) detectgraph( ) I) It initializes the graphics system
2) initgraph( ) ii) releases memory of graphics system
3) cleardevice( ) iii) checks the system for graphics
4) closegraph( ) iv) clears the graphics window and places the cursor in (0,0)
a. 1-ii, 2- iv, 3- I, 4- iii b. 1-1, 2-ii, 3- iii, 4- iv c. 1- iii, 2- I, 3- iv, 4- ii d. 1-iv, 2- iii, 3-ii, 4- i
Answers
One mark
1. b 11.b 21.b
2. d 12.b 22.a
3. a 13.b 23.b
4.b 14.c
5.a 15.a
6.a 16.b
7.b 17.a
8.b 18.b
9.b 19.b
10.a 20.a
two mark
1. c 11.a
2. b
3. b
4.a
5.c
6.a
7.b
8.c
9.a
10.b
four mark
1. c
2. b
3. a
4.a
5.d
6.a
7.c
UNIT IV- Files and Streams,polymorphism and virtual function
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