Questions and Answers
- What is the output of this program?
#include <iostream>
#include <vector>
#include <iterator>
#include <stddef.h>
using namespace std;
template<class myType>
class Container
{
public:
Container(size_t xDim, size_t yDim, myType const& defaultValue)
: objData(xDim * yDim, defaultValue)
, xSize(xDim)
, ySize(yDim)
{
}
myType& operator()(size_t x, size_t y)
{
return objData[y * xSize + x];
}
myType const& operator()(size_t x, size_t y) const
{
return objData[y * xSize + x];
}
int getSize()
{
return objData.size();
}
void inputEntireVector(vector<myType> inputVector)
{
objData.swap(inputVector);
}
void printContainer(ostream& stream)
{
copy(objData.begin(), objData.end(),
ostream_iterator<myType>(stream, ""/*No Space*/));
}
private:
vector<myType> objData;
size_t xSize;
size_t ySize;
};
template<class myType>
inline ostream& operator<<(ostream& stream, Container<myType>& object)
{
object.printContainer(stream);
return stream;
}
void ContainerInterfacing();
int main()
{
ContainerInterfacing();
return 0;
}
void ContainerInterfacing()
{
static int const ConsoleWidth = 95;
static int const ConsoleHeight = 30;
size_t width = ConsoleWidth;
size_t height = ConsoleHeight;
Container<int> mySimpleContainer(width, height, 0);
cout << mySimpleContainer.getSize() << endl;
mySimpleContainer(0, 0) = 4;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We formed a simple container and got the size of it and printing it.
- Which of the following type does the container should define?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Every container must define an iterator type. Iterators allow algorithms to iterate over the container’s contents.
- How can the member functions in the container be accessed?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
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.
- Which is used for manually writing lookup table?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
std:map
- Which are the parameters for the content of the buffer?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The contents of the buffer are initialized using the values from the iterator range supplied to the constructor by the start and finish parameters.