Holiday Tumsar

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Question Bank

Object Oriented Programming Using C++


Objective type questions
1. C++ language was invented by
(a) Bjame Stroustrup
(b) Dennis Ritche

(c) Ken Thompson


(d) none of the above

2. The languages COBOL and BASIC are commonly known as


(a) procedure oriented languages
(b) object-oriented languages
(c) low level languages
(d) none of the above
3. The packing of data and functions into a single component is known as
(a) encapsulation
(b) polymorphism
(c) abstraction
(d) none of the above
4. The method by which objects of one class get the properties of objects of another class is
known as
(a) inheritance
(b) encapsulation
(c) abstraction
(d) none of the above
5. The mechanism that allows same functions to act differently on different classes is
known as
(a) polymorphism
(b) encapsulation
(c) inheritance
(d) none of the above
6. Object-oriented programming is popular because
(a) user can define user-defined data types
(b) programming statements are easy
(c) it is easy to find bugs and errors
(d) all of the above
7. The existing class can be reused by
(a) inheritance
(c) dynamic binding

(b) polymorphism
(d) abstraction

8. Composition of objects in a class is known as


(a) delegation
(b) inheritance
(c) polymorphism
(d) none of the above
9. The cin and cout functions require the header file to include
(a) iostream.h
(b) stdio.h
(c) iomanip. h
(d) none of the above
10. The set. precision () is used to set
(a) decimal places
Department of Computer Science and Application

(b) number of digits


Page 1

Question Bank
(c) field width

(d) none of the above

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

13. This function accepts the string with blank spaces


(a) getline ( )
(b) cin
(c) scanf ( )
(d) none of the above
14. The streams is a
(a) flow of data
(c) flow of statements

(b) flow of integers


(d) none of the above

15. The statement cin hex reads the data in


(a) hexadecimal format
(c) binary format

(b) octal format


(d) decimal format

16. In C++, the symbol used for writing comments is


(a) / /
(b) //* *//
(c) * / * /
(d) none of the above
17. The :: is known as
(a) scope access operator
(c) both (a) and (b)

(b) double colons


(d) none of the above

18. What will be the output of the following program?


(a) # include <iostream.h>
(b) void main()
(c) {
i. char *n;
ii. cout sizeof (n);
(d) }
(a) 2
(b) 1

(c) 4
(d) none of the above

19. Which of the following loop statement uses two keywords?


(a) do-while loop
(c) while loop
(b) for loop
(d) none of the above
20. The statement which requires at least one statement followed by it is
(a) default
(b) continue
Department of Computer Science and Application

Page 2

Question Bank
(c) break

(d) else

21. The loop statement terminated by a semi-colon is


(a) do-while loop
(c) while loop
(b) for loop
(d) none of the above
22. The meaning of if (1) is
(a) always true
(c) both (a) and (b)

(b) always false


(d) none of the above

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

(c) when arguments are passed by reference


(d) none of the above

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

B. the dot operator


D. an index number

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

E. All of the above

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

53. Type specifier is optional when declaring a function


a. True
b. False
54. A pointer to a block of memory is effectively same as an array
A. True
B. False
55. Does this mentioning array name gives the base address in all the contexts?
A. Yes
B. No
56. Is there any difference in the following declarations?
int fun(int arr[]);
int fun(int arr[2]);
A. Yes
B. No
57. Are the expressions arr and &arr same for an array of 10 integers?
A. Yes
B. No
58. The keyword used to transfer control from a function back to the calling function is
A. switch
B. goto
C. go back
D. return
59. Which of the following type of class allows only one object of it to be created?
A. Virtual class
B. Abstract class
C. Singleton class
D. Friend class
60. Which of the following is not a type of constructor?
A. Copy constructor
B. Friend constructor
C. Default constructor
D. Parameterized constructor
61. Which of the following is not the member of class?
A. Static function
B. Friend function
C. Const function
D. Virtual function
62. Which of the following concepts means determining at runtime what method to invoke?
A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading
63. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
64. Which of the following concept of oops allows compiler to insert arguments in a function
call if it is not specified?
A. Call by value
B. Call by reference
C. Default arguments
D. Call by pointer
Department of Computer Science and Application

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

80. The members of struct are by default


(a) public
(c) protected

(b) private
(d) none of the above

81. The private data of any class is accessed by


(a) only public member function
(c) both (a) and (b)

(b) only private member function


(d) none of the above

82. When the class is declared inside the function, it is called as


(a) local class
(b) global class
(c) both (a) and (b)
(d) none of the above
83. A non-member function that can access the private data of class is known as
(a) friend function
(b) static function
(c) member function
(d) library function
84. Encapsulation means
(a) protecting data
(b) allowing global access
Department of Computer Science and Application

