Pass the C++ Institute C++ Certified Professional Programmer CPP Questions and answers with CertsForce

Viewing page 1 out of 7 pages
Viewing questions 1-10 out of questions
Questions # 1:

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

#include

#include

#include <algorithm>

using namespace std;

class B { int val;

public:

B(int v):val(v){}

int getV() const {return val;} bool operator < (const B & v) const { return val

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

deque d1(t, t+10);

sort(d1.begin(), d1.end());

deque::iterator it = upper_bound(d1.begin(), d1.end(), B(4), greater());

for_each(it, d1.end(), Out(cout)); cout<

return 0;

}

Program outputs:

Options:

A.

5 6 7 8 9 10


B.

4 5 6 7 8 9 10


C.

compilation error


D.

1 2 3 4 5


E.

1 2 3 4


Expert Solution
Questions # 2:

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

#include

#include <algorithm>

#include

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

int main() {

int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };

set s1(t, t+10);

vector v1(s1.rbegin(), s1.rend());

swap_ranges(s1.begin(), s1.end(), v1.begin());

for_each(v1.begin(), v1.end(), myfunction);

for_each(s1.begin(), s1.end(), myfunction);

return 0;

}

Program outputs:

Options:

A.

10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10


B.

compilation error


C.

1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10


D.

1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1


E.

10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1


Expert Solution
Questions # 3:

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

#include

#include <algorithm>

#include

using namespace std;

void myfunction(pair i) {

cout << " " << i.first;

}

int main() {

int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };

map m;

for(int i=0; i < 10; i++) {

m[i]=t[i];

}

for_each(m.begin(), m.end(), myfunction);

return 0;

}

Program outputs:

Options:

A.

10 5 9 6 2 4 7 8 3 1


B.

0 1 2 3 4 5 6 7 8 9


C.

9 8 7 6 5 4 3 2 1 0


D.

1 3 8 7 4 2 6 9 5 10


E.

compilation error


Expert Solution
Questions # 4:

Which sentence is correct about the code below? Choose all that apply.

#include

#include <algorithm>

#include

using namespace std;

class F {

int val;

public:

F(int v):val(v){}

bool operator() (int v) {

if (v == val) return true;

return false;

}

};

int main() {

int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };

vector v1(t, t + 10);

if (find(v1.begin(), v1.end(), 6) == find(v1.begin(), v1.end(), F(6))) {

cout<<"Found!\n";

} else {

cout<<"Not found!\n";

}

return 0;

}

Options:

A.

it will compile successfully


B.

it will display Found!


C.

it will display Not found!


D.

it will not compile successfully


Expert Solution
Questions # 5:

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

#include

#include

int main ()

{

std::vectorv1;

for(int i = 10; i>0; i??)

{

v1.push_back(i);

}

std::vector::iterator it = v1.begin();

int sum = 0;

while(it != v1.end())

{

sum+=it++;

}

std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<

return 0;

}

Options:

A.

program outputs 3 55


B.

compilation error


C.

program outputs 3 45


D.

program outputs 7 55


Expert Solution
Questions # 6:

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

#include

#include <algorithm>

#include

using namespace std;

int main () {

int t[] = {1,2,3,4,5,1,2,3,4,5};

vector v (t,t+10);

vector::iterator it;

int m1[] = {1, 2, 3};

it = search (v.begin(), v.end(), m1, m1+3);

cout << "found at position: " << it?v.begin() << endl;

return 0;

}

Program outputs:

Options:

A.

found at position: 5


B.

found at position: 0


C.

found at position: 6


D.

found at position: 1


E.

found at position: 10


Expert Solution
Questions # 7:

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

#include

#include <algorithm>

#include

using namespace std;

class A {

int a;

public:

A(int a) : a(a) {}

int getA() const { return a; } void setA(int a) { this?>a = a; }

};

int main () {

int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};

deque d (t,t+15);

int number = count(d.begin(), d.end(), 2);

cout<< number<

return 0;

}

Program outputs:

Options:

A.

4


B.

3


C.

2


D.

0


E.

compilation error


Expert Solution
Questions # 9:

What will happen 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, 0, 3, 4, 1, 2, 0 };

vector v(t, t + 10);

multimap m;

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

stringstream s;s << *i << *i;

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

}

pair::iterator, multimap::iterator> range;

range = m.equal_range(2);

for (multimap::iterator i = range.first; i != range.second; i++) {

cout << i?>first << " ";

}

return 0;

}

The output will be:

Options:

A.

2 2


B.

1 2


C.

1 3


D.

2


E.

0 2


Expert Solution
Questions # 10:

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

#include

#include <algorithm>

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

void multiply (int a) {

a*2;

}

int main() {

int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };

vector v1(t, t+10);

for_each(v1.begin(), v1.end(), multiply);

iter_swap(v1.begin(),t+9);

for_each(v1.begin(), v1.end(), myfunction);

return 0;

}

Program outputs:

Options:

A.

1 5 9 6 2 4 7 8 3 1


B.

compilation error


C.

1 2 3 4 5 6 7 8 9 10


D.

10 9 8 7 6 5 4 3 2 1


E.

10 5 9 6 2 4 7 8 3 1


Expert Solution
Viewing page 1 out of 7 pages
Viewing questions 1-10 out of questions