Holiday Tumsar
Holiday Tumsar
Holiday Tumsar
(b) polymorphism
(d) abstraction
Question Bank
(c) field width
11. To fill unused section of the field, the character is set by the function
(a) fill ( )
(b) width ( )
(c) precision ( )
(d) none of the above
12. The manipulator endl is equivalent to
(a) '\n'
(c) , \b'
(b) '\t'
(d) none of the above
(c) 4
(d) none of the above
Page 2
Question Bank
(c) break
(d) else
23. The curly braces are not present; the scope of loop statement is
(a) one statement
(b) two statements
(c) four statements
(d) none of the above
24. In nested loop
(a) the inner most loop is completed first
(b) the outer most loop is completed first
(c) both (a) and (b)
(d) none of the above
25. The main() function returns an integer value to
(a) operating system
(b) compiler
(c) main() function
(d) none of the above
26. The concept of declaring same function name with multiple definitions is
(a) function overloading
(b) operating overloading
(c) both (a) and (b)
(d) none of the above
27. The default arguments are used when
(a) function is called with less arguments
(b) function is void
28. The use of parenthesis is optional with one of the following statement
(a) return
(b) main
(c) clrscr
(d) exit
29. Which of the following program will generate an error message:
void main()
{
return 0;
}
(a) main() cannot return value
(b) void keyword in not allowed to main()
(c) function should return a non-zero value
(d) return statement is not allowed
30. Which of the following statements are true?
Department of Computer Science and Application
Page 3
Question Bank
1) A return type of void specifies that no value be returned
2) Functions by default return in t value
3) The return type can only be int, char or double
(a) (1) and (2)
(b) (1),(2) and (3)
(c) (1) and (3)
(d) none of the above
31. c++ provides inline functions to facilitate reduce function call overhead, mainly for
(a) small functions
(b) large functions
(c) member functions
(d) none of the above
32. Which allows you to create a derived class that inherits properties from more than one
base class?
A. Multilevel inheritance
B. Multiple inheritance
C. Hybrid Inheritance
D. Hierarchical Inheritance
33. Which feature in OOP allows reusing code?
A) Polymorphism
B) Inheritance
C) Encapsulation
D) Data hiding
34. A function that changes the state of the cout object is called a(n) _____
A. member
B. adjuster
C. manipulator
D. operator
35. What does C++ append to the end of a string literal constant?
A. a space
B. a number sign (#)
C. an asterisk (*)
D. a null character
36. An array element is accessed using
A. a first-in-first-out approach
C. a member name
37. To hide a data member from the program, you must declare the data member in the
_____ section of the class
A. concealed
B. confidential
C. hidden
D. private
E. restricted
38. The function whose prototype is void getData(Item *thing); receives
A. a pointer to a structure
B. a reference to a structure
C. a copy of a structure
D. four bytes
39. 10. The number of structures than can be declared in a single statement is
A. one
B. two
C. three
D. unlimited
40. Format flags may be combined using the _____
A. bitwise OR operator (|)
B. logical OR operator (||)
C. bitwise AND operator (&)
D. logical AND operator (&&)
Department of Computer Science and Application
Page 4
Question Bank
41. The arguments that determine the state of the cout object are called
A. classes
B. manipulators
C. format flags or state flags
D. state controllers
42. The following statement where T is true and F is false T&&T||F&&T
A. is true
B. is false
C. is wrong
D. not applicable in C language
43. The statement int num[2][3]={ {1,2}, {3,4}, {5, 6} };
A. assigns a value 2 to num[1][2]
B. assigns a value 4 to num[1][2]
C. gives an error message
D. assigns a value 3 to num[1][2]
44. The standard input stream, which refers to the keyboard, is called
A. cin
B. cout
C. stin
D. stout
45. Elements in an array are identified by a unique _____
A. data type
B. order
C. subscript
D. symbol
46. The body of a C++ function is surrounded by _____
A. parentheses
B. angle brackets
C. curly brackets
D. square brackets
47. Which of the following type casts will convert an Integer variable named amount to a
Double type?
A. (double) amount
B. (int to double) amount
C. int to double(amount)
D. int (amount) to double
48. 25. Which of the following is a string literal constant?
A. Visual C++
B. 137.45
C. A
D. 2,365
49. Which of the following, if any, are valid names for variables?
A. class
B. friend
C. #OnHand
D. void
E. None of the above is valid names for variables
50. You have assigned the address of Value to the pointer P, Which statement will display
the value stored in Value?
A. cout<<P;
B. cout<<*Value;
C. cout<<&P;
D. cout<<*P;
51. The void specifier is used if a function does not have return type.
a. True
b. False
52. You must specify void in parameters if a function does not have any arguments.
Department of Computer Science and Application
Page 5
Question Bank
a. True
b. False
Page 6
Question Bank
65. How many instances of an abstract class can be created?
A. 1
B. 5
C. 13
D. 0
66. Which of the following cannot be friend?
A. Function
C. Object
B. Class
D. Operator function
67. Which of the following concepts of OOPS means exposing only necessary information to
client?
A. Encapsulation
B. Abstraction
C. Data hiding
D. Data binding
68. Why reference is not same as a pointer?
A. A reference can never be null.
B. A reference once established cannot be changed.
C. Reference doesn't need an explicit dereferencing mechanism.
D. All of the above.
69. cout is a/an __________ .
A. operator
C. object
B. function
D. macro
70. Which of the following concepts provides facility of using object of one class inside
another class?
A. Encapsulation
B. Abstraction
C. Composition
D. Inheritance
71. How many types of polymorphisms are supported by C++?
A. 1
B. 2
C. 3
D. 4
72. Which of the following is an abstract data type?
A. int
B. double
C. string
D. Class
73. Which of the following concepts means adding new components to a program as it runs?
A. Data hiding
B. Dynamic typing
C. Dynamic binding
D. Dynamic loading
74. Which of the following statement is correct?
A. A constructor is called at the time of declaration of an object.
B. A constructor is called at the time of use of an object.
C. A constructor is called at the time of declaration of a class.
D. A constructor is called at the time of use of a class.
Department of Computer Science and Application
Page 7
Question Bank
75. Which of the following approach is adapted by C++?
A. Top-down
B. Bottom-up
C. Right-left
D. Left-right
76. Which of the following is correct about function overloading?
A. The types of arguments are different.
B. The order of argument is different.
C. The number of argument is same.
D. Both A and B.
77. Which of the following is correct about class and structure?
A. class can have member functions while structure cannot.
B. class data members are public by default while that of structure are private.
C. Pointer to structure or classes cannot be declared.
D. class data members are private by default while that of structure are public by
default.
78. Which of the following concepts means wrapping up of data and functions together?
A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism
Classes and objects
79. The members of a class are by default
(a) private
(b) public
(c) protected
(d) none of the above
(b) private
(d) none of the above
Question Bank
85. The size of object is equal. to
(a) total size of member data variables
(c) both (a) and (b)
86. In the prototype void sum( int &); arguments are passed
(a) value
(b) reference
(c) address
(d) none
Constructors and destructors
87. Constructors and destructors are automatically invoked by
(a) compiler
(c) main () function
(b) operating system
(d) object
88. Constructor is executed when
(a) object is declared
(b) object is destroyed
Operator overloading
92. Which one of the following operator cannot be overloaded
(a) dot operator ( . )
(b) plus operator (+)
(c) & ampersand operator
(d) -- operator
93. In postfix overloading of operator (++ or - -), the last argument should have type
(a) int
(b) void
(c)float
(d) long
94. A, B and C are objects of same class. To execute the statement C=A+B,the operator must
be overloaded.
(a) +
(b) =
(c) both (a) and (b)
(d) none of the above
95. The operator function returns value of
(a) basic type
(b) void type
(c) class type
( d) all types
Department of Computer Science and Application
Page 9
Question Bank
Inheritance
96. An object a cannot access the variable
class A
{
public:
int a;
private:
int b;
public:
A() {a=10,b=20;}
};
void main(){ A a;}
(a) b
(c) both (a) and (b)
(b) a
(d) both a and b are accessible
102.
The class is declared virtual when
a) two or more classes involved in inheritance have common base class
b) more than one class is derived
c) we want to prevent a base class from inheritance
Department of Computer Science and Application
Page 10
Question Bank
d) none of the above
103.
The ambiguity of members normally occurs in
(a) single inheritance
(b) multilevel inheritance
(b) multiple inheritance
(d) none of the above
104.
Class A is a base class of class B. The relationship between them is
(a) kind of relationship
(b) has a relationship
(c) is a relationship
(d) none of the above
Pointers and Array
105.
The pointer holds
(a) address of the variable
(c) both (a) & (b)
106.
An integer type pointer can hold only address of
(a) integer variable
(b) float variable
(c) any variable
(d)none
107.
The address of the variable is displayed by the symbol
(a) & (ampersand)
(b) *(asterisk)
(c) (not operator)
(d) none
108.
The sizeof ( ) object is equal to
(a) total size of data member variables
(c) size of large element
109.
Array elements are stored in
(a) continuous memory locations
(c) CPU registers
110.
Private member variables can be accessed directly using
(a) pointers
(b) arrays
(c) this pointer
(d) none
111.
The object itself is a
(a) pointer
(c) class member
(a) variable
(d) none
112.
The size of void pointers is
(a) 2 bytes
(c) 4 bytes
(b) 0 byte
(d) none
113.
The this is present in every
(a) member function
(c) every object
Page 11
Question Bank
114.
The array name itself is a
(a) pointer
(c) variable
(b) reference
(d) object
B is a base class object and Dis derived class object. The statement B=D .
copies all elements of object d to object b
copies only base portion of object d to b
copies only derived portion of object D to B
none of the above
121.
When a base class is not used for object declaration it is called as
(a) abstract class
(b) container class
(c) concrete class
(d) derived class
122.
The derived class without pure virtual function is called as
(a) concrete class
(c) container class
(b) abstract class
(d) derived class
123.
a)
b)
c)
d)
Page 12
Question Bank
Page 13
Question Bank
Solve the Following Questions
Introduction to C++
1.
2.
3.
4.
5.
6.
7.
8.
9.
C++ declarations
16. Describe different parts of C++ programs.
17. List the new keywords in C++ with their functions.
18. What are identifiers, variables, and constants?
19. Which are the two types of constants? Describe them with suitable examples.
20. Describe the statements for creating constants. Explain with examples.
21. What is the use of the keyword void? In how many ways can it be used with function?
22. What is the difference between variable declaration in C and C++?
Department of Computer Science and Application
Page 14
Question Bank
23. Describe the use of scope access operator ( : :) and reference operator (&).
24. Describe types of derived data type.
25. Describe Precedence of operators in C++
26. Explain typecasting. What are explicit and implicit type conversions?
27. Explain use of comma operator.
Control Structures
28. Explain the need of control structures in c++.
29. What are the differences between break and continue statements?
30. Why goto statement is not commonly used?
31. Explain the working of if-else statement.
32. Explain the working of switch ()case statement.
33. Explain the role of break statement in switch ()case.
34. What are the differences between while and do-while loop statements?
35. What is an infinite loop?
36. Explain nested if's.
37. Explain nested switch () case statement.
38. Explain the use of the keyword default.
Functions in C++
39. What are the differences between C and C++ functions?
40. Describe different parts of a function?
41. What are void functions?
42. What does function prototype mean? Is it compulsory?
43. When is function prototype declaration not necessary?
44. What are default arguments? .
45. Where are default arguments assigned?
46. How are default arguments entered at run- time?
47. What are inline functions? Discuss its advantages and disadvantages.
48. What is the difference between call by value and call by reference? illustrate them with
examples.
49. What are constant arguments?
50. How is the value of a constant variable changed?
51. What is function overloading?
52. What are the rules for defining overloaded functions?
53. What precautions should we take while overloading function?
54. What is the difference between pointer and reference variable?
55. What is the difference between normal function and inline function?
56. What are actual and formal arguments?
57. How does return statement pass more than one value from function?
Classes and objects
58. Explain class and struct with their differences.
59. Which operators are used to access members?
Department of Computer Science and Application
Page 15
Question Bank
60. Explain the uses ofpri vate and public keywords. How are they different from each other?
61. Explain features of member functions.
62. What are static member variables and functions?
63. How are static variables initialized? Explain with the statement.
64. What are friend functions and friend classes?
65. How are static functions and friend functions invoked?
66. What do you mean by constant function?
67. What are local classes?
68. List the keywords terminated by colon with their use.
69. Can member functions be private?
70. What is the concept of data hiding? What are the advantages of its applications?
71. Is it possible to access private data members without using member function? If yes,
explain the procedure with an example.
72. What are static objects?
73. What is the difference between object and variable?
Constructors and destructors
74. What are constructors and destructors?
75. Explain the characteristics of constructors and destructors?
76. Explain constructors with arguments. How are arguments passed to the constructor?
77. What do you mean by overloading of constructors? How does it benefit the programmer?
78. Explain constructor with default arguments?
79. What is copy constructor?
80. What is the difference between calling methods for constructor and destructor?
81. What is static object? How is it different from normal object?
82. How are private constructors and destructors executed?
83. What is default constructor?
84. What is parameterized constructor?
Operator overloading
85. What do you mean by operator overloading?
86. What is the use of the keyword operator?
87. What are the rules for overloading operators?
88. What is the difference between operator overloading and function overloading?
89. What is the difference between overloading of binary operators and unary operators?
90. How are friend functions used to carry out overloading of operators? In which situation
are they helpful?
91. Describe rules for operator overloading.
Inheritance
92. What do you mean by inheritance?
93. What do you mean by base class and derived class?
94. Describe various types of inheritances with examples.
Department of Computer Science and Application
Page 16
Question Bank
95. What is the difference between single and multilevel inheritance?
96. What is the difference between multilevel and hybrid inheritance?
97. How are constructors and destructors executed in multilevel inheritance?
98. What is the use of virtual keyword?
99. What do you mean by virtual classes?
100.
What are abstract classes?
101.
Describe the use of public, private and protected access specifiers.
102.
What is the difference between private and protected access specificiers?
103.
What is the difference between private and protected inheritance?
104.
What are the advantages and disadvantages of inheritance?
105.
Explain hierarchical inheritance.
Pointers and arrays
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
What is polymorphism?
Explain compile time and run-time binding.
Explain the use of virtual keyword.
What are pure functions? How are they declared?
Is it possible to declare an object of the class that contains pure function?
What is the difference between virtual function and virtual classes?
How C++ compiler accomplishes dynamic binding?
Where do we use virtual functions? Give its applications.
What is early binding and late binding?
Describe rules for declaring virtual functions.
What is the difference between base class pointer and derived class pointer?
Page 17
Question Bank
Implement the programs in C++
1. Write a program to evaluate following series:
(a) x=x2+x3+ __x"
(b) z=x-y (Use (a) and (b)
(c) y=2x+2*(x3-lO)
(d) Display square root of z.
2. Write a program to display A to Z characters using while loop.
3. Write a program to draw a square box. Use for loop.
4. Write a program to declare and initialize a variable. Create a reference variable. Display
the value of actual
5. variable using reference variable.
6. Given the Vander Wall's constants x and y for a gas. Calculate the critical temperature,
pressure, and volume
7. using the' following formulas:
(a) ct= 8x/27Rb
(b) p=x/27b2
(c) v=3b
(d) R= 0.0821 dm3atm/mol/k.
(e) Read values of x and y and calculate and print the values of ct.p, and v.
8. The sum of the square of the first n natural numbers is calculated by the formula sum=n
(n+l) * (2n+l)/
9. Read value of n through the keyboard and calculate the sum of square of first n natural
numbers.
10. Write a program to calculate
(a) Area of circle (area=3.12*?)
(b) Circumference of the circle (c=2*3.12*r)
(c) Volume of the cylinder (v=3.12*?*h)
(d) Surface area of the closed cylinder (s=2*3.12*r*h+2*3.12*?)
(e) Volume of sphere (v=413*3.12*,-'1)
11. A company gives following rates of commission for the monthly sales of the product:
(a) Below Rs. 15000/No commission
(b) 15001-20000/5%
(c) 20001-30000/10%
(d) Above 30000/12%
(e) Write a program to read the sales and display the commission.
12. Write a program to display the sum of odd numbers between 1 to 150.
13. A worker takes a job for 31 days. His pay for the first day is Rs. 20. His pay for the
second day is Rs. 40. Each day's pay is twice what he gets in the previous day. What will
be the total pay for 31 days?
14. Write a program to find the range of the given numeric data.(Range smallest numberlargest number)
15. Write a program to display numbers from 10to 1using for loop.
16. Write a program to calculate the factorial of a given number.
17. Write a program to display only even numbers in between 1 to 150.
18. Write a program to solve the series x=1I2!+1/4!+lIn!.
Department of Computer Science and Application
Page 18
Question Bank
19. Write a program to calculate the sum of numbers between 1to N numbers. The user enters
the value of N.
20. Write a program to use break and continue statements.
21. Write a program to display alphabets A to Z using while loop.
22. Write a program to use break statement and terminate the loop.
23. Write a program to demonstrate the use of continue statement.
24. Write a program to calculate the square root of 1 to 10 numbers. Display the sum of
integer parts and fractional parts of the square roots obtained. (Note: set precision to 2)
25. Write a program to overload function to convert an integer number to an ASCII character
and float to ASCII string.
26. Write an inline function to display lines of different patterns.
27. Write a program to find the power of integer number like pow () library function.
28. Write a program to return more than one values from function. Use call by reference
method.
Classes and objects
29. Write a program to declare a class with three integer public data variables. Initialize and
display them.
30. Write a program to declare private data member variables and public member function.
Read and display the values of data member variables.
31. Write a program to declare private data member and a function. Also declare public
member function. Read and display the data using private function.
32. Write a program to declare three classes 81,82, and 83. The classes have a private data
member variable of character data type. Read strings for the classes 81 and 82.
Concatenate the strings read and assign it to the data member variable of class 83.
33. Write a program to enter positive and negative numbers. Enter at least 10 numbers. Count
the positive and negative numbers. Use classes and objects.
Constructors and destructors
34. Write a program to declare a class with private data members. Accept data through
constructor and display the data with destructor.
35. Write a program to pass an object to constructor and carry out copy constructor. Display
contents of all the objects.
36. Write a program to declare a class with three data members. Declare overloaded
constructors with no arguments, one argument, two arguments, and three arguments. Pass
values in the object declaration statement.
37. Create four objects and pass values in such a way that the entire four constructors are
executed one by one. Write appropriate messages in constructor and destructor so that the
execution of the program can be understood.
38. Write a program to declare a class with two data members. Also, declare and define
member functions to display the content of the class data members. Create object A.
Display the contents of object A. Again initialize the object A using explicit call to
constructor. This time pass appropriate values to constructor. Display the contents of
object A using member function.
Department of Computer Science and Application
Page 19
Question Bank
Operator overloading
39. Write a program to overload < operator and display the smallest number out of two
objects.
40. Write a program to overload = operator. Assign values of data.members of one object to
another object of the same type.
41. Write a program to overload = = operator. Compare two objects using overloaded
operator.
42. Write a program to evaluate the equation A=B*3,where A and B are objects of same
class. Use friend function.
Inheritance
43. Write a program to show inheritance between two classes
44. Write a program to create multilevel inheritance. Create classes A1,A2,A3.
45. Write a program to derive a class from multiple base classes
46. Write a program to show hierarchical inheritance.
47. Write a program to create a derived class from multiple base classes
48. Write a program to declare virtual base classes. Derive a class using two virtual classes.
Pointers and Arrays
49. Write a program to display the address of the variable
50. Write a program to declare a pointer. Display the value and address of the variable using
pointers.
51. Write a program to declare a void pointer
52. Write a program to use wild pointer
53. Write a program to declare a pointer to a class.
54. Write a program to use this pointer and return pointer reference.
55. Write a program to declare a pointer to the base class and access the member variable of
base and derived clas.
56. Write a program to display names, rollno and grades of 3 students using array of class
objects.
Binding, Polymorphism and Virtual Functions
57. Write a program to declare virtual function and execute the same function defined in base
and derived classes.
58. Write a program to declare pure virtual function.
59. Write a program to define virtual, non-virtual function and determine size of the objects.
Page 20