Introduction To OOP
1)
Functions are also called as
__________.
a) Subroutines b) subprograms c) Procedures d)
All
2)
POP stands for _______
a)
Procedure Oriented Programs b)
Program oriented procedure
c)
Procedural oriented programs d)
None
3)
OOP stands for _______
a) Object oriental
programming b) Object oriented programming
c) Optical Object
programs d)
None
4)
____ is a feature which we can change the data
structure of an object without affecting the
operation of the
program.
a) Data
encapsulation b) Data
abstraction/hiding c) Reusability d) None
5)
_________ is generally shorter because
objects are small and contain independent code.
a) Application
debug b) Application
implementation c) Application
testing d) None
6)
C++ was developed by _________.
a) Denis Ritchie b) Bjarne Stroustrup c) James Gosling d) None
7)
It was developed in which year ____
a) 1980 b) 1986 c) 2000 d) 1886
8)
______ was the first release of C++.
a) 1.0 b) 1.1 c) 1.2 d) 2.0
9)
It was released by ________ company.
a) Microsoft b) AT&T c) IBM d) Oracle
10)
C++ is superset of _____.
a) C b) Java c)
VB d)
None
11)
_____ is said to be an instance of a
class.
a) Variable b) Object c) Both a &
b d) none
12)
______ is single unit of data and
functions that operate on the data.
a) Object b) Class c) Both a
& b d) None
13)
________ describes the data and its
behavior or functionality.
a) Object b) Class c) Both a
& b d) None
14)
The method of ________ is the process
of dividing into subclasses.
a) Inheritance b) Polymorphism c) Both a & b d) None
15)
A _______ is a data type defined by
user describing the data it represents.
a) Object b) Class c) Both a &
b d) None
16)
In inheritance the main class is said to be ____
a) Parent class b) super class c) Base class d) None
17)
The concept of _____ provides an
important extension to the idea of reusability.
a) Inheritance b) Polymorphism c) Both a & b d) None
18)
______ allows to create multiple
definitions for operators and functions and at run – time depending on the
context a particular definition will be used.
a) Inheritance b) Polymorphism c) Both a & b d) None
19)
___________ is a kind of polymorphism.
a)Overloading b) Overriding c) Both a & b d) None
20)
_____ is a feature by which the
operators +,-,etc., can be made to work with our class.
a) Operator
overloading b) Function overloading c) Both a & b d) None
21)
The extension of C++ is _____.
a) C b) CPP c) .CP d) None
22)
On compilation, of C++ source code we
get ____ file.
a) . CPP b) .EXE c) .OBJ d) None
23)
On linking, of C++ source code we get
____ file.
a) . CPP b) .EXE c) .OBJ d) None
24)
________ functions saves memory space
as the code is not repeatedly compiled.
a) Normal
b) Inline c)
Static d)
None
25)
The local variables are stored in
______
a) Data segment b) Stack Segment c) Hash Segment d) None
26)
The static and global variables are
stored in ______
a) Data segment b) Stack Segment c) Hash Segment d) None
27)
The “ #include” is said to be a
___________
a) Empty statement b) preprocessor
directive c) Pragma d) None
28)
____ is the object used to display
information on standard output device.
a) cin b) printf c) cout d) None
29)
>> is said to be _____ operator.
a) Insertion b) Extraction c) Put d)
None
30)
<< is said to be _____ operator.
a) Insertion b) Extraction c) get d) None
31)
______ is the manipulator.
a) endl b) setw c) Both a
& b d) None
32)
_____ is the maximum number of
characters in a variable name.
a) 5 b) 32 c) 256 d) 1024
33)
________ is a fixed value throughout
the program.
a) Variables b) Constants c) Both a & b d) None
34)
____ is exponent form
a) –14E-2 b)
–14-E+2 c)
–14-E2 d)
None
35)
________ specifies what the variable
name is and what type it will hold.
a) Data Type b) Data Declaration c) Both a & b d) None
36)
An array is collection of _____ data.
a) Homogeneous b) Heterogeneous c) Both d) None
37)
The position in array is represented
by ____
a) Subscript b)
Indicator c)
Both d)
None
38)
The index of an array starts with __
a) 1 b) 0 c)
–1 d)
None
39)
The maximum number of dimensions
depends on ____.
a) Interpreter b) Compiler c) Operating system d) None
40)
________ defines the set of all names
that will be permissible values of the type.
a) Structures b) Enum c) Both d) None
41)
______ is a datatype which is used to
define heterogeneous set of data types.
a) Structures b) enum c) Array d) None
42)
The assignment statement is called
____ statement.
a) Static b) Dynamic c) Put d) None
43)
____ is modulus operator.
a) / b) ^ c) % d) &
44)
Type _____ is implicitly done.
a) Casting b) Conversion c) Both a& b d) None
45)
Type _____ is explicitly done.
a) Casting b) Conversion c) Both a & b d) None
46)
The conditional operators return _____
a) true, false b) 0, 1 c) yes, no d)
None
47)
The set of compound statements
enclosed within { } is said to be _____.
a) Group b) Block c) Stack d) Heap
48)
____ is said to be statement
terminator.
a) . b) ; c) : d) –
49)
_____ is said to be unconditional
branching.
a) If b)
Switch c) Goto d) None
50)
The loops perform the task until
expression evaluates to ______.
a) true b) false
51)
In ____ loop , the statements are to
be executed atleast once for condition to be verified.
a) While b)
DO.. WHILE c) For d) None
52)
The functions associated with a class
are called.
a) functions b) procedure c) methods d) All
53)
The _____ feature ties data and
procedures logically together.
a) data hiding b) data encapsulation c) Both d) None
54)
The ____ feature is that the data is
concealed within a class.
a) Data Hiding b) Data Abstraction c) Both d) None
55)
The ____ refers to calls to member
functions.
a) Messages b) Overloading c) Both a & b d) None
56)
The default access specifier for
structures is _____
a) Public b) Private c)
Protected d)
None
57)
The default access specifier for class
is ___
a) public b) private c)
friendly d)
None
58)
Automatic initialization is carried
out using a special member function called the ____.
a) Starter b) Initialiser c) constructor d) None
59)
_______ is invoked when the compiler
returns to the calling function.
a) Constructor b) Destructor c) Both a & b d) None
60)
_____ is said to be scope resolution
operator.
a) : b) :: c) ?: d)
None
61)
_____ is said to be scope conditional
operator.
a) : b) :: c) ?: d)
None
62)
If a data item in a class is defined
as ____, then only one such item is created for entire class.
a) Private
b) Static c)
Extern d)
None
Two mark Questions
1)
Which of the following are true for
POP:
1) Data is given secondary status.
2) There is data-hiding
concept
3) More emphasis is on
doing things by functions
4) There is
data-encapsulation concept
a) I, ii b) I, iii c) ii, iv d) None
2)
Which of the following are true for
OOP.
i) Data is given primary
status
ii) There is data-hiding
concept
iii) More emphasis is on
doing things by functions
iv) There is
data-encapsulation concept
a. I, ii only b. ii, iii, iv c)
I, ii, iv d)
None
3)
In which of the two categories OOP
fall:
a) Increased programming,
decreased maintenance cost
b) Decreased programming,
increased maintenance cost
c) Increased speed,
decreased maintenance cost
d)
None
4)
Which of the following are principles
of Inheritance.
i) Each subclass shares
common characteristics
ii) Each subclass can have
its own particular characteristics.
a) I only b) ii only
c) Both I, ii d. None
5)
The term ____ and ____ are used
interchangeably.
a) Overloading,
polymorphism b)
Overloading, inheritance
c) Reusability,
inheritance d)
Reusability, Polymorphism
6)
The functions are overloaded means:
i)
Their names are different
ii)
They can have same number of arguments, but data types different
iii) They can have
different number of arguments
iv) They have same names
a) I, iii b) ii, iii, iv c) All d)
None
7)
Specify the order in which the source
code is converted to executable file.
i)
Source text file
ii)
Verify
iii)
Link
iv)
Compile
v) Testing
vi) Execute
a)
I, iv, iii, vi b) ii,
iv, iii, vi c) iv, I, ii, v d) ii, iii, iv, v
8)
Which of the following are valid
access specifiers for members of the class:
i) Global
ii) Private
iii) auto
iv) extern
v) protected
vi) public
vii) static viii)
final
a)
ii, iv, v, viii b) ii,
vi, v c) I, iii, vi, v d) All
9)
What is the range of integer values
a) –32768,32767 b) 0, 32768 c) 32768,0 d) None
10)
Which of the following are true for
structures:
i) The template must be
terminated with semicolon
ii) The tag-name can be
used to declare structure variables.
iii) The structure members
cannot be initialized inside the template
a)
I only b) ii,
iii
c) All d)
ii only
11)
Which of the following are valid
expressions:
i) A signed or unsigned
variable
ii) A signed or unsigned
constant
iii) Variables connected
by ,(comma) operator
iv) A variable or constant in parenthesis
a) I, ii, iv b)
I, iv only c)
All d)
None
12)
______ are the statements used only
within a loop.
a) Break b) Continue c) Exit d Both a,b
13)
Match the access specifiers:
1)
Private I)
can be accessed outside the class
2) Public ii)
can be accessed only by parent and child classes
3) Protected iii) can be
accessed only within the class
a) 1- I, 2- ii , 3 – iii b) 1- iii, 2- I , 3- ii c) 1- ii, 2- iii, 3- I d) 1-iii, 2- ii, 3 – I
14)
Which of the following are true for
constructors:
i) They have same name as
that of the class
ii) they have (~)
preceding the name.
iii) They are
automatically called at the time of creating the object
iv) They cannot be
overloaded.
a) I, iii b)
I, ii c)
ii, iv d)
iii, iv
15)
Which of the following are true for
destructors:
i) They have same name as
that of the class
ii) they have (~)
preceding the name.
iii) They are
automatically called at the time of creating the object
iv) They cannot be
overloaded.
a)
I, ii, iii b)
I, ii c)
ii, iv d)
iii, iv
Four mark Questions
1)
Which of the following are the
features of C++
i)
Multiple inheritance ii)
Implicit support for abstract classes
iii)
pointers to class members iv)
Operator overloading
a) All b) I, ii only c) I, iii, iv d) None
2)
Match the following:
Escape
Sequence Character
1) \a I)
Tab
2) \x add ii)
bell(beep)
3) \t iii)
backslash
4) \\ iv)
Hexadecimal representation
v)
Backspace
a) 1- ii; 2- iv; 3-
I; 4- iii b) 1 – iii; 2- iv ; 3-
v; 4 – I c) 1- v; 2- iv; 3- I; 4-
iii d) None
3)
What is the O/P:
struct ss
{
int
sno,age;
float
fee;
char
name[30];
};
void main()
{
cout<
}
a) 36 b. 38 c) 30 d) 4
4)
Give the o/p:
void main()
{
int
I=10;
cout<<++I<<”\t”<
}
a)
12 11 10 b)
11 11
11 c)
10 10
10 d)
11 10
10
5)
Arrange the operators from higher at
top to lowest is bottom:
i) *,-,/,%,+
ii) < , >,
==, !=, >=, <=
iii) ?:
iv) ( )
v) &&, ||
vi) !, ++, - -, -
vii)
=,+=,-=,*=,/=,%=
a) ii, iv, iii, I,
vii, v, vi b) iv, vi, I, ii, v, iii, vii c) iv, vi, ii, I,
v, vii, iii d) I, iii, ii, v, vi, vii, ii, iv
6)
What does the following program do :
void
main()
{
char
x;
cout<<”\n
enter a character “;
cin>>x;
switch(x)
{
case
‘A’: case ‘a’:
case
‘E’: case ‘e’:
case
‘I’: case ‘i’:
case
‘O’: case ‘o’:
case
‘U’: case ‘u’:
cout<<”\n
vowel”; break;
default:
cout<<”\n
consonant”’;
}
}
a) Accepts a
character and displays Vowel or consonant
b) Accepts a string
and checks characters which are vowel or not
c) Error
d) None
7)
Give the O/P:
for(I=0;I<5 o:p="o:p">5>
{
if(I==3)
continue;
cout<<”\n”<
}
a) 1 2
4 5 b) 0
1 2 4 5 c)
0 1 2
3 5 d) 1
2 3 5
8)
Give the O/p :
class myclass
{
int num;
public:
myclass(){num=0;}
myclass(int n){num=n;}
void sh(){
cout<<”\n num=”<
};
void main()
{
num n1, n2(30);
n1.sh();
n2.sh();
}
a) num = 0 num = 30 b)
num=” “
num=30 c) num=junkvalue
num=30 d) error
9)
Give the O/p :
class myclass
{
int
num;
public:
myclass(int n){num=n;}
void sh(){
cout<<”\n num=”<
};
void main()
{
num n1, n2(30);
n1.sh();
n2.sh();
}
a) num = 0 num = 30 b)
num=” “
num=30 c) num=junkvalue
num=30 d) error
10)
Discuss the O/P:
class try
{
int id,tot;
public:
try(){tot=0;
tot++; id=tot;}
void
print()
{
cout<<”\n id is
“<
}
};
void main()
{
try
ss1,ss2;
ss1.print();
ss2.print();
}
a) id=1 count=1 b)
junk values c) Error d) None
11)
Discuss the O/P:
class try
{
int id;
static
int tot
public:
try(){
tot++; id=tot;}
void
print()
{
cout<<”\n id is “<
}
static
void printcount()
{
cout<<”\n number of instances
“<
}
};
int try::tot=0;
void main()
{
try
ss1,ss2;
try::printcount();
}
a) 1 b) 2 c) 0 d)
None
12)
What does the following program do:
void
main()
{
int
c;
for(c=65;c<=122;c++)
{
if(c>90
&& c<97 o:p="o:p">97>
continue;
cout<
}
}
a) Displays numeric
set b) displays alphabet set c) displays char., set d) Error
13)
What does the following program do:
void main()
{
int n[10],I,j,temp;
cout<<”\n Enter 10 numbers:”;
for(I=0;I<10 o:p="o:p">10>
cin>>n[I];
for(I=0;I<9 o:p="o:p">9>
{
for(j=I+1;j<10 j="j" o:p="o:p">10>
{
if(n[I]>n[j])
{
temp=n[I];
n[I]=n[j];
n[j]=temp;
}
}
}
for(I=0;I<10 o:p="o:p">10>
cout<<”\n”<
}
a) Displays the
entered numbers in ascending order
b) Displays the
entered numbers in descending order
c) Both a & b
d) None
14)
Which of the one is the correct logic
for reversing the string:
i) void main() ii)
void main()
{ {
char ss[80]; char ss[80],ss1[80];
cout<<”\n enter a string”;
cout<<”\n enter a
string:”; cin.getline(ss,80);
cin.getline(ss,80); strcpy(ss1,ss);
int l=strlen(ss); strrev(ss1);
for(l=l-1;l>=0; l- -) cout<<”\n reverse is “<
cout<
}
a) I only b) ii only c) Both I, ii d) None
15)
What is the O/P of :
class A
{
int
a;
A()
{a=0;}
public:
void
show()
{
}
};
void
main()
{
A
ss;
ss.show();
}
a) 0 b)
Junk value c)
error d)
None
16)
Match the following:
Operators Category
1)
++ A)
binary
2)
+= B)
ternary
3)
?: C)
unary
a) 1- A, 2- B, 3- C b)
1- C, 2- A, 3- B c) 1-
C, 2- B, 3- A d) a. 1-
B, 2- A, 3- C
*************************
Key
for One mark
1 d 2 a 3 b 4 b 5 c
6 b 7 b 8 c 9 b 10 a
11 b 12 a 13 b 14 a 15 b
16 c 17 a 18 b 19 c 20 a
21 b 22 c 23 b 24 b 25 b
26 a 27 b 28 c 29 b 30 a
31 c 32 b 33 b 34 a 35 b
36 a 37 a 38 b 39 b 40 b
41 a 42 b 43 c 44 b 45 a
46 b 47 b 48 b 49 c 50 a
51 b 52 c 53 b 54 a 55 a
56 a 57 b 58 c 59 b 60 b
Key for two marks questions
1 b 2 c 3 a 4 C 5 a
6 b 7 a 8 b 9 a 10 c
11 a 12 d 13 b 14 a 15 a
Key for four marks questions
1 c 2 a 3 b 4 a 5 b
6 a 7 b 8 a 9 d 10 a
11 b 12 b 13 a 14 c 15 c
16 b
UNIT II- Operator Overloading and Inheritance
One mark questions:
1)
________ are those that have been
redefined within a C++ class.
a) Method
Overloading b) Operator
Overloading c) Both a & b d) None
2)
The internal call to an object ss++
will be made as _______
a) ss. operator++(
) b) ss.
operator++(0) c) ss.
operator++(1) d)
None
3)
_______ is a special pointer that
points to the current object.
a) This b) new c) Both d) None
4)
To prevent the member wise copy, it is
necessary to provide the ______.
a) Copy Constructor b) Constructor c) Operator Constructor d) None
5)
______ provides explicit conversion
between datatypes.
a) Conversion b) Casting c) Both d) None
6)
Operator int( ) is said to be
___________.
a) Conversion
Function b) Casting Function c) Both d) None
7)
To convert from basic to Object we use
______ in the class.
a) Conversion Function b) Constructor c)
Both d)
None
8)
To convert from Object to basic we use
______ in the class.
a) Conversion
Function b) Constructor c) Both d) None
9)
Functions with same name but differing
in their signatures is said to be ____.
a) Operator
Overloading b) Function Overloading c) Both d)
None
10)
The process of creating new classes
from already existing classes is said to be ____.
a) Inheritance b)
Polymorphism c)
Exceptions d) None
11)
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
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
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=”<
string&
operator=(string &s)
{
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=”<
string&
operator=(string &s)
{
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
stack::push(var);
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”<
cout<<”\n”<
cout<<”\n”<
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;}
};
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;}
};
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;}
};
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 ”
before the class
ii) Use the statement
“template ” before the
main( )
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 c.
stack d.
None
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”<
outfile<<”C++
is said to superset of C”<
}
ii)
void main( )
{
ifstream
outf(“out.txt”);
outf<<”
Creating an ASCII test file<
outf<<”
C++ is superset of C”<
}
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 o:p="o:p">3>
{
cout<<” Enter atleast two integers”; exit(0);
}
else
{
for(I=1;I
cout<<”
sum of the numbers is :”<
}
}
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 o:p="o:p" range="range" throw="throw">0>
return
st[top--];
}
};
void main()
{ tack ss1;
try
{ s1.push(11);
s1.push(12);
s1.push(24);
cout<
cout<
cout<
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