0% found this document useful (0 votes)
24 views

C++ QB

Uploaded by

hasnayashik7
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

C++ QB

Uploaded by

hasnayashik7
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 60

Question Bank of C++

LESSON-1, FUNDEMENTALS OF OBJECT-ORIENTED


PROGRAM.

1. What is ‘encapsulation’?
a. It is a collection of similar data items,
b. It is a combination of similar data items and the function
c. It is the combination of data items and function
d. It is the division of a program into independent module

2. Abstraction is?
a. A collection of similar data items
b. A combination of similar data items and the function
c. The combination of data items and function
d. A collection of necessary data items and function

3. Encapsulation is used?
a. To hide the information
b. for data abstraction
c. to define all necessary features of the real-world objects
d. all of the above

4. Which of the following property distinguishes one object from the


others?
a. Behavior
b. identity
c. state
d. Message

5. Object-oriented programming approach focuses on?


a. function
b. data
c. both
d. None of these
6. Procedure-oriented programming approach focuses on
a. Function
b. Data
c. Both
d. None of above

7. Which of the following language supports inheritance?


a. object-oriented Programming
b. procedure oriented programming
c. Object-based programming
d. structure oriented programming

8. Which of the following language supports data abstraction?


a. object-oriented programming
b. object-based programming
c. Both a and b
d. None of the above

9. UML stands for?


a. unified master language
b. unified modeling language
c. unique modeling language
d. unique modern language

10. Which of the following language supports top-down design concept?


a. object-oriented programming
b. object-based programming
c. procedure-oriented programming
d. None of the above

11. Encapsulation is an
a. abstraction of structure
b. abstraction of class
c. abstraction of privilege
d. abstraction of object
12. Class is a collection of
a. similar objects
b. similar function
c. dissimilar objects
d. dissimilar function

13. Which of the following have state and behavior?


a. Class
b. Objects
c. function
d. Base class

14. Which of the following supports the capability of one class to use
properties of another class?
a. Class
b. Inheritance
c. polymorphism
d. Encapsulation

15. Which of the following supports the capability of sending same


message to objects of several different classes?
a. Class
b. Inheritance
c. Polymorphism
d. Encapsulation

16. Which of the following language makes the software reuse possible?
a. object-oriented programming
b. object-based programming
c. procedure-oriented programming
d. Structure-oriented programming

17. Which of the following is true?


a. class is an object
b. object is a class
c. modular programming is a procedure-oriented programming
d. A base class can inherit the properties of a derived class
18. Which of the following is not true?
a. object represents data and its associated function under single unit
b. object have some identity and behavior
c. objects are the instances of a class
d. Class is an instance of an object

19. Which of the following features is used to implement data


abstraction?
a. object
b. encapsulation
c. inheritance
d. polymorphism

20. Which of the following is not true?


a. A class is a group of similar object that do not share common
properties and behavior.
b. Data abstraction specifies the essential features
c. Inheritance supports code reusability
d. Encapsulation is the way of implementing abstraction

21. Which of the following is true?


a. object represents data and its associated function under single unit
b. Polymorphism supports sending same message to objects of several
different classes
c. Encapsulation is the way of implementing abstraction
d. all the above

22. Which of the following is true?


a. object-based languages supports only class, objects, polymorphism and
inheritance
b. object-based languages supports only class, object and polymorphism
c. object-based languages supports only class, object, and inheritance.
d. Object-based languages
23. The polymorphism is a way?
a. for an entity to behave I several forms
b. for an entity to inherit some properties form the other class
c. for an entity to group an object as a data member
d. non of the above

24. Which of the following is true for inheritance?


a. we can eliminate the redundant code
b. we can drive features from different classes
c. we can reuse the existing code
d. All of the above

25. Which of the following are the main features of OOP?


a. overloading, inheritance and polymorphism
b. Encapsulation, inheritance and polymorphism
c. inheritance, templates and exception handling
d. Inheritance, templates and polymorphism

26. Which of the following property hides the details of implementation


from the user?
a. Data abstraction
b. Encapsulation
c. Information hiding
d. all the above

27. A class?
a. Is a user-defined data type
b. is a metadata
c. is a technique to implement encapsulation
d. All the above

28. Which of the following is correct?


a. object is an instance of a class
b. object is a real time entity
c. object is a variable of class name type
d. all the above.
29. The child class is called?
a. derived class
b. base class
c. ancestor class
d. super class

30. The object name is also called as its


a. identity
b. state
c. behavior
d. all the above

31. An object has


a. state, behavior and identity
b. state, message, behavior
c. behavior, identity, and message
d. none of the above

32. Encapsulation allows


a. data abstraction
b. data hiding
c. inheritance
d. all the above

33. Which of the following notation is used to draw the object diagram?
a. circle
b. triangle
c. Square box
d. Rectangle box

34. Where would you place the class name on the diagram/
a. outside the diagram
b. Top
c. Bottom
d. Middle
35. The first parent class is also called as
a. ancestor class
b. base class
c. super class
d. all the above

36. An object is an instance of


a. class
b. state
c. behavior
d. message

Review Question.

1. What is the procedure-oriented programming? What are its


disadvantages?
2. What are the characteristics of object-oriented programming languages?
3. What is the difference between the object-based and object-oriented
programming languages?
4. What is message passing?
5. write the merits and determines of object-oriented language as
compared to procedure-oriented language
6. What is the purpose of class diagram? Describe icons used for class
relationships?
7. How can we use objects as software modules?
8. What is the difference between active ans passive object?
9. Explain the following by giving suitable examples?
a. Association
b. Aggregation
10.In what way inheritance is useful in OOP’s
11.What is meant by object-programming?
12.What are the core OOP’s concepts?
13.What is an interface?
14.What are objects? How are they created?
15.What do you mean by “Is-A”, and “A-part-Of” relationship?
16.What is aggregation? Explain its properties and various types?
17.Compare global automatic and static objects?
18.Can an object of one class interact with an object of another class? Give
a suitable example to explain?
19.What are the different forms of association between objects?
20.Write the difference between inherited method and redefined method?
21.Define the following terms

