Font size
WorksheetsOOPs Using C++ (CSE)
Total questions: 125
Worksheet time: 1hrs 20mins
OOPs stands for
Object Oriented Programming
Oriented object Programming
_____ is an object oriented language
c++
compiler
programming
The __________ statement uses single expression for multiple choices
loop
switch
multiple value
if else
C++ is built upon the foundation of C.
True
False
Trulse
I don't know
A programming mechanism that binds together code and the data it manipulates, and that keeps both safe from outside interference and misuse.
Polymorphism
Inheritance
Encapsulation
Object-Oriented Programming
(from Greek meaning “many forms”) is the quality that allows one interface to access a general class of actions.
Polymorphism
Inheritance
Encapsulation
Object-Oriented Programming
Is the process by which one object can acquire the properties of another object.
Polymorphism
Inheritance
Encapsulation
Object-Oriented Programming
C++ is procedure oriented programming & C is object oriented programming.
True
False
Trulse
I don't know
A blueprint for a software object is called a ___.
object
program
API
class
Allows us to consider complex ideas while ignoring irrelevant detail that would confuse us.
Abstraction
Encapsulation
Generalisation
Polymorphism
Object
An _________ is an instance or of a copy of a class.
Class
Attribute
Object
________ is wrapping /hiding of data into a single unit called class
Abstraction
Polymorphism
Encapsulation
Inheritance
__________ refers to the act of representing essential details.
Polymorphism
Abstraction
Inheritance
Encapsulation
__________ 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.
Inheritance
Polymorphism
Abstraction
Encapsulation
c++ is an _____________ , developed by ______________ , and is an extension of c language
object oriented program , Bjarane
class and data
complier, interpreter
functions comments
What does modularity means?
Hiding part of program
Subdividing programs into small independent parts
Overriding parts of programs
Wrapping things into single unit?
Which of the following explains Polymorphism?
int func(int, int);
float func1(float, float);
int func(float);
int func(int, int, char);
int func();
int new_func();
int func(int);
int func(int);
Which of the following is C++ equivalent for scanf()?
cout
cin
scanf
input
What is the only function all C++ programs must contain?
start()
system()
main()
program()
Program
int main()
{
cout<<"Hi everybody";
return 0;
}
Wrapping data and its related functionality into a single entity is known as _____________
Abstraction
Encapsulation
Polymorphism
Modularity
How structures and classes in C++ differ?
In Structures, members are public by default whereas, in Classes, they are private by default
In Structures, members are private by default whereas, in Classes, they are public by default
Structures by default hide every member whereas classes do no
Structures cannot have private members whereas classes can have
What does polymorphism in OOPs mean?
Concept of allowing overiding of functions
Concept of hiding data
Concept of keeping things in differnt modules/files
Concept of wrapping things into a single unit
Which concept allows you to reuse the written code?
Encapsulation
Abstraction
Inheritance
Polymorphism
vWhich of the following explains Polymorphism?
int func(int, int); float func1(float, float);
int func(int); int func(int);
int func(float); float func(int, int, char);
int func(); int new_func();
C++ is ______________
procedural programming language
object oriented programming language
functional programming language
both procedural and object oriented programming language
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;}
}
Abstraction
Encapsulation
Inheritance
Polymorphism
Which of the following class allows to declare only one object of it?
Abstract class
Virtual class
singleton class
Friend class
Which of the following is correct?
Base class pointer object cannot point to a derived class object
Derived class pointer object cannot point to a base class object
A derived class cannot have pointer objects
A base class cannot have pointer objects
What is the other name used for functions inside a class?
Member variables
Member functions
Class functions
Class variables
How many types of polymorphism are there in C++?
1
2
3
4
Which of the following is an abstract data type?
int
float
class
string
Which of the following explains the overloading of functions?
Virtual polymorphism
Transient polymorphism
Ad-hoc polymorphism
Pseudo polymorphism
Which of the following approach is used by C++?
Top-down
bottom-up
left-right
right-left
Which of the following is correct?
C++ allows static type checking
C++ allows dynamic type checking.
C++ allows static member function to be of type const.
C++ allows both static and dynamic type checking
Which keyword is used to declare the friend function?
friend
firend
classfriend
myfriend
What is the syntax of friend function?
friend class1 Class2;
friend class;
friend class
friend class()
Pick out the correct statement.
A friend function may be a member of another class
A friend function may not be a member of another class
A friend function may or may not be a member of another class
none of the above
Where does keyword ‘friend’ should be placed?
function declaration
function definition
main function
block function
A friend class can access ____________________ members of other class in which it is declared as friend.
private
protected
public
both private and protected
Which feature of OOP indicates code reusability?
Abstraction
Polymorphism
Encapsulation
Inheritance
Which of the following is associated with objects?
State
Behaviour
Identity
All of the above
The feature in object-oriented programming that allows the same operation to be carried out differently, depending on the object, is:
Inheritance
Polymorphism
Overfunctioning
Overriding
Which among the following feature is not in the general definition of OOPS?
Modularity
Efficient Code
Code reusability
Duplicate or Redundant Data
How many types of polymorphism in the C++ programming language?
Three types of polymorphism
Two types of polymorphism
Five types of polymorphism
Four types of polymorphism
Consider the following two statements: (a)A publicly derived class is a subtype of its base class. (b)Inheritance provides for code reuse.
Both the statements (a) and (b) are correct.
Neither of the statements (a) and (b) are correct
Statement (a) is correct and (b) is incorrect
Statement (a) is incorrect and (b) is correct
Which of the following OOP concept binds the code and data together and keeps them secure from the outside world?
Polymorphism
Inheritance
Abstraction
Encapsulation
Which of the following feature is also known as run-time binding or late binding?
Dynamic typing
Dynamic loading
Dynamic binding
Data hiding
The combination of abstraction of the data and code is viewed in (a) .
The name of the default access specifier for the member functions or data members in the C++ programming language is (a) .
What is an exception in C++?
A syntax error
An unexpected problem that occurs during the execution of a program
A warning from the compiler
A type of function call
When do exceptions occur in C++?
At compile-time
During runtime
During memory allocation
At link-time
Which keyword is used to handle exceptions in C++?
try
catch
throw
All of the above
What is the purpose of the try block in C++?
To execute code and handle exceptions
To contain code that might throw an exception
To throw an exception
To catch exceptions from other blocks
What happens if an exception is thrown in C++ but not caught?
The program will terminate abruptly
The program will continue executing
The exception will be ignored
The program will pause and wait for user input
What is the throw keyword used for in C++?
To declare an exception
To signal that an exception has occurred
To handle an exception
To define a new exception type
What is the purpose of the catch block in C++?
To declare an exception
To handle an exception thrown from a try block
To return a value from a function
To prevent exceptions from occurring
Which of the following is an example of a synchronous exception?
Disk failure
Division by zero
Power failure
Keyboard interrupt
What is an asynchronous exception in C++?
An exception that occurs due to user input errors
An exception that occurs due to external factors beyond the program's control
An exception that can be handled at compile-time
An exception related to memory allocation
Which of the following best describes the catch block?
It always executes after the try block, regardless of exceptions
It is used to define how to handle specific exceptions thrown by the try block
It must be placed before the try block
It can only catch one type of exception
What are the benefits of exception handling in C++?
It improves program readability and maintainability by separating normal code from error-handling code
It guarantees the program will never crash
It speeds up program execution
It automatically fixes all runtime errors
How do you catch all exceptions in a catch block?
catch(int e)
catch(...)
catch(exception)
catch(all)
Which of the following is a limitation of exception handling in C++?
It can lead to resource leaks if not handled properly
It makes the code easier to read
It automatically prevents memory leaks
It is required for all programs
Which of the following examples demonstrates throwing an exception for division by zero?
throw 0;
throw "Division by zero";
throw exception;
throw divide_by_zero;
What is the purpose of a try-catch block in exception handling?
To prevent exceptions from being thrown
To transfer control from the point where an exception occurred to a handler that can manage the error
To stop program execution
To declare variables in a protected scope
Which of the following is true about exception handling in C++?
It only works with built-in exceptions
Both basic types and objects can be thrown as exceptions
Only objects can be thrown as exceptions
Exceptions must always be caught within the same function where they are thrown
What is the primary purpose of exception handling in C++?
To increase program performance
To handle runtime errors without crashing the program
To fix all syntax errors in the code
To manage memory allocation
What happens if an exception is thrown in a try block but not caught?
The program continues to run normally
The program terminates with an error
The exception is automatically ignored
The program enters an infinite loop
Which of the following is a valid catch block to handle an integer exception?
catch(int e)
catch(exception e)
catch(...)
catch(int)
What is one of the limitations of using exception handling?
Exceptions always slow down the program
Exceptions may break the structure or flow of the code due to invisible exit points
Exceptions are handled at compile-time
Exception handling can only be used with pointers
(a) is a process of converting system error messages in to user friendly messages.
An (a) is an event, which occurs during the execution of a program, that disrupt the normal flow of a program's instructions.
Exceptions are _________anomalies that a program encounters during execution.
compile time
run time
The Keywords for handling the Exception in C++ are
Try
catch
throw
remove
___________ block consists of the code that may generate exception.
Try
Catch
_________keyword is used to throw an exception encountered inside try block.
throw
catch
try
Raising of an exception is done by _______expression.
throw
catch
___________block detects and throws an exception
Try
catch
_____________block catches and handles the exception.
try
catch
__________block specifies the action to be taken when an exception occur.
try
catch
A function can have _____ inside the parenthesis
loops
Arguments/Parameters
Braces
Types
A function that returns a whole number starts with the word
int
void
string
{ }
Fill in the blank to have this function work properly
_____ function ( ) {
int a = 4;
int b = 5;
cout<<a*b;
}
string
int
void
variable
Fill in the blank to have this function work properly
_____ function ( ) {
string greeting = "Welcome to my game";
return greeting;
}
string
void
int
variable
Select all of the types you may have for a function
string
bool
void
variable
int
What is the meaning of modular programming
data type of the value that function returns to the part of the program that called it
breaking a program up into smaller, manageable functions or modules
one single program without breaking it into module
none of the above
It refers to the part of function heading that specifies an input for the function to perform its task
global variable
function arguments or function parameters
function statements
function heading
This method copies the actual value of an argument into the formal parameter of the function.
call by value
call by pointer
call by reference
It is a type of variable that can only be used within a function
local variable
global variable
parameter variables
constant variable
True or False. We can call functions inside of other functions.
True
False
If an argument from the parameter list of a function is defined constant then _______________
It can be modified inside the function
It cannot be modified inside the function
Error occurs
Segmentation fault
What will be the output of the following C++ code?
10
0
Syntax error
Segmentation fault
Which variable retains its value in between function calls?
static
register
extern
auto
global
How many values can a C Function return at a time?
only one value
maximum of 2 values
maximum of 3 values
maximum 8 values
What is the main purpose of functions in C++?
To execute loops faster
To reduce code redundancy and improve reusability
To replace the main() function
To speed up compilation
Which keyword defines a function that does not return a value?
int
return
void
float
How do you call a function in C++?
functionName;
functionName()
call functionName();
define functionName();
What is required in a function declaration?
Function name and parameters
Only the function body
Function name, return type, and parameters (if any)
Only the return type
What will happen if a function is declared but not called?
It will cause a compilation error
It will execute automatically
Nothing will happen
The program will crash
What is the default return type of a function in C++ if not specified?
void
int
float
char
Which of the following statements about function parameters is true?
A function can only have one parameter
Parameters are mandatory in all functions
Parameters act as variables inside the function
Parameters must be initialized in the function declaration
What is the correct way to define a function with two integer parameters?
void function(int a, int b);
function(int a, int b) {}
int function(int a, int b) { return a + b; }
void function() { int a, b; }
What is "pass by reference" in functions?
Passing values by copying them
Allowing a function to modify the original variable
Passing only integer values
Calling a function multiple times
Which function type returns a value?
void function
Function with no parameters
Function with a return type
Function with default parameters
Which of the following is an example of function overloading?
Two functions with the same name but different parameters
A function calling another function
A function using multiple loops
A function with no return type
Which statement about the return keyword is correct?
It must always be used in functions
It ends function execution and sends a value back
It only works with int functions
It can only be used once per function
Which function prototype is correct?
int sum(int x, y);
void sum(int, int);
function sum(int a, int b);
int sum(int a) return a + 1;
What happens if a function with void return type has a return statement with a value?
Compilation error
Function returns the value
Undefined behavior
The value is ignored
What is required to pass an array as a function parameter?
Specify the array size in the function definition
Use the return keyword
Declare the array inside the function
Pass the array by reference or pointer
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);
1 1
1 0
0 1
0 0
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);
9
27
81
243
What is the output of the following code: int check(int num) { if (num > 10) return 1; return 0; } cout << check(15) << " " << check(5);
0 0
1 1
1 0
0 1
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);
10 9 11
13 11 14
20 18 15
12 10 13
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));
8
16
64
256
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);
5
7
10
12
What is the output of the following code: void update(int &x) { x += 10; } int num = 5; update(num); cout << num;
5
10
15
Compilation error
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!
Which of the following is the default return value of functions in C++?
What is the purpose of the 'void' keyword in C++ functions?
To indicate that the function does not return a value
To specify the return type as an integer
To define a function that takes no arguments
To declare a function as private
From which function the execution of a C++ program starts?
init() function
start() function
main() function
begin() function
Which of the following is important in a function?
Return Type
Function Name
parameter list
all of these
When do we define the default values for a function?
In the function declaration
