Sequences

1

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

A. Array
B. Vector
C. Dequeue
D. List

2

How the list containers are implemented?

A. Using Double linked list
B. Using Single linked list
C. Both a & b
D. None of the mentioned

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 << ' ' << *it;
26.
        cout << '\n';
27.
        return 0;
28.
    }
A. 2.72 12.15 72.25
B. 12.15 73.0 12.77
C. 73.35
D. None of the mentioned

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 << ' ' << p[i];
14.
        for (i = 0; i < 5; i++)
15.
            myvector.get_allocator().destroy(&p[i]);
16.
        myvector.get_allocator().deallocate(p, 5);
17.
        return 0;
18
    }
A. 1 2 3 4 5
B. 0 1 2 3 4
C. 1 2 3 4
D. 5 4 3 2 1

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 << ' ' << *it;
19.
        cout << '\n';
20.
        return 0;
21.
    }
A. 110
B. 220
C. Both a & b
D. None of the mentioned