a. Encapsulation
b. Data abstraction
c. Inheritance
d. Polymorphism
e. Class and Objects
f. Multiple inheritance

LESSON-2, BASICS OF C++.

1. The go to statement transfers the control to


a. A label
b. A variable
c. A function
d. An operator

2. An int data type requires


a. 2 bytes
b. 4 bytes
c. 1 bytes
d. 8 bytes

3. int a=10/3; will give answer?


a. 3
b. 3.33
c. 3.0
d. Error.

4. float a=10/3;will give answer


a. 3
b. 3.33
c. 3.0
d. Error
5. float a=(float)10/3; will give answer
a. 3
b. 3.33
c. 3.0
d. Error

6. iostream.h is a
a. Header file
b. Preprocessor directives
c. User-defined function
d. Both (a) and (b)

7. cout in C++ is a
a. Object
b. Class
c. Function
d. Command

8. In the statement if(2) {cout<<”hello”;} else {cout<<”hi”;}


a. There is an error
b. It will display message hello
c. It will display message hi
d. Infinite loop

9. << is called
a. insertion operator
b. Extraction operator
c. Object
d. Function

10.>> is called
a. insertion operator
b. Extraction operator
c. Object
d. Function
11.In the statement if (1/2) {cout<<”hello”;} else {cout<<”hi”;}
a. There is an error
b. It will display message hello
c. It will display message hi
d. Infinite loop

12.cin object in C++ corresponds to the


a. standard input stream
b. standard output stream
c. Iterative statement
d. Function

13.The for loop is best if we know


a. Fixed number of iteration
b. Test condition
c. Value for calculation
d. Number of conditions are fixed

14.In while loop the condition is evaluated


a. First then body is executed
b. After the execution of the body
c. In between the body of loop
d. After update statement is executed

15.In do-while loop the condition is evaluated


a. First then body execute
b. After update statement is
c. In between the body of loop
d. After the execution of body

16.In switch statement the expression


a. Can be of any type
b. Can be of an integer or character type
c. Cannot be of floating type
d. Both (b) and (c)
17.To display output ; what is used in c++
a. cout
b. cin
c. header file
d. class

18.The for ( int i=0;I < 5: i++); cout<<i<<” “; will give the output
a. An error
b. 0 1 2 3 4
c. 5
d. Infinite loop

19.The for (int i=0, int j = 0; i<5: i++) cout <<i<<” “<<j; will give the
output
a. an error
b. 0 0 1 0 2 0 3 0 4 0
c. 5
d. Infinite loop

20.c++ was originally developed by


a. Donald Knuth
b. Bjarne Stroustrup
c. Ken Thompson
d. Deniss Richie

21.The preprocessor directive #include is required if


a. console output is used
b. console input is used
c. Both console input and output is used
d. None of the above

22.The standard C++ comment is


a. /
b. //
c. /* and */
d. None of these
23.The statement that tests to see if sum is equal to 1000 and average is
less than 40, and if so, prints the text string “Correct answer” is
a. if ( (sum = 100) && (avg < 40 ) )
cout<<”correct answer”;
b. if ( (sum == 100) && (avg < 40) ) cout<< “correct answer”;
c. if ( ( sum == 100) : : (avg <40) ) cout<<”Correct answer”;
d. None of these option

Review Question

1. What is ternary operator?


2. What is type casting?
3. How is == different from =?
4. Discuss the function of sizeof () and coma operator?
5. How will you decide which loop is to be used when?
6. How is Switch statement different from the if-else statement?
7. Explain the various kinds of looping statements in c++?
8. What is the difference between break and continue statements of c++?
9. What are the difference between while and do-while statement?
10.explain the different control statements in c++
11.Which of the following are not valid c++ identifiers? Give reasons:
a. const
b. abz267
c. john
d. simp-inter
e. Suresh’s
f. 2ndclass
g. Float
h. pice

LESSON-3, FUNCTIONS.

1. function prototype is also called


a. Function declaration
b. Function definition
c. Function call
d. Return type
2. Memory is allocated during
a. function declaration
b. function definition
c. function call
d. Return type

3. inline function should be used for


a. small set of code
b. large set of code
c. friend function
d. for main () function

4. Static variable should be defined


a. inside the function
b. outside the function
c. in the function call
d. Anywhere

5. Function prototype is not required when


a. function is defined before the main
b. function is defined after the main () function
c. function is the defined in the main () function
d. it is not needed at all

6. Parameters associated with function call are called


a. Actual parameter
b. Formal parameter
c. Global parameter
d. Auto parameter

7. Parameters defined within the function are called


a. extern parameter
b. formal parameter
c. auto parameter
d. register parameter
8. if void is not written before main () then the main () function will
return
a. int
b. float
c. void
d. long

9. which storage specifier retains the value between the function call
a. auto
b. register
c. extern
d. static

10.which storage specifier initializes the value zero to the variable


a. auto
b. register
c. extern
d. static

11.which method of parameter passing does not change the original


variable
a. call by value
b. call by reference
c. call by pointers
d. both (b) and (c)

12.if function does not return any value then its return type is
a. int
b. float
c. void
d. char

13.Maximum number of values that can be returned by any function is


a. 1
b. 2
c. 0
d. 4
14.Lifetime of extern variable is
a. function
b. file
c. block
d. none

15.For char A; which one is correct?


a. A = “A”;
b. A = “X”;
c. A = ‘A’;
d. A = X;

16.What is the purpose of the cin object?


a. To represent an input stream
b. To represent an output stream
c. To represent the process of input
d. To act as a receptacle to put values in

Review Questions

1. Explain the significance of array? What are the different types of


arrays?
2. What are the rules to declare an array?
3. How is character array different from other type of arrays?
4. Can a multidimensional array be passed as an argument to a function?
5. Can a group of strings be stored in a two dimensional array?
6. What is the purpose of subscript in array?
7. How the multi-dimensional array is different from single-dimensional
array?
8. Distinguish between the character array and integer array?
9. What is the importance of NULL character in a string?
10.What is two-dimensional character array? How are they initialized?
LESSON-4, ARRAYS.

1. Arrays is a collection of
a. integer data item
b. similar data items
c. dissimilar data items
d. built-in data type

