0% found this document useful (0 votes)
3 views6 pages

Answers To Sample Test

The document consists of a series of multiple-choice questions related to C++ programming concepts, including Object-Oriented Programming, data structures, and algorithms. It also includes a passage about a disaster relief camp's food distribution system using C++ code, which manages elderly and non-elderly citizens using a queue and stack. The questions test the reader's understanding of the code and related programming principles.

Uploaded by

Pratham Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Answers To Sample Test

The document consists of a series of multiple-choice questions related to C++ programming concepts, including Object-Oriented Programming, data structures, and algorithms. It also includes a passage about a disaster relief camp's food distribution system using C++ code, which manages elderly and non-elderly citizens using a queue and stack. The questions test the reader's understanding of the code and related programming principles.

Uploaded by

Pratham Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2025-05-25

25/25p

1.
Which of the following is not a feature of Object-Oriented Programming?
Polymorphism
Abstraction
Sequential
Encapsulation

At least 1 correct, and max 0 wrong 1/1p

2.
What distinguishes object-oriented programming from procedural programming?

Use of header files


Emphasis on functions

Use of classes and objects

Dependency on compilers

At least 1 correct, and max 0 wrong 1/1p

3.
What does the cin object in C++ represent?
Input stream
Output Stream
Namespace
Class

At least 1 correct, and max 0 wrong 1/1p


4.
Which keyword is used to define a namespace in C++?
using
namespace
public
class

At least 1 correct, and max 0 wrong 1/1p

5.
Which of the following is true about constructors in C++?

They can return a value


They are invoked manually
They are automatically called when an object is created
They must always be virtual

At least 1 correct, and max 0 wrong 1/1p

6.
Which of the following is a non-linear data structure?
Stack
Array
Queue
Tree

At least 1 correct, and max 0 wrong 1/1p

7.
The worst-case time complexity of linear search is:
O(log n)
O(n)
O(n/2)
O(1)

At least 1 correct, and max 0 wrong 1/1p


8.
Which sorting algorithm compares and swaps adjacent elements repeatedly?
Bubble Sort
Selection Sort
Heap Sort
Quick Sort

At least 1 correct, and max 0 wrong 1/1p

9.
What is the correct way to declare a 2D array of integers in C++?

arr[3]
arr[][3]
arr[2][3]
int arr[2][3]

At least 1 correct, and max 0 wrong 1/1p

10.
What is the role of a pointer in C++?
Stores a class object
Refers to a function
Stores the address of another variable
Refers to a reference variable

At least 1 correct, and max 0 wrong 1/1p


Answer questions 11 to 15 based on the passage below -

Passage:

A disaster relief camp uses the following C++ code to manage the food distribution line. Elderly citizens are
given priority and temporarily pushed into a stack before the regular queue is served.

#include <iostream>
#include <queue>
#include <stack>
using namespace std;

struct Person {
string name;
bool isElderly;
};

queue<Person> q;
stack<Person> s;

void distribute() {
while (!q.empty()) {
Person p = q.front(); q.pop();

if (p.isElderly)
s.push(p);
else {
while (!s.empty()) {
cout << s.top().name << " (priority)\n";
s.pop();
}
cout << p.name << " (normal)\n";
}
}
while (!s.empty()) {
cout << s.top().name << " (priority-end)\n";
s.pop();
}
}

int main() {
q.push({"Ali", false});
q.push({"Dadi", true});
q.push({"Riya", false});
q.push({"Nana", true});
q.push({"Kabir", false});

distribute();
}

11.
Which data structures are used for elderly and non-elderly people respectively?
Stack for non-elderly, queue for elderly
Queue for both
Stack for elderly, queue for non-elderly
Only queue is used

At least 1 correct, and max 0 wrong 3/3p

12.
What will be the output order printed by the distribute() function?
Ali (normal), Dadi (priority), Riya (normal), Nana (priority), Kabir (normal)
Ali (normal), Dadi (priority), Riya (normal), Nana (priority), Kabir (normal), Dadi (priority-
end), Nana (priority-end)
Ali (normal), Dadi (priority), Nana (priority), Riya (normal), Kabir (normal)
Dadi (normal), Adi (priority), Riya (normal), Nana (priority), Kabir (normal)

At least 1 correct, and max 0 wrong 3/3p

13.
Suppose one more elderly person {"Dadaji", true} is added after Kabir . Where in the output will
his name appear?

Before Riya
After Kabir
After Nana but before Kabir
At the very beginning

At least 1 correct, and max 0 wrong 3/3p


14.
Which policy reflects a characteristic of Queues?
FIFO
LIFO
LILO
FILO

At least 1 correct, and max 0 wrong 3/3p

15.
If the stack used for elderly in the code is replaced with a linked list that inserts elderly members at the
beginning, what key functional change will occur in the program’s output order?
Elderly members will now be printed in the same order they arrived.
Elderly members will not be printed at all.
Elderly members will be printed in reverse order compared to stack.
There will be no change in the order of output.

At least 1 correct, and max 0 wrong 3/3p

You might also like