(c) data hiding


(d) both (a) and (c)
Page 8

Question Bank
85. The size of object is equal. to
(a) total size of member data variables
(c) both (a) and (b)

(b) total size of member function


(d) none

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

(c) both (a) and (b)


(d) none of the above

89. The destructor is executed when


(a) object goes out of scope
(c) when object contains nothing

(b) when object is not used


(d) none of the above

90. Destructors can be


(a) overloaded
(b) able to return result

(c) able to return result


(d) explicitly called

91. Constructor has the same name as


(a) the class they belong to
(c) class name and preceded by -

(b) the current program file name


(d) both a and c

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

97. Private data members of a class can be accessed by


(a) public member functions of the same class
(b) directly by the object
(c) private member function of the same class
(d) none
98. In multilevel inheritance, the middle class acts as
(a) base class as well as derived class
(b) only base class
(c) only derived class
(d) none
99. In single inheritance, constructors are executed from
(a) base class to derived class
(b) derived class to base class
(c) both (a) and (b)
(d) none
100.
In the following program object of which class can access all member variables?
struct A { int X; } ;
struct B A int y; } ;
struct C B int z; } ;
struct D C { int k; } ;
(a) object of class D
(b) object of class B
(c) object of class C
(d) object of class A
101.
(a)
(b)
(c)
(d)

The protected keyword allows


derived class to access base class members directly
prevents direct access to public members
allows objects to access private members
all of the above

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)

(b) value of the varible


(d) none

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

(b) total size of member function


(d) none

(b) different memory location


(d) none

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

(b) non-member function


(d) all of the above

Department of Computer Science and Application

Page 11

Question Bank
114.
The array name itself is a
(a) pointer
(c) variable

(b) reference
(d) object

Binding, Polymorphism and Virtual Functions


115.
Consider the statement virtual void display () = o. The display () function is
(a) pure virtual function
(b) pure member function
(c) normal function
(d) all of the above
116.
The do-nothing function is nothing but
(a) pure virtual function
(b) pure member function
(c) both (a) and (b)
(d) none
117.
Static binding is done at the time of
(a) compilation of the program
(b) at run time
(c) both (a) and (b)
(d) none
118.
Dynamic binding is done using the keyword
(a) virtual
(b) inline
(c) static
(d) void
119.
The virtual keyword solves the
(a) ambiguity in base and derived classes
(c) ambiguity in base classes
120.
(a)
(b)
(c)
(d)

(b) ambiguity in derived classes


(d) none of the above

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)

A pointer to base class object can hold address of


only derived class object
only base class object
address of base class object and its derived class object
none of the above

Department of Computer Science and Application

Page 12

Question Bank

Department of Computer Science and Application

Page 13

Question Bank
Solve the Following Questions
Introduction to C++
1.
2.
3.
4.
5.
6.
7.
8.
9.

What is object-oriented programming?


Explain the key concepts of OOP.
What is ANSI standard?
What are the disadvantages of conventional programming languages?
Explain the evolution of C++.
List the names of popular OOP languages.
List the unique features of an OOP paradigm.
What is an object and a class?
Compare and contrast OOP languages with procedure oriented languages.

Input and Output


1. List the names of pre-defined streams with their 'C' equivalents?
2. What are formatted and unformatted input/output functions?
3. Distinguish between
(a) cin () and scanf ()
(b) cout () and printf ()
(c) ios:: fixed and cout. precision ()
4. What are the uses of put () and get () functions?
5. What is the use of getline () function? Which two arguments does it require?
6. Describe bit fields required in setf () function.
7. List the flags without bit fields with their working.
8. What is the role of iostream. hand iomanip. h header files?
9. Write the statement for concatenation of two strings using cout. wri te () statement.
10. Describe the procedure for designing manipulator.
11. What is the function of peek () and ignore () functions?
12. What are ingle and multiple parameter manipulator?
13. In which format the cout statement display the address of variable? How can it be
converted to unsigned?
14. What do you mean by formatted and unformatted data?
15. Explain the procedure for creating custom input/output objects

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 are pointers?


What is void pointer?
What is this pointer?
What are the features and uses of pointers?
In which situation does the pointer become harmful?
Explain any two characteristics of pointers.
What are arrays?
Explain array declaration and initialization
Explain the characteristics of arrays with example.
Explain array of classes.

Binding, Polymorphism and Virtual Functions


116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.

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?

Department of Computer Science and Application

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.

Department of Computer Science and Application

Page 20

You might also like