MCQs
The contents of the buffer are initialized using the values from the iterator range supplied to
the constructor by the start and finish parameters.
Every container must define an iterator type. Iterators allow algorithms to iterate over the
container's contents.
The container manages the storage space for its elements and provides member functions
to access them, either directly or through iterators which reference objects with similar
properties to pointers.
None.
What is the output of this program?
1.
#include
2.
#include
3.
#include
4.
#include
5.
using namespace std;
6.
template
7.
class SimpleContainer
8.
{
9.
public:
10.
SimpleContainer(size_t xDim, size_t yDim, myType const& defaultValue)
11.
: objectData(xDim * yDim, defaultValue)
12.
, xSize(xDim)
13.
, ySize(yDim)
14.
{
15.
}
16.
myType& operator()(size_t x, size_t y)
17.
{
18.
return objectData[y * xSize + x];
19.
}
20.
myType const& operator()(size_t x, size_t y) const
21.
{
22.
return objectData[y * xSize + x];
23.
}
24.
int getSize()
25.
{
26.
return objectData.size();
27.
}
28.
void inputEntireVector(vector inputVector)
29.
{
30.
objectData.swap(inputVector);
31.
}
32.
void printContainer(ostream& stream)
33.
{
34.
copy(objectData.begin(),
objectData.end(),
35.
ostream_iterator(stream, ""/*No Space*/));
36.
}
37.
private:
38.
vector objectData;
39.
size_t xSize;
40.
size_t ySize;
41.
};
42.
template
43.
inline ostream& operator
In this program, We formed a simple container and got the size of it and printing it.
Output:
$ g++ cont1.cpp
$ a.out
200
None.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
class Component
5.
{
6.
public:
7.
virtual void traverse() = 0;
8.
};
9.
class Leaf: public Component
10.
{
11.
int value;
12.
public:
13.
Leaf(int val)
14.
{
15.
value = val;
16.
}
17.
void traverse()
18.
{
19.
cout traverse();
34.
}
35.
};
36.
int main()
37.
{
38.
Composite containers[4];
39.
for (int i = 0; i 40.
for (int j = 0; j 41.
containers[i].add(new Leaf(i *3+j));
42.
for (int k = 1; k 43.
containers[0].add(&(containers[k]));
44.
for (int p = 0; p 45.
{
46.
containers[p].traverse();
47.
}
48.
}
In this program, We are choosing and printing the numbers based on the certain limit and this
is a composite design pattern.
Output:
$ g++ cont.cpp
$ a.out
0 1 2 3 4 5 6 7 8 9 10 11
3 4 5
6 7 8
9 10 11
There are three sets of requirements. They are container interface requirements, Allocator
interface requirements and iterator requirements.
None.
The basic interface of an allocator class consists of a set of typedefs, a pair of allocation functions,
allocate() and deallocate() and a pair of construction/destruction members, construct() and destroy().