wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

OOPs Using C++ (CSE)

Total questions: 125

Worksheet time: 1hrs 20mins

Name
Class
Date
1.

OOPs stands for

a)

Object Oriented Programming

b)

Oriented object Programming

2.

_____ is an object oriented language

a)

c++

b)

compiler

c)

programming

3.

The __________ statement uses single expression for multiple choices

a)

loop

b)

switch

c)

multiple value

d)

if else

4.

C++ is built upon the foundation of C.

a)

True

b)

False

c)

Trulse

d)

I don't know

5.

A programming mechanism that binds together code and the data it manipulates, and that keeps both safe from outside interference and misuse.

a)

Polymorphism

b)

Inheritance

c)

Encapsulation

d)

Object-Oriented Programming

6.

(from Greek meaning “many forms”) is the quality that allows one interface to access a general class of actions.

a)

Polymorphism

b)

Inheritance

c)

Encapsulation

d)

Object-Oriented Programming

7.

Is the process by which one object can acquire the properties of another object.

a)

Polymorphism

b)

Inheritance

c)

Encapsulation

d)

Object-Oriented Programming

8.

C++ is procedure oriented programming & C is object oriented programming.

a)

True

b)

False

c)

Trulse

d)

I don't know

9.

A blueprint for a software object is called a ___.

a)

object

b)

program

c)

API

d)

class

10.

Allows us to consider complex ideas while ignoring irrelevant detail that would confuse us.

a)

Abstraction

b)

Encapsulation

c)

Generalisation

d)

Polymorphism

e)

Object

11.

An _________ is an instance or of a copy of a class.

a)

Class

b)

Attribute

c)

Object

12.

________ is wrapping /hiding of data into a single unit called class

a)

Abstraction

b)

Polymorphism

c)

Encapsulation

d)

Inheritance

13.

__________ refers to the act of representing essential details.

a)

Polymorphism

b)

Abstraction

c)

Inheritance

d)

Encapsulation

14.

__________ is the process of using a function for more than one purpose. It allows the use of different internal structures of the object by keeping the same external interface.

a)

Inheritance

b)

Polymorphism

c)

Abstraction

d)

Encapsulation

15.
These have identitystate, and behavior.
a)
class
b)
object
c)
method
d)
void
16.
Which line of code would you use to print the value of a variable named Result to the screen?
a)
cout << Result << endl;
b)
cin >> "Result" >> endl;
c)
cin >> Result >> endl;
d)
cout << "Result" << endl;
17.
Which of the following approach is adapted by C++?
a)
Top down
b)
Bottom up
c)
Right to left
d)
left right
18.

c++ is an _____________ , developed by ______________ , and is an extension of c language

a)

object oriented program , Bjarane

b)

class and data

c)

complier, interpreter

d)

functions comments

19.

What does modularity means?

a)

Hiding part of program

b)

Subdividing programs into small independent parts

c)

Overriding parts of programs

d)

Wrapping things into single unit?

20.

Which of the following explains Polymorphism?

a)

int func(int, int);

float func1(float, float);

b)

int func(float);

int func(int, int, char);

c)

int func();

int new_func();

d)

int func(int);

int func(int);

21.

Which of the following is C++ equivalent for scanf()?

a)

cout

b)

cin

c)

scanf

d)

input

22.

What is the only function all C++ programs must contain?

a)

start()

b)

system()

c)

main()

d)

program()

23.
What is the output of this program?
Program
int main()
{
cout<<"Hi everybody";
return 0;
}
a)
"Hi everybody"
b)
Hi everybody"
c)
Hi everybody
d)
"Hi everybody
24.

Wrapping data and its related functionality into a single entity is known as _____________

a)

Abstraction

b)

Encapsulation

c)

Polymorphism

d)

Modularity

25.

How structures and classes in C++ differ?

a)

In Structures, members are public by default whereas, in Classes, they are private by default

b)

In Structures, members are private by default whereas, in Classes, they are public by default

c)

Structures by default hide every member whereas classes do no

d)

Structures cannot have private members whereas classes can have

26.