2. Array is a
a. derived data type
b. built-in data type
c. enumerated data type
d. user-defined data type

3. Array elements are accessed by using


a. subscript
b. dot operator
c. arrow operator
d. elements name

4. Array elements are stored in


a. contiguous memory
b. randomly
c. integer array
d. structure

5. The NULL character is represented by


a. \0 (zero)
b. /0 (zero)
c. \0 (0 alphabet)
d. 0 (zero)

6. Which of the array declaration is valid/


int a[3];
int [3];
a[3] of int
int a[0-3];
7. The array is passed as a parameter to a function using
always call by value
always call be reference
it may be call by value or call by reference
none of the above

8. ASCII value for NULL character is


a. 0 (zero)
b. 48
c. 97
d. 68

9. To read a string consist of spaces, we use


a. cin>>
b. gets()
c. cout<<
d. puts ()

10.Which header file is required to use exit ()


a. studio.h
b. ctype.h
c. iostream.h
d. process.h

11.Which header file is required to use gets?


a. studio.h
b. string.h
c. iostream.h
d. procees.h

12.In int A[5] = {1, 4, 6}, what is value of A[3]?


a. 0
b. Garbage
c. 6
d. 4
13.In int A[3] = {1, 4, 6}, what is value of A[3]?
a. 0
b. Garbage
c. 6
d. 4

14.Which of the following is not correct?


a. char A[] = “Umang”;
b. char A[6] = “Umang”;
c. char A[6] = { ‘U’, ‘m’, ‘a’, ‘n’, ‘g’, ‘\0’};
d. char A[6] = ‘Umang’;

15.For char A; which one is correct?


a. A = “A’;
b. A = “X”;
c. A = ‘A’;
d. A = X;

16.What is the purpose pf the cin object?


a. To represent an input stream
b. To represent an output stream
c. To represent the process of input
d. To act as a receptacle to put values in

REVIEW QUESTIONS

1. Explain the significance of array? What are the different types


of arrays?
2. What are the rules to declare an array?
3. How is character array different from other type of array?
4. Can a multidimensional array be passed as an argument to a
function?
5. Can a group of strings be stored in a two-dimensional array?
6. What is the purpose of subscript in array?
7. How the multi-dimensional array is different from single-
dimensional array?
8. Distinguish between the character array and integer array?
9. What is the importance of NULL character in a string?
10.What is two-dimensional character array? How are they
initialize?
5. STRUCTURE, UNION AND BIT FIELDS

1. For the following code how much memory is reserved?


Union example
{
Float a;
Char b;
} X;
a. 2 bytes
b. 4 bytes
c. 1 byte
d. 8bytes

2. struct is
a. an identifier
b. constant
c. keyword
d. user-defined variable

3. Structure members are accessed by using


a. dot operator
b. index
c. subscript
d. directly we can access

4. Structure is a collection of
a. similar data items
b. dissimilar data items
c. it may be similar or dissimilar data items
d. special characters

5. For the following code, how much memory is allocated?


Struct example
{
Int a;
Float b;
Char c;
};
a. 4 bytes
b. 7 bytes
c. No allocation bytes
d. 8 bytes

6. A = B is valid if
a. A and B are variables of the same structure type
b. A and B are variables of the different structure type
c. Both (a) and (b) are true
d. Error

7. Structure tag is a
a. an identifier
b. structure variable
c. structure name
d. keyword

8. for the following code, how much memory is allocated


Struct example
{
Int a;
Float b;
Char c;
} X;
a. 4 bytes
b. 7 bytes
c. No allocation
d. 8 bytes

9. while accessing the structure members, left side of dot operator must
be
a. Structure variable
b. Structure pointer
c. Keyword struct
d. Index value
10.What will be output of the following?
struct sample
{
Unsigned int rollno: 12;
Char name {2}: 16;
Unsigned int age : 12;
} X;
Cout<<X.rollno. <<X.
Name<<X.age;
a. Bit field must have integral type
b. 12 16 12
c. Bit field is too large
d. Nothing

11.What will be the output of the following?


Struct sample
{
Unsigned int rollno: 12;
Char name: 10;
Unsigned int age: 12;
} X;
If
X.rollno=102;
X.name = ‘A’; X.age = 24;
Cout<<X.rollno<<X.
Name<<X.age;
e. Bit field must have integral type
f. 12 16 12
g. Bit field is too large
h. 102 A 24
11.What will be output of the following?
Struct
{
Int rollno;
Char name [10];
Int age;
} x;
If X.rollno = 102; x.name = “Amar”; X.age = 24;
Cout<<X.rollno<<X.
Name<<X.age;
a. Error since structure tag is missing
b. Incorrect variable declaration
c. 102 Amar 24
d. Both (a) and (b)

12.Find the error if any


Struct
{
Int rollno;
Char name [10];
Int age;
} X,Y,Y;

e. Error since structure tag is missing


f. Cannot declare more than one variable in this fashion
g. Correct declaration
h. Cannot use array within structure

Review Question

1. How is an array different from a structure?


2. Can you assign a structure variable to another? If yes, when/
3. How the structure is initialized?
4. Can we pass a structure variable to a function? What are the ways
to pass structure variable to a function?
5. Can an array be a member of a structure?
6. Declare a structure for an employee payroll slip containing
a. Eno
b. Ename
c. Basic pay
d. HRA
e. DA
f. Gross
g. Income tax
h. Professional tax

7. What are the difference between a structure and a union?


8. Explain bit fields?
9. What do you understand by nested structure? Give an example?

LESSON-6, POINTERS.

1. int A [4] = {1,2,3,4} ; Suppose the base address is 1000 then


cout<<(A+1) will display
a. 2
b. 1
c. 1000
d. 1002

2. Char A [] = “Umang” suppose the base address is 1000 then


cout<< (A+1) will display
a. 1002
b. 1001
c. Umang
d. Mang

3. Char A [] = “Umang”. Suppose the base address is 1000 then


cout<<*(A+1) will display
a. m
b. um
c. garbage value
d. none of these
4. Char A [] = “Anand”. Suppose the base address is 1000 then
cout<<*A+1 will display
a. n
b. An
c. 66
d. Garbage value

