WorksheetsChapter 1: Principles of Object Oriented Programming
Total questions: 10
Worksheet time: 5mins
Which operator in C++ is called the extraction operator and is typically used with cin to read input into a variable?
<< insertion operator for output
>> extraction operator for input
== equality operator for comparison
:: scope resolution for names
Which statement best distinguishes Object-Oriented Programming from Procedure-Oriented Programming regarding data focus and structure?
POP emphasizes data and groups it into objects
OOP emphasizes data and groups it into objects
POP emphasizes objects communicating via methods
OOP emphasizes free data moving across functions
What is data encapsulation in C++?
Showing essential features while hiding details
Binding data and methods within a single unit
Allowing data to move freely between functions
Exposing variables directly for easy access
Which statement best contrasts C and C++ regarding programming paradigms?
C supports object paradigms, C++ supports procedural paradigms
C supports procedural paradigms, C++ supports both paradigms
C supports both paradigms, C++ supports only object paradigms
C supports only object paradigms, C++ supports only procedural paradigms
In C++, which for-loop header correctly iterates an index i from 0 through 4 to print five elements?
for(i=1;i<=5;i++)
for(int i=0;i<5;i++)
for(int i=0;i<=4;i--)
for(i=0;i<=5;i++)
Which statement about the new and delete operators is correct?
new allocates stack memory for variables
delete releases memory allocated with malloc
new returns a base address to a pointer
delete initializes allocated memory to zero
Given A = 60 (0011 1100) and B = 13 (0000 1101) in C++, what is the result of the expression AB in decimal?
12
49
61
-61
Which description best fits an if-else statement?
Executes if block on true, else block on false
Executes both blocks in sequence always
Skips both blocks when condition is true
Requires two conditions evaluated sequentially
Given int a = 100; if (a < 20) { cout << "a is less than 20"; } else { cout << "a is not less than 20"; } What prints?
a is not less than 20
a is less than 20
No output is produced
Compilation error occurs
Why does sizeof usually not evaluate its operand at runtime for objects?
Because it is computed at compile time for known types
Because it always calls a memory allocator internally
Because it requires executing the object's constructor
Because it depends on current stack pointer value