What does polymorphism in OOPs mean?

a)

Concept of allowing overiding of functions

b)

Concept of hiding data

c)

Concept of keeping things in differnt modules/files

d)

Concept of wrapping things into a single unit

27.

Which concept allows you to reuse the written code?

a)

Encapsulation

b)

Abstraction

c)

Inheritance

d)

Polymorphism

28.

vWhich of the following explains Polymorphism?

a)

int func(int, int); float func1(float, float);

b)

int func(int); int func(int);

c)

int func(float); float func(int, int, char);

d)

int func(); int new_func();

29.

C++ is ______________

a)

procedural programming language

b)

object oriented programming language

c)

functional programming language

d)

both procedural and object oriented programming language

30.

Which of the following feature of OOPs is not used in the following C++ code?

class A

{ int i;

public:

void print() {cout << "hello" << i;}

}

class B : public A{

int j;

public: void assign (int a ) {k = a;}

}

a)

Abstraction

b)

Encapsulation

c)

Inheritance

d)

Polymorphism

31.

Which of the following class allows to declare only one object of it?

a)

Abstract class

b)

Virtual class

c)

singleton class

d)

Friend class

32.

Which of the following is correct?

a)

Base class pointer object cannot point to a derived class object

b)

Derived class pointer object cannot point to a base class object

c)

A derived class cannot have pointer objects

d)

A base class cannot have pointer objects

33.

What is the other name used for functions inside a class?

a)

Member variables

b)

Member functions

c)

Class functions

d)

Class variables

34.

How many types of polymorphism are there in C++?

a)

1

b)

2

c)

3

d)

4

35.

Which of the following is an abstract data type?

a)

int

b)

float

c)

class

d)

string

36.

Which of the following explains the overloading of functions?

a)

Virtual polymorphism

b)

Transient polymorphism

c)

Ad-hoc polymorphism

d)

Pseudo polymorphism

37.

Which of the following approach is used by C++?

a)

Top-down

b)

bottom-up

c)

left-right

d)

right-left

38.

Which of the following is correct?

a)

C++ allows static type checking

b)

C++ allows dynamic type checking.

c)

C++ allows static member function to be of type const.

d)

C++ allows both static and dynamic type checking

39.

Which keyword is used to declare the friend function?

a)

friend

b)

firend

c)

classfriend

d)

myfriend

40.

What is the syntax of friend function?

a)

friend class1 Class2;

b)

friend class;

c)

friend class

d)

friend class()

41.

Pick out the correct statement.

a)

A friend function may be a member of another class

b)

A friend function may not be a member of another class

c)

A friend function may or may not be a member of another class

d)

none of the above

42.

Where does keyword ‘friend’ should be placed?

a)

function declaration

b)

function definition

c)

main function

d)

block function

43.

A friend class can access ____________________ members of other class in which it is declared as friend.

a)

private

b)

protected

c)

public

d)

both private and protected

44.

Which feature of OOP indicates code reusability?

a)

Abstraction

b)

Polymorphism

c)

Encapsulation

d)

Inheritance

45.

Which of the following is associated with objects?

a)

State

b)

Behaviour

c)

Identity

d)

All of the above

46.

The feature in object-oriented programming that allows the same operation to be carried out differently, depending on the object, is:

a)

Inheritance

b)

Polymorphism

c)

Overfunctioning

d)

Overriding

47.

Which among the following feature is not in the general definition of OOPS?

a)
  1. Modularity

b)
  1. Efficient Code

c)
  1. Code reusability

d)
  1. Duplicate or Redundant Data

48.

How many types of polymorphism in the C++ programming language?

a)
  1. Three types of polymorphism

b)
  1. Two types of polymorphism

c)
  1. Five types of polymorphism

d)
  1. Four types of polymorphism

49.

Consider the following two statements: (a)A publicly derived class is a subtype of its base class. (b)Inheritance provides for code reuse.

a)

Both the statements (a) and (b) are correct.

b)

Neither of the statements (a) and (b) are correct

c)

Statement (a) is correct and (b) is incorrect

d)

