91. Members of which access specifiers are not inherited?
92. What is Pseudo-random number engines?
93. What will be the output of the following C++ code?
#include <iostream>
#include <set>
using namespace std;
int main ()
{
multiset<int> mymultiset;
for (int i = 0; i < 5; i++) mymultiset.insert(i);
multiset<int> :: key_compare mycomp = mymultiset.key_comp();
int highest = *mymultiset.rbegin();
multiset<int> :: iterator it = mymultiset.begin();
do
{
cout << ' ' << *it;
} while (mycomp(*it++, highest));
return 0;
}
#include <iostream>
#include <set>
using namespace std;
int main ()
{
multiset<int> mymultiset;
for (int i = 0; i < 5; i++) mymultiset.insert(i);
multiset<int> :: key_compare mycomp = mymultiset.key_comp();
int highest = *mymultiset.rbegin();
multiset<int> :: iterator it = mymultiset.begin();
do
{
cout << ' ' << *it;
} while (mycomp(*it++, highest));
return 0;
}94. What type can be used to replace templates from this function?
template<class T, class U>
T func(T a, T b, U c)
{
if(c == '+' || c){
return a+b;
}
else if(c == '-' || !c){
return a-b;
}
}
template<class T, class U>
T func(T a, T b, U c)
{
if(c == '+' || c){
return a+b;
}
else if(c == '-' || !c){
return a-b;
}
}95. What is the importance of mutable keyword?
96. What will be the output of the following C++ code?
#include <iostream>
#include<string.h>
using namespace std;
int main()
{
try
{
char *p;
strcpy(p, "How r u");
}
catch(const exception& er)
{
}
}
#include <iostream>
#include<string.h>
using namespace std;
int main()
{
try
{
char *p;
strcpy(p, "How r u");
}
catch(const exception& er)
{
}
}97. What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
cout << "max(1, 2) == " << max(1, 2) << '\n';
cout << "max('a', 'z') == " << max('a', 'z') << '\n';
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
cout << "max(1, 2) == " << max(1, 2) << '\n';
cout << "max('a', 'z') == " << max('a', 'z') << '\n';
return 0;
}98. Which is present in the basic interface of the allocator interface?
99. What will be the output of the following C++ code?
#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;
}
#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;
}100. What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <tuple>
using namespace std;
int main()
{
tuple <int, char, string> tp;
tp = make_tuple("Hello", 4, 'c');
return 0;
}
#include <iostream>
#include <string>
#include <tuple>
using namespace std;
int main()
{
tuple <int, char, string> tp;
tp = make_tuple("Hello", 4, 'c');
return 0;
}Read More Section(C plus plus miscellaneous)
Each Section contains maximum 100 MCQs question on C plus plus miscellaneous. To get more questions visit other sections.
- C plus plus miscellaneous - Section 1
- C plus plus miscellaneous - Section 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 5
- C plus plus miscellaneous - Section 6
- C plus plus miscellaneous - Section 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 10
- C plus plus miscellaneous - Section 11
