CPP

CPP

Container Design has 10 Questions

How many sets of requirements are need in designing a container?

1
2
3
4
Which interface in the container is required for storage management?

Memory management
Allocater interface
Memory interface
None of the mentioned
Which is present in the basic interface of the allocator interface?

Set of typedefs
A pair of allocation functions
allocate()
All of the mentioned
Which container provides random access iterators?

vector
deque
sort
Both a & b
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 << value << ' ';
  20.         }
  21.     };
  22.     class Composite: public Component
  23.     {
  24.         vector < Component * > children;
  25.         public:
  26.         void add(Component *ele)
  27.         {
  28.             children.push_back(ele);
  29.         }
  30.         void traverse()
  31.         {
  32.             for (int i = 0; i < children.size(); i++)
  33.                 children[i]->traverse();
  34.         }
  35.     };
  36.     int main()
  37.     {
  38.         Composite containers[4];
  39.         for (int i = 0; i < 4; i++)
  40.             for (int j = 0; j < 3; j++)
  41.                 containers[i].add(new Leaf(i *3+j));
  42.             for (int k = 1; k < 4; k++)
  43.                 containers[0].add(&(containers[k]));
  44.             for (int p = 0; p < 4; p++)
  45.             {
  46.                 containers[p].traverse();
  47.             }
  48.     }

345
678
901
None of the mentioned
Which is used for manually writing lookup table?

std:map
std:lookup
std:find
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     #include 
  5.     using namespace std;
  6.     template<class myType>
  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<myType> inputVector)
  29.         {
  30.             objectData.swap(inputVector);
  31.         }
  32.         void printContainer(ostream& stream)
  33.         {
  34.             copy(objectData.begin(), objectData.end(),
  35.             ostream_iterator<myType>(stream, ""/*No Space*/));
  36.         }
  37.         private:
  38.         vector<myType> objectData;
  39.         size_t  xSize;
  40.         size_t  ySize;
  41.     };
  42.     template<class myType>
  43.     inline ostream& operator<<(ostream& stream, SimpleContainer<myType>& object)
  44.     {
  45.         object.printContainer(stream);
  46.         return stream;
  47.     }
  48.     void sampleContainerInterfacing();
  49.     int main()
  50.     {
  51.         sampleContainerInterfacing();
  52.         return 0;
  53.     }
  54.     void sampleContainerInterfacing()
  55.     {
  56.         static int const ConsoleWidth  = 80;
  57.         static int const ConsoleHeight = 25;
  58.         size_t width  = ConsoleWidth;
  59.         size_t height = ConsoleHeight;
  60.         SimpleContainer<int> mySimpleContainer(width, height, 0);
  61.         cout << mySimpleContainer.getSize() << endl;
  62.         mySimpleContainer(0, 0) = 5;
  63.     }

2000
No Space
Error
Depends on the compiler
How the member functions in the container can be accessed?

Iterator
Indirect
Both a & b
None of the mentioned
Which are the parameters for the content of the buffer?

start
finish
Both a & b
None of the mentioned
Which of the following type does the container should define?

Iterator type
Vector type
Storage type
None of the mentioned