CPP C++ Certified Professional Programmer

Loading demo links...

Showing 10–12 of 15 questions

Question 10 (Volume A)

What will happen when you attempt to compile and run the code below, assuming you enter the following sequence: 1 2 3?

#include

using namespace std;

int main ()

{ int a,b,c;

cin>>a>>b>>c; cout<<><><>

Program will output:

Select an option, then click Submit answer.

  • 123

  • 1 2 3

  • 321

  • compilation error

  • the result is unspecified

Question 11 (Volume B)

What happens when you attempt to compile and run the following code?

#include #include using namespace std; class A

{ int a,b; public:

A(const A & c) { a = c.a; }

A():a(0),b(0){}

void setA(int a) {this?>a = a;} void setB(int b) {this?>b = b;} int getA() {return a;} int getB() {return b;}

};

int main ()

{

vector v;

A a;

a.setA(10); a.setB(11);

v.push_back(a);

cout<<>

Select an option, then click Submit answer.

  • program outputs 10 11

  • the result is unpredictable

  • program outputs 10 0

  • program outputs 11 0

  • compilation error

Question 12 (Volume B)

What happens when you attempt to compile and run the following code?

#include

#include

#include

#include #include using namespace std; int main() {

int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 }; vector v(t, t + 10); map m;

for (vector::iterator i = v.begin(); i != v.end(); i++) { stringstream s;s << *i << *i;

m.insert(pair(*i, s.str()));

}

pair<>::iterator, map::iterator> range; range = m.equal_range(6);

for (map::iterator i = range.first; i != range.second; i++) { cout << i?>first << " ";

} return 0; }

Select an option, then click Submit answer.

  • program outputs: 6

  • program outputs: 5 7

  • program outputs: 6 7

  • program outputs: 1 5

  • program outputs: 6 5