91. Which function is used to construct heap from given sequence of numbers?
92. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class BaseClass
{
protected:
int i;
public:
BaseClass(int x)
{
i = x;
}
~BaseClass()
{
}
};
class DerivedClass: public BaseClass
{
int j;
public:
DerivedClass(int x, int y): BaseClass(y)
{
j = x;
}
~DerivedClass()
{
}
void show()
{
cout << i << " " << j << endl;
}
};
int main()
{
DerivedClass ob(3, 4);
ob.show();
return 0;
}
#include <iostream>
using namespace std;
class BaseClass
{
protected:
int i;
public:
BaseClass(int x)
{
i = x;
}
~BaseClass()
{
}
};
class DerivedClass: public BaseClass
{
int j;
public:
DerivedClass(int x, int y): BaseClass(y)
{
j = x;
}
~DerivedClass()
{
}
void show()
{
cout << i << " " << j << endl;
}
};
int main()
{
DerivedClass ob(3, 4);
ob.show();
return 0;
}93. What will be the output of the following C++ code?
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> mystack;
mystack.push(10);
mystack.push(20);
mystack.top() -= 5;
cout << mystack.top() << endl;
return 0;
}
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> mystack;
mystack.push(10);
mystack.push(20);
mystack.top() -= 5;
cout << mystack.top() << endl;
return 0;
}94. What will be the output of the following C++ code?
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main ()
{
int numbers[] = {1, 2, 3};
int remainders[5];
transform ( numbers, numbers + 5, remainders,
bind2nd(modulus<int>(), 2) );
for (int i = 0; i < 5; i++)
cout << (remainders[i] == 1 ? "odd" : "even") << "\n";
return 0;
}
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main ()
{
int numbers[] = {1, 2, 3};
int remainders[5];
transform ( numbers, numbers + 5, remainders,
bind2nd(modulus<int>(), 2) );
for (int i = 0; i < 5; i++)
cout << (remainders[i] == 1 ? "odd" : "even") << "\n";
return 0;
}95. What will be the output of the following C++ code?
#include <new>
#include<cstdlib>
#include <iostream>
using namespace std;
class X;
struct Node
{
X* data;
bool filled;
Node() : filled(false) { }
};
class X
{
static Node buffer[];
public:
int number;
enum { size = 3};
void* operator new(size_t sz) throw (const char*)
{
void* p = malloc(sz);
if (sz == 0)
throw "Error: malloc() failed";
cout << "X :: operator new(size_t)" << endl;
return p;
}
void *operator new(size_t sz, int location) throw (const char*)
{
cout << "X :: operator new(size_t, " << location < ")" << endl;
void* p = 0;
if (location < 0 || location >= size || buffer[location].filled == true)
{
throw "Error: buffer location occupied";
}
else
{
p = malloc(sizeof(X));
if (p == 0)
throw "Error: Creating X object failed";
buffer[location].filled = true;
buffer[location].data = (X*) p;
}
return p;
}
static void printbuffer()
{
for (int i = 0; i < size; i++)
{
cout << buffer[i].data->number << endl;
}
}
};
Node X::buffer[size];
int main()
{
try
{
X* ptr1 = new X;
X* ptr2 = new(0) X;
X* ptr3 = new(1) X;
X* ptr4 = new(2) X;
ptr2->number = 10000;
ptr3->number = 10001;
ptr4->number = 10002;
X :: printbuffer();
X* ptr5 = new(0) X;
}
catch (const char* message)
{
cout << message << endl;
}
}
#include <new>
#include<cstdlib>
#include <iostream>
using namespace std;
class X;
struct Node
{
X* data;
bool filled;
Node() : filled(false) { }
};
class X
{
static Node buffer[];
public:
int number;
enum { size = 3};
void* operator new(size_t sz) throw (const char*)
{
void* p = malloc(sz);
if (sz == 0)
throw "Error: malloc() failed";
cout << "X :: operator new(size_t)" << endl;
return p;
}
void *operator new(size_t sz, int location) throw (const char*)
{
cout << "X :: operator new(size_t, " << location < ")" << endl;
void* p = 0;
if (location < 0 || location >= size || buffer[location].filled == true)
{
throw "Error: buffer location occupied";
}
else
{
p = malloc(sizeof(X));
if (p == 0)
throw "Error: Creating X object failed";
buffer[location].filled = true;
buffer[location].data = (X*) p;
}
return p;
}
static void printbuffer()
{
for (int i = 0; i < size; i++)
{
cout << buffer[i].data->number << endl;
}
}
};
Node X::buffer[size];
int main()
{
try
{
X* ptr1 = new X;
X* ptr2 = new(0) X;
X* ptr3 = new(1) X;
X* ptr4 = new(2) X;
ptr2->number = 10000;
ptr3->number = 10001;
ptr4->number = 10002;
X :: printbuffer();
X* ptr5 = new(0) X;
}
catch (const char* message)
{
cout << message << endl;
}
}96. How many variants of tie() function is there?
97. What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 5.0);
cout<<arg(cn)<<endl;
return 0;
}
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 5.0);
cout<<arg(cn)<<endl;
return 0;
}98. 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(4, '1', "Hello");
cout<<get<0>(tp)<<endl;
cout<<get<1>(tp)<<endl;
cout<<get<2>(tp)<<endl;
return 0;
}
#include <iostream>
#include <string>
#include <tuple>
using namespace std;
int main()
{
tuple <int, char, string> tp;
tp = make_tuple(4, '1', "Hello");
cout<<get<0>(tp)<<endl;
cout<<get<1>(tp)<<endl;
cout<<get<2>(tp)<<endl;
return 0;
}99. Pick out the correct option.
100. What is meant by garbage collection?
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 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 9
- C plus plus miscellaneous - Section 10
- C plus plus miscellaneous - Section 11