5. Char A [] = “Anand’; char *ptr then which statement is not


correct
a. A++
b. Ptr++
c. *ptr
d. Ptr = A

6. struct complex { int real ; float imag ; } X ; complex *ptr =


&X ; then which statement is correct
a. ptr->real;
b. ptr.real;
c. X->imag;
d. All the above

7. Char * const ptr = “Umang” then which statement is correct


a. ptr = “Anand”;
b. *ptr = ‘A’;
c. *ptr = “Anand”;
d. Ptr = ‘A’;

8. int A[2] [4] ; then A[1] [2] is equivalent to


a. *(A=1)+2;
b. *(*(A+1)+2)
c. *(A[1]+2)
d. Both b and c

9. int a[2] [4] [3] ; then A[0] [0] [0] is equivalent to


a. *(*(*(A+0)+0)+0);
b. *(*(A[0]+0)+0)
c. *(A[0] [0]+0)
d. All the above
10. If int A [4]; then A [2] is equivalent to
a. *A+2;
b. *A[2]
c. & (A+2)
d. 2 [A]

11. Char A [ ] = “Anand”; then thee statement cout<<sizeof


(A); will display
a. 2
b. 6
c. 5
d. Error

12. Char X = ‘X’; char Y [] = “Y” then cout<<sizeof (X)


<<”Y” then cout<<sizeof (X) <<” “<<sizeof (Y); will display
a. 2 1
b. 1 1
c. 1 2
d. 0 0

13. If float A [] = {1.2, 2.3, 3.5, 4.1, 5.6} then cout<<sizeof


(A); will display
a. 20
b. 10
c. 5
d. 0

14. f int A[2] [3] = {1,2,3,4,8,6} ; then cout<<* (A+1)+1 will


display
a. address of 8
b. 5
c. 8
d. address of 4

15. Which operator is used to access the structure member


through pointer to structure?
a. arrow operator
b. dot operator
c. scope resolution operator
d. ternary operator
16. Reference is a
a. synonym for “pointer”
b. Value at address
c. Another name for a class
d. All the above
17. Reference parameter is a
a. reference which is used as an argument to a function call
b. parameter which is passed to a reference
c. parameter which is used to initialize a reference
d. all the above

18. When the parameters are passed by call by reference


a. Changes are reflected only in the formal parameter
b. changes are reflected in to the actual parameters
c. changes are made to the local variables only
d. None of above

19. Which of the following is a valid declaration for pointer to


function in C++?
a. (float 8) example ();
b. float (*) example ();
c. float * example ();
d. All the above

20. Which of the following is a valid function declaration which


