91. What is meant by template specialization?
92. What will be the output of the following C++ code?
#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>
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();
}
}93. Which can be used to create a random number without duplication?
94. Which handler is used to handle all types of exception?
95. What will be the output of the following C++ code?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue<int> mypq;
mypq.push(30);
mypq.push(100);
mypq.push(25);
mypq.push(40);
while (!mypq.empty())
{
cout << " " << mypq.top();
mypq.pop();
}
cout << endl;
return 0;
}
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue<int> mypq;
mypq.push(30);
mypq.push(100);
mypq.push(25);
mypq.push(40);
while (!mypq.empty())
{
cout << " " << mypq.top();
mypq.pop();
}
cout << endl;
return 0;
}96. Which of the following is true about exception handling in C++?
i. There is a standard exception class in C++ similar to Exception class in Java.
ii. All exceptions are unchecked in C++, i.e., the compiler does not checks if the exceptions are caught or not.
iii. In C++, a function can specify the list of exceptions that it can throw using comma separated list like following.
void fun(int a, char b) throw (Exception1, Exception2, ..)
i. There is a standard exception class in C++ similar to Exception class in Java.
ii. All exceptions are unchecked in C++, i.e., the compiler does not checks if the exceptions are caught or not.
iii. In C++, a function can specify the list of exceptions that it can throw using comma separated list like following.
void fun(int a, char b) throw (Exception1, Exception2, ..)
97. What will be the output of the following C++ code?
#include <iostream>
#include <iterator>
#include <list>
using namespace std;
int main ()
{
list<int> firstlist, secondlist;
for (int i = 1; i <= 2; i++)
{
firstlist.push_back(i);
secondlist.push_back(i * 10);
}
list<int> :: iterator it;
it = firstlist.begin();
advance (it, 3);
copy (secondlist.begin(), secondlist.end(), inserter(firstlist, it));
for ( it = firstlist.begin(); it != firstlist.end(); ++it )
cout << *it << " ";
return 0;
}
#include <iostream>
#include <iterator>
#include <list>
using namespace std;
int main ()
{
list<int> firstlist, secondlist;
for (int i = 1; i <= 2; i++)
{
firstlist.push_back(i);
secondlist.push_back(i * 10);
}
list<int> :: iterator it;
it = firstlist.begin();
advance (it, 3);
copy (secondlist.begin(), secondlist.end(), inserter(firstlist, it));
for ( it = firstlist.begin(); it != firstlist.end(); ++it )
cout << *it << " ";
return 0;
}98. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template<typename type>
type Max(type Var1, type Var2)
{
return Var1 > Var2 ? Var1:Var2;
}
int main()
{
int p;
p = Max(100, 200);
cout << p << endl;
return 0;
}
#include <iostream>
using namespace std;
template<typename type>
type Max(type Var1, type Var2)
{
return Var1 > Var2 ? Var1:Var2;
}
int main()
{
int p;
p = Max(100, 200);
cout << p << endl;
return 0;
}99. Which operator is used for input stream?
100. How many categories are available in facets?
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 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 10
- C plus plus miscellaneous - Section 11