Statement (a) is incorrect and (b) is correct

50.

Which of the following OOP concept binds the code and data together and keeps them secure from the outside world?

a)
  1. Polymorphism

b)

Inheritance

c)

Abstraction

d)
  1. Encapsulation

51.

Which of the following feature is also known as run-time binding or late binding?

a)
  1. Dynamic typing

b)
  1. Dynamic loading

c)
  1. Dynamic binding

d)
  1. Data hiding

52.

The combination of abstraction of the data and code is viewed in (a)   .

53.

The name of the default access specifier for the member functions or data members in the C++ programming language is (a)   .

54.

What is an exception in C++?

a)

A syntax error

b)

An unexpected problem that occurs during the execution of a program

c)

A warning from the compiler

d)

A type of function call

55.

When do exceptions occur in C++?

a)

At compile-time

b)

During runtime

c)

During memory allocation

d)

At link-time

56.

Which keyword is used to handle exceptions in C++?

a)

try

b)

catch

c)

throw

d)

All of the above

57.

What is the purpose of the try block in C++?

a)

To execute code and handle exceptions

b)

To contain code that might throw an exception

c)

To throw an exception

d)

To catch exceptions from other blocks

58.

What happens if an exception is thrown in C++ but not caught?

a)

The program will terminate abruptly

b)

The program will continue executing

c)

The exception will be ignored

d)

The program will pause and wait for user input

59.

What is the throw keyword used for in C++?

a)

To declare an exception

b)

To signal that an exception has occurred

c)

To handle an exception

d)

To define a new exception type

60.

What is the purpose of the catch block in C++?

a)

To declare an exception

b)

To handle an exception thrown from a try block

c)

To return a value from a function

d)

To prevent exceptions from occurring

61.

Which of the following is an example of a synchronous exception?

a)

Disk failure

b)

Division by zero

c)

Power failure

d)

Keyboard interrupt

62.

What is an asynchronous exception in C++?

a)

An exception that occurs due to user input errors

b)

An exception that occurs due to external factors beyond the program's control

c)

An exception that can be handled at compile-time

d)

An exception related to memory allocation

63.

Which of the following best describes the catch block?

a)

It always executes after the try block, regardless of exceptions

b)

It is used to define how to handle specific exceptions thrown by the try block

c)

It must be placed before the try block

d)

It can only catch one type of exception

64.

What are the benefits of exception handling in C++?

a)

It improves program readability and maintainability by separating normal code from error-handling code

b)

It guarantees the program will never crash

c)

It speeds up program execution

d)

It automatically fixes all runtime errors

65.

How do you catch all exceptions in a catch block?

a)

catch(int e)

b)

catch(...)

c)

catch(exception)

d)

catch(all)

66.

Which of the following is a limitation of exception handling in C++?

a)

It can lead to resource leaks if not handled properly

b)

It makes the code easier to read

c)

It automatically prevents memory leaks

d)

It is required for all programs

67.

Which of the following examples demonstrates throwing an exception for division by zero?

a)

throw 0;

b)

throw "Division by zero";

c)

throw exception;

d)

throw divide_by_zero;

68.

What is the purpose of a try-catch block in exception handling?

a)

To prevent exceptions from being thrown

b)

To transfer control from the point where an exception occurred to a handler that can manage the error

c)

To stop program execution

d)

To declare variables in a protected scope

69.

Which of the following is true about exception handling in C++?

a)

It only works with built-in exceptions

b)

Both basic types and objects can be thrown as exceptions

c)

Only objects can be thrown as exceptions

d)

Exceptions must always be caught within the same function where they are thrown

70.

What is the primary purpose of exception handling in C++?

a)

To increase program performance

b)

To handle runtime errors without crashing the program

c)

To fix all syntax errors in the code

d)

To manage memory allocation

71.

What happens if an exception is thrown in a try block but not caught?

a)

The program continues to run normally

b)

The program terminates with an error

c)

The exception is automatically ignored

d)

The program enters an infinite loop

72.

Which of the following is a valid catch block to handle an integer exception?

a)

catch(int e)

b)

catch(exception e)