returns a pointer?
a. (double) (example*(double, double));
b. double (*) example (double, double);
c. double (example (*double, *double);
d. double *example (double, double);

21. Which of the following is a valid function pointer call in C+


+?
a. void (*example) (1,2);
b. f = (*example) (1,2);
c. example(1,2);
d. example->(1,2);
22.Which of the following operator is used for dynamically allocating the
memory?
a. new
b. malloc
c. calloc
d. All the above

23. Which of the following operator is used for dynamically de-allocating


the memory?
e. delete
f. destructor
g. destroy
h. void

24.Which of the following pointer is called a zero pointer?


a. void
b. Null
c. Function pointer
d. None of these

Review Questions

1. What is a pointer?
2. What is the relationship between array and a pointer?
3. What is the difference between & and * operator?
4. What are the operations possible with pointer variables?
5. How is an array and a pointer related?
6. What do understand by pointer to pointer?
7. Explain pointer to function?
8. What are the differences between array of pointers and pointer
to the array?
9. What are the differences between array of pointers and pointer
to pointer?
10.What are the difference between malloc () and new operators?
11.What are the differences between free () and delete?
LESSON-7, CLASSES AND OBJECTS.

1. Which function can access the private members of a class?


a. Private member function
b. Friend function
c. Public member function
d. All the above

2. Private access mode implements


e. data hiding
f. encapsulation
g. data abstraction
h. polymorphism

3. Class is a
a. built-in data type
b. user-defined data type
c. derived data type
d. enumerated data type

4. Class is
a. collection of similar elements
b. collection of dissimilar elements
c. combination of data members and member functions
d. none of the above

5. By default all the members of a class are


a. Private
b. Public
c. Protected
d. All the above

6. All the member functions defined inside the class are


a. Public member functions
b. Infinite functions
c. Friend functions
d. Virtual functions
7. Friend function can be defined in
a. Private access mode
b. Public access mode
c. Protected access mode
d. Any of the above

8. Which of the following cannot be accessed by the outside


world?
a. private member of a class
b. public member of a class
c. protected members of a class
d. both (a) and (b)

9. Which one of the following is access specifier?


a. auto
b. friend
c. inline
d. public

10. The binding of data members and the member functions In a


class is called?
a. encapsulation
b. polymorphism
c. object
d. data hiding

11. Which holds the address of an object?


a. class
b. friend function
c. this pointer
d. private access specifiers

12.Who can access the private members of a class?


a. member function of the class
b. friend function of the class
c. both (a) and (b)
d. none of the above
13.Which operator is used to access the members of a class object?
a. arrow operator
b. dot operator
c. bitwise operator
d. all the above

14.The member function cannot alter the data members if it is


declared as
a. friend function
b. inline function
c. const function
d. virtual function

15.Which operator is used to define the outline member function?


a. dot operator
b. scope resolution operator
c. arrow operator
d. bitwise operator

16.Forward declaration is used when


a. a function is a friend of one class
b. a function is a friend of two classes
c. a class is a friend of another class
d. a member function of one class is a friend of another class

17.if a class A is a friend of another class B then


a. All member function of class A can use the private members of
class b
b. All member function of class B can use the private members of
class A
c. Only public member functions of class A can use the private
members of class B
d. Only public member functions of class B can use the private
members of class A

18. A class is called a container class if


a. it contains all the member function in public mode
b. it contains the object of another class as data members
c. it contains another class inside
d. it contains both the friend and the inline functions
19. A Class is called a nested class if
a. it contains all the member function in public mode
b. it contains the objects of another class as data members
c. it contains another class inside
d. it contains
20.The method in which address of an object is passed to as an
argument is called?
a. call by value
b. call by reference
c. call by text
d. none of the above

21.Private data or functions are accessible to


a. to friend function
b. to member function of the same class
c. to any function
d. both (a) and (b)

22.The only different between a class and structure is


a. members are private in class and public in structure by default
b. class can consists of data and member function and structure
consists data only
c. we can specify different access mode in class in structure it is
not possible
d. all the above

23.The class without a tag name is called


a. nested class
b. container
c. anonymous class
d. friend class

24.Can two classes contain member functions with the samr name?
a. no
b. yes, but if both the class have the same name
c. if it a friend function
d. Yes, this is always allowed
25.A class is a
a. data type
b. user-defined type
c. abstract type
d. all the above

REVIEW QUESTIONS

1. How are data hiding, abstraction and encapsulation


implemented in C++?
2. What are the differences between a class and an object?
3. Can a class contain another class?
4. What is a container class?
5. What are the differences between structure and a class?
6. What is the significance of this pointer?
7. What are the different access specifiers in a class?
8. What is a friend function?
9. How is a friend function different from a member function?
10.How is memory allocated to a class and its object?
11.What are the different ways to define the member function of a
class?
12.State the different characteristics of am object-oriented
programming. How are these properties implemented in C++?

LESSON-8, CONSTRUCTORS AND DISTRUCTORS.

1. A constructor is called automatically when an object is?


a. Created
b. Initialized
c. Destroyed
d. A member of another class

2. If three objects Z,X and Y are created from the same class then
the sequence of constructor calling for the objects?
a. Z X Y
b. X Y Z
c. Y Z X
d. In any order
3. If three objects Z, X and Y are from the same calss then the
sequences of destructor invocation is
a. Z X Y
b. X Y Z
c. Y X Z
d. In any order

4. constructor is
a. A function which is automatically called when object is created
b. It is called explicitly when object is created
c. A function which destroys the objects
d. A special operator like new or delete

5. Constructor can return


a. void data
b. Any data of user-defined types
c. Any data of built-in types
d. No value (not even void)

6. Which of the following is true


a. A class can have many destructors
b. A class can have many constructors
c. A constructor is called using new operator
d. Destructors cannot be virtual

7. The constructor which does not take any parameter is called?


a. parameterized constructor
b. Default constructor
c. Default argument constructor
d. Dynamic constructor

8. When no constructor is defined in the class then the compiler


supplies?
a. Default argument constructor
b. Default constructor
c. Dynamic constructor
d. No constructor
9. We cannot pass the parameters to
a. Default argument constructor
b. Parameterized constructor
c. Dynamic constructor
d. Destructor
10.Constructor generally declared in
a. Public mode
b. Private mode
c. Protected mode
d. None of the above

11.Constructor is useful because


a. It allocates memory dynamically
b. It initializes the object
c. It allocates the memory to the member function
d. It supports data hiding

12. Destructor is
a. A function which is automatically called when object is created
b. It is called explicitly when object is created
c. A function which destroys the object
d. A special operator like new or delete

13.Destructor is useful because


a. It de-allocates memory dynamically
b. It release the memory occupied by an object
c. It improves the speed of a program by reducing the number of
statements in the source
d. It supports data hiding

14.Constructor can be declared


a. Public mode
b. Private mode
c. Protected mode
d. All the above
15.Which of the following is true
a. A class can have many constructors, but at most one destructor
b. The destructor never takes arguments
c. Destructors are always called at the end of a block, whereas
constructors can be called anywhere in the code
d. all the above

STATE WHETHER TRUE OR FALSE

1. Constructors can be overloaded


2. Constructor is a member function of a class
3. Constructor can be defined in private mode
4. Destructor is called automatically
5. A constructors name is same as class name
6. Constructor can be virtual
7. Destructor may be virtual

REVIEW QUESTION

1. What is constructor? How do we invoke a constructor function?


2. What are the rules for declaration of the constructor function?
3. What is parameterized constructor? How it is different from the
default argument constructor?
4. What is the importance of a destructor?
5. Can a constructor be overloaded?
6. Explain how the data members of a class can be initialized in C++?
7. What are the different situations when a copy constructor is
automatically invoked?
8. Explain the pros and cons of copy constructors?
9. Explain the pros and cons of default constructor?
10. When is a destructor member function invoked in a class?
11. What is the difference between default constructors?
12. What should be the sequences of default value assignment for the
default argument constructor?
13. Can we have a more than one constructors in a class? If yes,
explain the need for such a situation.
14. What is the difference between destructor and a delete operator?
LESSON-9, INHERITANCE.

1. Which class is not used to create the object?


a. Virtual base class
b. container class
c. abstract class
d. nested class

2. The private members of the base class can be inherited in?


a. Private mode
b. Protected mode
c. public mode
d. cannot be inherited

3. Virtual base class is generally used in


a. Hierarchical inheritance
b. Multiple inheritances
c. Multilevel inheritance
d. hybrid inheritance

4. In public inheritance, the public member of the base class becomes?


a. Public
b. Private
c. Protected
d. none of the above

5. In private inheritance the public member of the base class becomes?


a. public
b. private
c. protected
d. none of the above
6. In protected inheritance the protected member of the base class
becomes?
a. public
b. private
c. protected
d. none of the above

7. In private inheritance the private member of the base class becomes?


a. public
b. private
c. protected
d. cannot be inherited

8. When the object of derived class is created then the order of


constructor execution is?
a. base to derived
b. derived to base
c. intermediate to base
d. bottom to top

9. A class that contain object of another class is called/


a. Container class
b. Virtual base class
c. Abstract class
d. Nested class

10.A class that contains a class within another class is calle?


a. Container class
b. Virtual base class
c. Abstract class
d. Nested class

11.Private members cannot be accessed directly by the derived class


because
a. They are not inherited
b. they are not friend of the derived class
c. they are accessible directly to the derived class
d. they are even not accessible to the base class
12.Inheritance is?
a. A relationship in which a class includes one or more objects of another
class
b. A relationship in which a class includes one or more objects of another
class
c. A relationship In which a class is defined in terms of another class
d. None of the above

13.If a base class and a derived class contain the member function with
the same name then the function that will be called by the object of
the derived class is
a. Base class
b. Derived class
c. Depend on the virtual base class

14.Deriving a class from multiple base classes is called


a. Multilevel inheritance
b. Multiple inheritances
c. Hybrid inheritance
d. None of the above

15.Deriving multiple classes from single base class is called


a. Multilevel inheritance
b. Multiple inheritances
c. Hybrid inheritance
d. None of the above

16.Deriving multiple classes from single base class and then deriving a
class from these multiple base classes is called?
a. Multilevel inheritance
b. Multiple inheritances
c. Hybrid inheritance
d. None of the above

17.In the derived class member functions can access the following base
class members in inheritance
a. Public and protected only
b. Private and protected only
c. Private and public only
d. Private, public and protected
18.An object of the derived class can access the following base class
members in inheritance?
a. Public and protected only
b. Public only
c. Protected only
None

19.Depending on the visibility mode which is the correct syntax if we


wish to derive B from A in private mode
a. Class B: A {};
b. Private class B: private A {};
c. Private class B: Class A {};
d. class A: Private class B {};

20.Which is the correct syntax if we wish to derive B from A and C in


private and public mode, respectively
a. class B: Private A,C {};
b. Class B, class C: private B;
c. class B:A, public C{};
d. private class A, public class C: private class B{};

21.if class B, class C:A{}; is written in C++ then the type of inheritance
is
a. Multiple inheritance
b. Hierarchical inheritance
c. Multilevel inheritance
d. none of the above

22.Inheritance is used to
a. Avoid rewriting of the code
b. Data abstraction
c. To change the visibility modes
d. To use virtual base class

23.The ambiguity in the single-level inheritance is removed by using


a. colon operator
b. Scope resolution operator
c. virtual base class
d. Container class
24.Which of the following statements is true?
a. A base class can access the derived class members
b. a derived class can access the private members of the base class
c. A base class can access the public and protected members of the
derived class
d. A derived class can access the public and protected members of the
base class

25.In C++, we can inherit


a. Data members and member functions only
b. Data members, member functions friend function only
c. Date members only
d. Member function only

26.The relationship between the base class and the derived class is called
a. “Is-A” relationship
b. “Kind-Of” relationship
c. “Part-Of” relationship
d. Both (a) and (b)

27.If class B: class A, class C {}; is written in C++ then the type of
inheritance is
a. Multiple inheritance
b. Hierarchical inheritance
c. Multilevel inheritance
d. None of the above

28.If class B: class A, class C {}; is written in C++ then the visibility
mode in multiple inheritance is
a. Private
b. Public
c. Protected
d. All

29.Inheritance is very useful because it provides


a. Reusability
b. Extension
c. It minimizes the amount of code which has to be written
d. All the above
30.Reusability can be achieved through
a. class
b. Inheritance
c. Polymorphism
d. Encapsulation

31.A base class is a


a. Specialized class
b. A virtual base class
c. An abstract class
d. All the above

32.Which is the following represents relation ship?


a. Polymorphism
b. Function overloading
c. Inheritance
d. None of the above

REVIEW QUESTIONS

1. What is reusability?
2. Explain the virtual base class?
3. In what order are the constructors called when a derived class object is
created?
4. What is the difference between a container class and nested class/
5. What is the difference between the private mode inheritance and the
protected mode inheritance?
6. How do we make a class virtual?
7. When do we make a class virtual?
8. Describe the hybrid inheritance?
9. How is the ambiguity removed in single-level inheritance?
10.What are the visibility modes?
11.Explain how a protected member of a base class can be accessed by
the public member function of the derived class?
12.What are the advantages of inheritance?
13.How does the containership differ from inheritance?
14.How does the visibility mode control the access of members in the
derived class?
15.What is the significance of virtual base class?
16.Explain the different forms of inheritance with the help of suitable
example?
17.What are public inheritance, private inheritance and protected
inheritance?

LESSON-10, POLYMORPHISM.

1. Operator overloading is done by using?


a. public member function
b. private member function
c. friend function
d. both (a) and (b)

2. How many operators overloading can be defined for the same operator
in as single class?
a. 1
b. 2
c. 3
d. No limit

3. The unique name of the function is called?


a. function call
b. Function prototype
c. Function definition
d. Signature

4. Which of the following cannot be virtual?


a. Constructor
b. Destructor
c. Pure virtual function
d. Both (a) and (b)

5. An overloaded function call can be ambiguous when


a. There are more than one functions with the same name
b. There are more than one functions with the same signatures
c. There are more than one functions with the same return type
d. All the above
6. A pointer to base class can hold the address of
a. Base class only
b. Derived class only
c. Both
d. It cannot hold the address

7. Virtual keyboard in the virtual function definition appears


a. Before return type
b. After return type
c. Can appear anywhere
d. Not necessary to use

8. “Function overloading” can be defined as


a. A single function which has more than one definition in a program
b. Two or more functions which have the same name and argument
types
c. Two or more functions which have the same name but different
argument types
d. Two or more function which have same names but different return
types

9. Operator overloading is
a. A Class
b. A concept by which we can give special meaning to an operator of
language
c. An object of a language
d. A concept by which we can design new object

10.for overloading +operator using member function which of the


following declaration is correct
a. Sum (complex & );
b. Sum (complex &, complex& );
c. Sum (complex, Complex );
d. It cannot be overloaded at all

11.A pure virtual function is a virtual function that


a. has no body
b. defines a abstract class
c. Implements late binding
d. All the above
12.When an operator is overloaded then we cannot change its
a. Template
b. Precedence
c. Syntax rules
d. All the above

13.How many parameters are required when unary operator is overloaded


using friend function parameter
a. 2
b. 1
c. 3
d. 0

14.Which of the following can be overloaded


a. sizeof
b. ?:
c. .*
d. []

15.The conversion from basic to class type can be done by


a. constructor
b. not possible
c. object of derived class
d. overloaded casting operator

16.Object cannot be created of


a. base class
b. derived class
c. class containing friend function
d. class containing pure virtual function

17.“Function overloading” is useful because


a. We can give some name to the related function
b. We can define functions with same name but different return types
c. We can reduce the total number of functions
d. All the above
18.void operator ++ (int) is used to overload
a. Pre-increment ++
b. Post-increment ++
c. Both (a) and (b)
d. Error

19.How does the compiler decide which over loaded function to call?
a. It calls all the function having same name
b. It calls the function with the closest signature
c. It calls only those function with the return type void
d. It calls the first function it finish with the same name

20.A friend function cannot be used to overload


a. + operator
b. <=operator
c. = assignment operator
d. / division operator

21.Operator overloading is used to


a. Change the template meaning of the operator
b. Define new operator
c. Make user-defined data type (class) to work like any built-in data
types
d. Use many function with the same name

22.A pure virtual function is a virtual function that


a. defines friend class
b. defines abstract class
c. defines virtual base class
d. all the above

23.Which of the following operator cannot be overloaded?


a. .
b. : :
c. ? :
d. All the above
24.To overload the binary operator a s friend function, how many
parameters are required?
a. Binary operators cannot be overloaded at all
b. 1
c. 2
d. 1 or 2

25.To overload the > operator as a friend function, how many parameters
are required?
a. Ternary operator cannot be overloaded at all
b. 1
c. 2
d. 1 or 2

26.Which operator cannot be overloaded?


a. >=
b. .*
c. New
d. Delete

27.Operator overloading is a form of polymorphism because?


a. It is just like the function overloading as virtual
b. The same operator may be used for the different type of object
c. We can define operator overloading as virtual
d. None of above

28.Pointer to base class can access the members (same name) of the
derived class only, if
a. Pointer holds the address of the derived class’s object and function in
the base class are defined as virtual
b. Pointer holds the address of the base class’s object and functions in
the base class are defined as virtual
c. Pointer holds the address of the derived class’s object and function in
the derived class are defined as virtual
d. Pointer hold the address of the base class’s object and functions in the
derived class are defined as virtual

REVIEW QUESTIONS
1. What is polymorphism? List the advantages and disadvantages of
using polymorphism on object-oriented programming?
2. What are static and dynamic binding?
3. How the operator overloading is done by using friend function?
Explain with example?
4. Explain how polymorphism is implemented using keyword virtual?
5. What is pure virtual function? What are the advantages and
disadvantages of defining and declaring a pure virtual function in
object-oriented programming?
6. What is the abstract base class and what are the advantages of using it
in a programming?
7. What is function overloading? What are the scope rules for governing
the function overloading?
8. Explain why a constructor member function cannot be a virtual
method?
9. Explain the various techniques of defining a pure virtual function?
10.How is function overloading done with default arguments? What is
the major limitation of default arguments?

LESSON-11, TEMPLATE AND EXCEPTION HANDLING.

1. Template is used for


a. Virtual base class
b. Friend class
c. Container class
d. Nested class

2. The generacity is defined as the method in which


a. a special property of a class is defined
b. the data structures and functions are defined without knowing the
details of the data types on which they operate
c. pure virtual function is used in the class
d. all the above

3. Which statement is true


a. Template class can be inherited
b. Member function can be a function template
c. Template class can be defined for user-defined data types
d. All the above
4. Template supports
a. generacity
b. polymorphism
c. inheritance
d. all the above

5. A template is
a. a collection of similar elements
b. a collection of dissimilar elements
c. a combination of data members and member function
d. none of the above

6. The generacity is defined as


a. abstraction of data members
b. abstraction of encapsulation
c. abstraction of structures
d. all the above

7. Which keyword is used to define a function template in C++


a. Template
b. Template function
c. Friend
d. Virtual

8. A template is useful because


a. the same logic need not be repeatedly written for different data types
b. it provides a way of defining the behavior of the class without actually
knowing the data types
c. it provides polymorphic behavior by using generacity
d. all the above

9. Which of the following is true


a. We can override a function template for a particular type
b. We can inherit a new class from the class template
c. A function template can have multiple argument types

d. all the above


10.Which of the following is true?
a. Class templates are normally used for a container class
b. A class template member function can be defined outside the class
template
c. Template argument can take default values
d. All the above

11.Exception handling in general is a way of dealing with


a. Exceptional errors
b. Syntax error
c. Semantic error
d. None of the above

12.The three key words used with exception handling are


a. try
b. catch
c. throw
d. None of the above

REVIEW QUESTIONS

1. What is a template?
2. What are the advantages and disadvantages of templates?
3. What is function template?
4. Do you agree with the statement that “a template increases the
efficiency of designing a program”?
If yes, explain?
5. How is the function template defined in a program in C++? What are
the rules that must be followed to define a function template?
6. What is a class template? What are the rules that must be followed to
define a class template?
7. What is the difference between an overloaded function and a function
template?
8. What is the difference between a class template and a template class?
9. What is generic programming and how is it implemented in C++?
10.How does the template support polymorphism?
11.What is an exception?
12.What may be the conditions when an exception occurs?
13.Explain try, catch throw?
14.Where are the keywords try, catch and throw used?
15.What are the advantages of using exception handling mechanism in a
program?
16. What happens if several handlers match the type of thrown object?
17.Explain how an exception handler is defined and invoked in a
program?
18.Can we restrict the exception type?

LESSON-12, FILE ORGANISATION.

1. In a binary file?
a. No character translation take place
b. Only new line character is translated
c. None of the above

2. fstream class is derived from


a. iostream
b. istream
c. ostream
d. iomanip

3. A file in C++ can be opened using


a. constructor of the appropriate class
b. open () function
c. appened () function
d. both (a) and (b)

4. Which mode is used to seek the end of file upon opening the file
a. ios: : in
b. ios: :out
c. ios: :ate
d. ios: :app

5. Which of the following is not a file mode?


a. ios: :ate
b. ios: :octal
c. ios: :binary
d. ios: :nocreate
6. Which of the following puts the pointer to end of the file?
a. ios: :ate
b. ios: :app
c. ios: :out
d. None of the above

7. Which of the following are used to read and write block of data?
a. read () and write ()
b. get () and put ()
c. getline () and cout
d. none of the above

8. Which of the following not an I/O error handler in C++?


a. bad()
b. eof()
c. good()
d. none of the above

9. >> (the extraction operator) belongs to


a. ostram class
b. istream class
c. conio.h
d. none of the above

10.cin is
a. an object of istream class
b. an object of ostream class
c. an operator, not an object
d. None of the above

11.Which class supports opening a file in write mode?


a. ofstream
b. ifstream
c. istream
d. ostream
12.fobj.seekg (0) will place the pointer to
a. the beginning of fobj
b. the end of fobj
c. depends on the offset
d. depends on the arguments

13.What is the meaning of seekg (-2, ios: :end)?


a. position the pointer second byte from the end
b. position the pointer second byte from the beginning
c. It cannot move in the negative direction.
d. None of the above.

14. Which operator is used to send the data to output file to output to an
output file?
a. >>
b. <<
c. ? :
d. None of the above

REVIEW QUESTIONS

1. What is a random file?


2. How can the block of data be written into a data file?
3. What is the difference between get () and getline () functions?
4. What is the difference between put () and write functions?
5. What is the difference between read () and get () functions?
6. Describe the purpose of seekg (), seekp (). Tellg () and tellp ()?
7. Describe the stream class hierarchy?
8. Difference between the text mode and the binary mode of file?
9. Name three member function of istream class?
10.What is a file mode? Describe the various file mode options
available?

LESSON-13, TURBO GRAPHICS.


1. To display text in the gothic font you would use?
a. drawtext ()
b. cputs ()
c. outtext ()
d. cout ()

2. To set thee font, direction, etc. you would use


a. drawtext ()
b. cputs ()
c. outtext ()
d. settextstyle ()

3. To draw a bar with outline you would use


a. draw text ()
b. cputs ()
c. bar ()
d. Bar3d ()

4. To display the text in vertical direction you would use


a. settextstyle ()
b. settextjustify ()
c. settextfont ()
d. settextlinestyle ()

5. Text mode functions are include in


a. iostream.h
b. conio.h
c. graphics.h
d. stdlib.h

6. To position the cursor within the text window you would use
a. gotoxy ()
b. setcursor ()
c. moveto ()
d. putch ()
7. Graphics mode functions are included in
a. iostream.h
b. conio.h
c. graphics.h
d. stdlib.h

8. Which of the following is used for identifying the graphics hardware?


a. graphresult ()
b. initgraph ()
c. graphdefault ()
d. getviewsettings ()

9. Which of the following is used for setting the window size for
graphics output?
a. setviewport ()
b. graphdefault ()
c. window ()
d. None of the above

10.Which of the following is used to get the current cursor position?


a. getx () and gety ()
b. getmaxx ()
c. getmaxy ()
d. None of the above

11.Which of the following is used to move the cursor to the relative


position of the current current position?
a. moveto ()
b. moverel (0
c. lineto ()
d. linerel (0

12.Which of the following constant specifies the RED color?


a. 1
b. 0
c. 2
d. 4
13.The color constant 0 specifies the following color?
a. BLACK
b. GREEN
c. WHITE
d. RED

14.Which of the following is used to get the current drawing color?


a. getcolor ()
b. set color ()
c. get maxcolor ()
d. setbkcolor ()

15.fillpoly () is used to
a. draw a polygon
b. draw and fill s polygon
c. draw an ellipse
d. draw an arc

16.Which of the following is used for sending a string to the output


device?
a. outtext ()
b. outtextxy ()
c. settextjustify ()
d. graphdefault ()

REVIEW QUESTION

1. Which header file is required to work with graphics programming in


C++?
2. What is the function of the library function window ()?
3. Which function is used to change the current cursor positing in text
mode?
4. Which function specifies the color of text within window?
5. How can you change the size of the characters in graphics?
6. How many arguments are specified to draw a 3D bar?
7. Which function returns the current background color code (int type)?
8. What is the function of settext style ()?
9. Which number specifies blink?
10.What is the purpose of initgraph ()?
11.How can you select the driver so that it selects the best mode for
graphics display?
12.How many arguments are specified to draw a polygon?
13.What number should be specified is setlinestyle () to draw solid line?
14.Which function sets the characteristics of letters such as font,
direction and size?

LESSON-14, PREPROCESSOR DIRECTIVES AND I/O.

1. To change the base of a number which of the following manipulator is


used?
a. setbase ()
b. setw ()
c. setprecision ()
d. all the above

2. Setw () manipulator is used?


a. to change the base of a number
b. to set the width of the field
c. to set the fraction part of the real number
d. none of the above

3. cin is
a. a command
b. an object
c. variable
d. none of the above

4. Which of the following is used to set character positions of the


fractional part of the real number?
a. setbase ()
b. setw (0
c. setprecision ()
d. all the above
5. cin is an object of
a. istream class
b. ostream class
c. iostream class
d. none of the above

6. Which of the following file in included to use getline (0?


a. iostream.h
b. studio.h
c. conio.h
d. None of the above

7. Which of the following function is used to read a single character?


a. getch ()
b. getchar ()
c. cin.get ()
d. all the above

8. Which of the following function is used to read character string?


a. gets ()
b. cin.getline ()
c. both (a) and (b)
d. none of the above

9. Which of the following cannot read a space character?


a. Cin >>
b. Cout <<
c. getchar ()
d. get ()

10.Which of the following file in include to use setbase ()?


a. iostream.h
b. iomanip.h
c. studio.h
d. process.h
11.Which of the following file is included while using strcpy ()
a. iostream.h
b. studio.h
c. string .h
d. ctype.h

12.strlen () function is used to find the length with the following


condition
a. It does not count NULL character in the length
b. It does count the NULL character in the length
c. Strlen () is not at all used fro finding the length
d. It counts only first ten characters

REVIEW QUESTIONS

1. What are the manipulators?


2. What is a stream?
3. What are the flags in ios?
4. Ca n you read a space character using cin?
5. Describe the iostream, ostream and istream?
6. Explain the setbase (), setpecision () and hex manipulators?
7. How can use the base of a numeric number be changed?
8. Why do we need to include iostream.h file in C++ program?
9. How is gets () function different from getline () function?
10.What is a header file? Explain its importance?

You might also like