Welcome to the Class Hierarchies,Library and Containers MCQs Page
Dive deep into the fascinating world of Class Hierarchies,Library and Containers with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Class Hierarchies,Library and Containers, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Class Hierarchies,Library and Containers, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.
Check out the MCQs below to embark on an enriching journey through Class Hierarchies,Library and Containers. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.
Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Class Hierarchies,Library and Containers. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!
Class Hierarchies,Library and Containers MCQs | Page 8 of 15
Explore more Topics under Object Oriented Programming Using C++
#include <iostream>
#include <vector>
using namespace std;
class Component
{
public:
virtual void traverse() = 0;
};
class Leaf: public Component
{
int value;
public:
Leaf(int val)
{
value = val;
}
void traverse()
{
cout << value << ' ';
}
};
class Composite: public Component
{
vector < Component * > children;
public:
void add(Component *ele)
{
children.push_back(ele);
}
void traverse()
{
for (int i = 0; i < children.size(); i++)
children[i]->traverse();
}
};
int main()
{
Composite containers[4];
for (int i = 0; i < 4; i++)
for (int j = 0; j < 3; j++)
containers[i].add(new Leaf(i *3+j));
for (int k = 1; k < 4; k++)
containers[0].add(&(containers[k]));
for (int p = 0; p < 4; p++)
{
containers[p].traverse();
}
}
#include <iostream>
#include <vector>
#include <iterator>
#include <stddef.h>
using namespace std;
template<class myType>
class SimpleContainer
{
public:
SimpleContainer(size_t xDim, size_t yDim, myType const& defaultValue)
: objectData(xDim * yDim, defaultValue)
, xSize(xDim)
, ySize(yDim)
{
}
myType& operator()(size_t x, size_t y)
{
return objectData[y * xSize + x];
}
myType const& operator()(size_t x, size_t y) const
{
return objectData[y * xSize + x];
}
int getSize()
{
return objectData.size();
}
void inputEntireVector(vector<myType> inputVector)
{
objectData.swap(inputVector);
}
void printContainer(ostream& stream)
{
copy(objectData.begin(), objectData.end(),
ostream_iterator<myType>(stream, ""/*No Space*/));
}
private:
vector<myType> objectData;
size_t xSize;
size_t ySize;
};
template<class myType>
inline ostream& operator<<(ostream& stream, SimpleContainer<myType>& object)
{
object.printContainer(stream);
return stream;
}
void sampleContainerInterfacing();
int main()
{
sampleContainerInterfacing();
return 0;
}
void sampleContainerInterfacing()
{
static int const ConsoleWidth = 80;
static int const ConsoleHeight = 25;
size_t width = ConsoleWidth;
size_t height = ConsoleHeight;
SimpleContainer<int> mySimpleContainer(width, height, 0);
cout << mySimpleContainer.getSize() << endl;
mySimpleContainer(0, 0) = 5;
}
Suggested Topics
Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!