c)

catch(...)

d)

catch(int)

73.

What is one of the limitations of using exception handling?

a)

Exceptions always slow down the program

b)

Exceptions may break the structure or flow of the code due to invisible exit points

c)

Exceptions are handled at compile-time

d)

Exception handling can only be used with pointers

74.

(a)   is a process of converting system error messages in to user friendly messages.

75.

An (a)   is an event, which occurs during the execution of a program, that disrupt the normal flow of a program's instructions.

76.

Exceptions are _________anomalies that a program encounters during execution.

a)

compile time

b)

run time

77.

The Keywords for handling the Exception in C++ are

a)

Try

b)

catch

c)

throw

d)

remove

78.

___________ block consists of the code that may generate exception.

a)

Try

b)

Catch

79.

_________keyword is used to throw an exception encountered inside try block.

a)

throw

b)

catch

c)

try

80.

Raising of an exception is done by _______expression.

a)

throw

b)

catch

81.

___________block detects and throws an exception

a)

Try

b)

catch

82.

_____________block catches and handles the exception.

a)

try

b)

catch

83.

__________block specifies the action to be taken when an exception occur.

a)

try

b)

catch

84.

A function can have _____ inside the parenthesis

a)

loops

b)

Arguments/Parameters

c)

Braces

d)

Types

85.

A function that returns a whole number starts with the word

a)

int

b)

void

c)

string

d)

{ }

86.

Fill in the blank to have this function work properly


_____ function ( ) {


int a = 4;

int b = 5;


cout<<a*b;


}

a)

string

b)

int

c)

void

d)

variable

87.

Fill in the blank to have this function work properly


_____ function ( ) {


string greeting = "Welcome to my game";


return greeting;


}

a)

string

b)

void

c)

int

d)

variable

88.

Select all of the types you may have for a function

a)

string

b)

bool

c)

void

d)

variable

e)

int

89.

What is the meaning of modular programming

a)

data type of the value that function returns to the part of the program that called it

b)

breaking a program up into smaller, manageable functions or modules

c)

one single program without breaking it into module

d)

none of the above

90.

It refers to the part of function heading that specifies an input for the function to perform its task

a)

global variable

b)

function arguments or function parameters

c)

function statements

d)

function heading

91.

This method copies the actual value of an argument into the formal parameter of the function.

a)

call by value

b)

call by pointer

c)

call by reference

92.

It is a type of variable that can only be used within a function

a)

local variable

b)

global variable

c)

parameter variables

d)

constant variable

93.

True or False. We can call functions inside of other functions.

a)

True

b)

False

94.

If an argument from the parameter list of a function is defined constant then _______________

a)

It can be modified inside the function

b)

It cannot be modified inside the function

c)

Error occurs

d)

Segmentation fault

95.

What will be the output of the following C++ code?

a)

10

b)

0

c)

Syntax error

d)

Segmentation fault

96.

Which variable retains its value in  between function calls?

a)

static

b)

register

c)

extern

d)

auto

e)

global

97.

How many values can a C Function return at a time?

a)

only one value

b)

maximum of 2 values

c)

maximum of 3 values

d)

maximum 8 values

98.

What is the main purpose of functions in C++?

a)

To execute loops faster

b)

To reduce code redundancy and improve reusability

c)

To replace the main() function

d)

To speed up compilation

99.

Which keyword defines a function that does not return a value?

a)

int

b)

return

c)

void

d)

float

100.

How do you call a function in C++?

a)

functionName;

b)

functionName()

c)

call functionName();

d)

define functionName();

101.

What is required in a function declaration?

a)

Function name and parameters

b)

Only the function body

c)

Function name, return type, and parameters (if any)

d)

Only the return type

102.

What will happen if a function is declared but not called?

a)

It will cause a compilation error

b)

It will execute automatically

c)

Nothing will happen

d)

The program will crash

103.

What is the default return type of a function in C++ if not specified?

a)

void

b)

int

c)

float

d)

char

104.

Which of the following statements about function parameters is true?

a)

A function can only have one parameter

b)

Parameters are mandatory in all functions

