Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

Which of the following does not support any insertion or deletion?


  1.    Array
  2.    Vector
  3.    Dequeue
  4.    List
 Discuss Question
Answer: Option A. -> Array

Because array is not dynamic in nature, So they can’t be manipulated.


Question 2.

How the list containers are implemented?


  1.    Using Double linked list
  2.    Using Single linked list
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Using Double linked list

List containers are implemented as doubly-linked lists. Doubly linked lists can store each of 

the elements they contain in different and unrelated storage locations.


Question 3.


What is the output of this program?


1.
#include
2.
#include
3.
#include
4.
using namespace std;
5.
bool same_integral_part (double first, double second)
6.
{
7.
return ( int(first) == int(second) );
8.
}
9.
struct is_near
10.
{
11.
bool operator() (double first, double second)
12.
{
13.
return (fabs(first - second) < 5.0);
14.
}
15.
};
16.
int main ()
17.
{
18.
double mydoubles[] = { 12.15, 2.72, 73.0, 12.77, 3.14, 12.77, 73.35, 72.25, 15.3, 72.25 };
19.
list mylist (mydoubles, mydoubles + 10);
20.
mylist.sort();
21.
mylist.unique();
22.
mylist.unique (same_integral_part);
23.
mylist.unique (is_near());
24.
for (list :: iterator it = mylist.begin(); it != mylist.end(); ++it)
25.
cout
  1.    2.72 12.15 72.25
  2.    12.15 73.0 12.77
  3.    73.35
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> 2.72 12.15 72.25

In this program, We are eliminating the values by using the unique operation in the list.
Output:
$ g++ seq4.cpp
$ a.out
2.72 12.15 72.25


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector;
7.
int * p;
8.
unsigned int i;
9.
p = myvector.get_allocator().allocate(5);
10.
for (i = 0; i < 5; i++)
11.
myvector.get_allocator().construct(&p[i], i);
12.
for (i = 0; i < 5; i++)
13.
cout
  1.    1 2 3 4 5
  2.    0 1 2 3 4
  3.    1 2 3 4
  4.    5 4 3 2 1
 Discuss Question
Answer: Option B. -> 0 1 2 3 4

In this program, We allocated the values to the vector by using get allocater and then we are destroying it.
Output:
$ g++ seq3.cpp
$ a.out
0 1 2 3 4


Question 5.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
unsigned int i;
7.
deque mydeque;
8.
mydeque.push_back (100);
9.
mydeque.push_back (200);
10.
mydeque.push_back (300);
11.
for(deque :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
12.
{
13.
}
14.
mydeque.clear();
15.
mydeque.push_back (110);
16.
mydeque.push_back (220);
17.
for(deque :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
18.
cout
  1.    110
  2.    220
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Both a & b

In this program, We cleared the old values presented in the dequeue with the new values.
Output:
$ g++ seq2.cpp
$ a.out
110 220


Question 6.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
unsigned int i;
7.
deque a (3,100);
8.
deque b (5,200);
9.
a.swap(b);
10.
cout
  1.    a contains: 200 200 200 200 200b contains: 100 100 100
  2.    a contains: 100 100 100 100 100b contains: 200 200 200
  3.    a contains: 200 200 200 200 200b contains: 200 200 200
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> a contains: 200 200 200 200 200b contains: 100 100 100

In this program, We swapped the values of both dequeues and printing the dequeues.
Output:
$ g++ seq1.cpp
$ a.out
a contains: 200 200 200 200 200b contains: 100 100 100


Question 7.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
deque mydeque (5);
7.
deque::reverse_iterator rit = mydeque.rbegin();
8.
int i = 0;
9.
for (rit = mydeque.rbegin(); rit!= mydeque.rend(); ++rit)
10.
*rit = ++i;
11.
for (deque :: iterator it = mydeque.begin();
12.
it != mydeque.end(); ++it)
13.
cout
  1.    12345
  2.    1234
  3.    54321
  4.    43210
 Discuss Question
Answer: Option C. -> 54321

In this program, We used the operation of rbegin and rend on dequeue and produced the result.
Output:
$ g++ seq.cpp
$ a.out
5 4 3 2 1


Question 8.

Which of the following class template are based on arrays?


  1.    vector
  2.    list
  3.    dequeue
  4.    Both a & c
 Discuss Question
Answer: Option D. -> Both a & c

Class template vector and class template dequeue both are based on arrays.


Question 9.

How many items are there in sequence container?


  1.    2
  2.    3
  3.    4
  4.    5
 Discuss Question
Answer: Option D. -> 5

There are five items in sequence container. They are array, vector, list, forward_list and dequeue.


Question 10.

Which of the following will return the new element at the end of container?


  1.    front
  2.    back
  3.    push_back
  4.    pop_back
 Discuss Question
Answer: Option B. -> back

None.


Latest Videos

Latest Test Papers