Weekend Special 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: sale65best

Free C++ Institute CPP Practice Exam with Questions & Answers | Set: 6

Questions 51

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

#include

#include

#include <iostream>

#include <algorithm>

using namespace std;

class B {

int val;

public:

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

operator int() { return val;}

};

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

struct Sequence { int start;

Sequence(int start):start(start){}

int operator()() { return start++; } };

bool predicate(int v) { return v%2==0; }

int main() {

vector v1(10);

generate_n(v1.begin(), 10, Sequence(1));

for_each(v1.begin(), remove_if(v1.begin(), v1.end(), predicate), Out(cout));cout<<endl;

return 0;}

Program outputs:

Options:
A.

1 3 5 7 9 6 7 8 9 10

B.

1 3 5 7 9

C.

2 4 6 8 10

D.

compilation error

E.

no output

C++ Institute CPP Premium Access
Questions 52

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

#include <iostream>

#include <algorithm>

#include

using namespace std;

int main () {

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

vector v (t,t+10);

vector::iterator it = v.begin();

while ( (it = adjacent_find (it, v.end())) != v.end()) {

cout<<it?v.begin()<<" ";it++;

}

cout<< endl;

return 0;

}

Options:
A.

program outputs: 2 3

B.

program outputs: 2 7

C.

program outputs: 3 8

D.

compilation error

E.

program will run forever

Questions 53

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

#include <iostream>

#include

#include

#include

#include <string>

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;

}

Options:
A.

program outputs: 6

B.

program outputs: 5 7

C.

program outputs: 6 7

D.

program outputs: 1 5

E.

program outputs: 6 5

Questions 54

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

#include <iostream>

#include

using namespace std;

int main ()

{

float f = 10.126;

cout<<f<<" "<

return 0;

}

Program outputs:

Options:
A.

10.126 10

B.

10.126 10.12

C.

compilation error

D.

10.126 10.13

Questions 55

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

#include <iostream>

#include <algorithm>

#include

using namespace std;

bool compare(int a, int b) { return a == b; }

int main () {

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

vector v (t,t+10);

vector::iterator it = v.begin();

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

while ( (it = find_first_of (it, v.end(), m1, m1+3)) != v.end()) {

cout<<it?v.begin()<<" ";

}

cout<< endl;

return 0;

}

Options:
A.

program outputs: 0 1 2 5 6 7

B.

program outputs: 0 5

C.

program outputs: 0 0

D.

compilation error

E.

program will run forever

Questions 56

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

#include <iostream>

#include

#include <string>

using namespace std;

int main(){

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

string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};

map m;

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

m.insert(pair(second[i],first[i]));

}

if (m[11] == "eleven") {

cout<<"eleven ";

}

for(map::iterator i=m.begin();i!= m.end(); i++) {

cout<<i?>second<<" ";

}

cout<<m.size();

return 0;

}

Options:
A.

program outputs: one two three four five six seven eight nine ten 11

B.

program outputs: one two three four five six seven eight nine ten 10

C.

program outputs: one two three four five six seven eight nine ten 10

D.

program outputs: eleven one two three four five six seven eight nine ten 10

E.

runtime exception

Questions 57

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

#include

#include <iostream>

#include <algorithm>

using namespace std;

class B { int val;

public:

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

int getV() const {return val;}

operator int () const { return val;} };

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

struct Add {

B operator()(B & a, B & b) { return a+b; }};

int main() {

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

vector v1(t, t+10);

vector v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(),1));

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<<endl;

return 0;

}

Program outputs:

Options:
A.

1 2 3 4 5 6 7 8 9 10

B.

2 3 4 5 6 7 8 9 10 11

C.

10 9 8 7 6 5 4 3 2 1

D.

11 10 9 8 7 6 5 4 3 2

E.

compilation error

Questions 58

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

#include

#include

#include <iostream>

using namespace std;

template

void print(T start, T end) {

while (start != end) {

std::cout << *start << " "; start++;

}

}

int main()

{

int t1[] ={ 1, 7, 8, 4, 5 };

list l1(t1, t1 + 5);

int t2[] ={ 3, 2, 6, 9, 0 };

deque d1(t2, t2 + 5);

l1.sort();

d1.sort();

l1.merge(d1);

print(l1.begin(), l1.end());

print(d1.begin(), d2.end()); cout<<endl;

return 0;

}

Options:
A.

program outputs: 0 1 2 3 4 5 6 7 8 9 0 2 3 6 9

B.

program outputs: 0 1 2 3 4 5 6 7 8 9

C.

program outputs: 9 8 7 6 5 4 3 2 1 0

D.

compilation error

Questions 59

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

#include

#include <iostream>

#include <algorithm>

using namespace std;

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

int main() {

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

int t2[]={5,6,8,2,1};

vector v1(10);

sort(t1, t1+5);

sort(t2, t2+5);

set_symmetric_difference(t1,t1+5,t2,t2+5,v1.begin());

for_each(v1.begin(), v1.end(), Out(cout));cout<<endl;

return 0;

}

Program outputs:

Options:
A.

6 8 3 4 0 0 0 0 0 0

B.

3 4 0 0 0 0 0 0 0 0

C.

6 8 0 0 0 0 0 0 0 0

D.

compilation error

E.

3 4 6 8 0 0 0 0 0 0

Questions 60

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

#include

#include

#include <iostream>

#include <algorithm>

using namespace std;

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

bool Greater(int v1, int v2) { return v1

int main() {

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

vector v1(t, t+10);

sort(v1.begin(), v1.end(), Greater);

for_each(v1.begin(), v1.end(), Out(cout));cout<<endl;

return 0;

}

Program outputs:

Options:
A.

8 10 5 1 4 6 2 7 9 3

B.

1 2 3 4 5 6 7 8 9 10

C.

compilation error

D.

10 9 8 7 6 5 4 3 2 1

Exam Code: CPP
Certification Provider: C++ Institute
Exam Name: C++ Certified Professional Programmer
Last Update: Mar 23, 2025
Questions: 228