c)

Parameters act as variables inside the function

d)

Parameters must be initialized in the function declaration

105.

What is the correct way to define a function with two integer parameters?

a)

void function(int a, int b);

b)

function(int a, int b) {}

c)

int function(int a, int b) { return a + b; }

d)

void function() { int a, b; }

106.

What is "pass by reference" in functions?

a)

Passing values by copying them

b)

Allowing a function to modify the original variable

c)

Passing only integer values

d)

Calling a function multiple times

107.

Which function type returns a value?

a)

void function

b)

Function with no parameters

c)

Function with a return type

d)

Function with default parameters

108.

Which of the following is an example of function overloading?

a)

Two functions with the same name but different parameters

b)

A function calling another function

c)

A function using multiple loops

d)

A function with no return type

109.

Which statement about the return keyword is correct?

a)

It must always be used in functions

b)

It ends function execution and sends a value back

c)

It only works with int functions

d)

It can only be used once per function

110.

Which function prototype is correct?

a)

int sum(int x, y);

b)

void sum(int, int);

c)

function sum(int a, int b);

d)

int sum(int a) return a + 1;

111.

What happens if a function with void return type has a return statement with a value?

a)

Compilation error

b)

Function returns the value

c)

Undefined behavior

d)

The value is ignored

112.

What is required to pass an array as a function parameter?

a)

Specify the array size in the function definition

b)

Use the return keyword

c)

Declare the array inside the function

d)

Pass the array by reference or pointer

113.

What is the output of the following code: bool isDivisible(int x, int y) { return (x % y == 0); } cout << isDivisible(10, 5) << " " << isDivisible(10, 3);

a)

1 1

b)

1 0

c)

0 1

d)

0 0

114.

What is the output of the following code: int power(int base, int exp) { int result = 1; for (int i = 0; i < exp; i++) { result *= base; } return result; } cout << power(3, 3);

a)

9

b)

27

c)

81

d)

243

115.

What is the output of the following code: int check(int num) { if (num > 10) return 1; return 0; } cout << check(15) << " " << check(5);

a)

0 0

b)

1 1

c)

1 0

d)

0 1

116.

What is the output of the following code: int compute(int a, int b = 4, int c = 2) { return a + b * c; } cout << compute(5) << " " << compute(5, 3) << " " << compute(5, 3, 3);

a)

10 9 11

b)

13 11 14

c)

20 18 15

d)

12 10 13

117.

What is the output of the following code: int square(int n) { return n * n; } int cube(int n) { return n * n * n; } cout << square(cube(2));

a)

8

b)

16

c)

64

d)

256

118.

What is the output of the following code: int multiply(int a, int b) { return a * b; } int add(int a, int b) { return a + b; } cout << multiply(add(2, 3), 2);

a)

5

b)

7

c)

10

d)

12

119.

What is the output of the following code: void update(int &x) { x += 10; } int num = 5; update(num); cout << num;

a)

5

b)

10

c)

15

d)

Compilation error

120.

Develop a C++ program that checks if a person is eligible to vote. Implement a function that takes an integer representing a person's age as input and prints whether they are eligible to vote (18 years or older). Requirements: Implement a function void checkEligibility(int age). If the age is 18 or above, print "You are eligible to vote!" Otherwise, print "You are NOT eligible to vote!" Example Input/Output: Enter your age: 16 You are NOT eligible to vote!

4 lines
121.

Which of the following is the default return value of functions in C++?

a)
char
b)
float
c)
int
d)
void
122.

What is the purpose of the 'void' keyword in C++ functions?

a)

To indicate that the function does not return a value

b)

To specify the return type as an integer

c)

To define a function that takes no arguments

d)

To declare a function as private

123.

From which function the execution of a C++ program starts?

a)

init() function

b)

start() function

c)

main() function

d)

begin() function

124.

Which of the following is important in a function?

a)

Return Type

b)

Function Name

c)

parameter list

d)

all of these

125.

When do we define the default values for a function?

a)

In the function declaration

b)
In the function call
c)
After the function execution
d)
During the function testing