C Plus Plus Miscellaneous - Study Mode

[#661] What will be the output of the following C++ code? #include <iostream>
#include <iomanip>
using namespace std

void showDate(int m, int d, int y)
{
cout << setfill('0')

cout << setw(2) << m << '/'
<< setw(2) << d << '/'
<< setw(4) << y << endl

}
int main()
{
showDate(1, 1, 2013)

return 0

}
Correct Answer

(C) 01/01/2013

[#662] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <cstdlib>
using namespace std

template<class T, class U = char>
class A
{
T a

U b

public:
A(T a_val, char b_val = '$'){
this->a = a_val

this->b = b_val

}
void print(){
cout<<a<<' '<<b<<endl

}
}

int main(int argc, char const *argv[])
{
A <int, int> a1(5,10)

A <int> a2(5)

A <float> a3(10.0)

a1.print()

a2.print()

a3.print()

return 0

}
Correct Answer

(A) 5 10 5 $ 10 $

[#663] What will be the output of the following C++ code? #include <iostream>
using namespace std

void Division(const double a, const double b)

int main()
{
double op1=0, op2=10

try
{
Division(op1, op2)

}
catch (const char* Str)
{
cout << "
Bad Operator: " << Str

}
return 0

}
void Division(const double a, const double b)
{
double res

if (b == 0)
throw "Division by zero not allowed"

res = a / b

cout << res

}
Correct Answer

(A) 0

[#664] What will be the output of the following C++ code? #include <iostream>
#include <functional>
#include <numeric>
using namespace std

int myaccumulator (int x, int y)
{
return x - y

}
int myproduct (int x, int y)
{
return x + y

}
int main ()
{
int a = 100

int series1[] = {10, 20, 30}

int series2[] = {1, 2, 3}

cout << inner_product(series1, series1 + 3, series2, a ,myaccumulator,
myproduct)

cout << endl

return 0

}
Correct Answer

(B) 34

[#665] What will be the output of the following C++ code? #include <iostream>
#include <vector>
#include <algorithm>
using namespace std

int main(int argc, char const *argv[])
{
vector <int> v = {1,5,23,90,15,35}

make_heap(v.begin(),v.end())

v.push_back(110)

push_heap(v.begin(), v.end())

pop_heap(v.begin(), v.end())

v.pop_back()

cout<<v.front()

}
Correct Answer

(A) 90