MCQs
Because array is not dynamic in nature, So they can’t be manipulated.
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.
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
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
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
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
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
In this program, We cleared the old values presented in the dequeue with the new values.
Output:
$ g++ seq2.cpp
$ a.out
110 220
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
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
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
Class template vector and class template dequeue both are based on arrays.
There are five items in sequence container. They are array, vector, list, forward_list and dequeue.
None.