C Plus Plus Miscellaneous - Study Mode

[#911] What will be the output of the following C++ code? #include <iostream>
using namespace std
template<typename T>class clsTemplate
{
public:
T value
clsTemplate(T i)
{
this->value = i
}
void test()
{
cout << value << endl
}
}
class clsChild : public clsTemplate<char>
{
public:
clsChild(): clsTemplate<char>( 0 )
{
}
clsChild(char c): clsTemplate<char>( c )
{
}
void test2()
{
test()
}
}
int main()
{
clsTemplate <int> a( 42 )
clsChild b( 'A' )
a.test()
b.test()
return 0
}
Correct Answer

(C) 42 A

[#912] What will be the output of the following C++ code? #include <iostream>
#include <algorithm>
#include <vector>
using namespace std
bool IsOdd (int i)
{
return ((i % 2) == 1)
}
int main ()
{
vector<int> myvector
myvector.push_back(10)
myvector.push_back(25)
myvector.push_back(40)
myvector.push_back(55)
vector<int> :: iterator it = find_if (myvector.begin(),
myvector.end(), IsOdd)
cout << *it << '
'
return 0
}
Correct Answer

(B) 25

[#913] Given below classes which of the following are the possible row entries in vtable of Base class? class Base
{
public:
virtual void function1() {}
virtual void function2() {}
}
class D1: public Base
{
public:
virtual void function1() {}
}
class D2: public Base
{
public:
virtual void function2() {}
}
Correct Answer

(A) Base::function1() and Base::function2()

[#914] Which of the following is the correct syntax of declaring a complex number?
Correct Answer

(B) complex<type> variable_name

[#915] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
double a = 10, b = 5, res
char Operator = '/'
try
{
if (b == 0)
throw "Division by zero not allowed"
res = a / b
cout << a << " / " << b << " = " << res
}
catch(const char* Str)
{
cout << "
Bad Operator: " << Str
}
return 0
}
Correct Answer

(D) 10 / 5 = 2