Sail E0 Webinar
Question


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
Options:
A .  2000
B .  No Space
C .  Error
D .  Depends on the compiler
Answer: Option D

In this program, We formed a simple container and got the size of it and printing it.
Output:
$ g++ cont1.cpp
$ a.out
200



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers