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

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

Questions 41

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

#include

#include <iostream>

#include <algorithm>

#include

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<<v.getV(); return out;}

templatestruct Out {

ostream & out;

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

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

};

int main() {

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

B t1[]={B(1),B(2),B(3),B(4)};

deque d1(t, t+10);

set s1(t, t+10);

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

cout<<includes(d1.begin(),d1.end(), t1,t1+4)<<" "<

<<endl;

return 0;

}

Program outputs:

Options:
A.

1 1

B.

1 0

C.

0 1

D.

0 0

E.

compilation error

C++ Institute CPP Premium Access
Questions 42

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: true true<enter>?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

bool a,b;

cin>>a>>b;

cout<<a<

return 0;

}

Program will output:

Options:
A.

truetrue

B.

falsefalse

C.

11

D.

00

E.

none of these

Questions 43

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):val(v){}

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

templatestruct Out {

ostream & out;

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

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

int main() {

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

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

vector v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

set_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.

1 2 3 4 5 6 8 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.

1 2 5 0 0 0 0 0 0 0

Questions 44

What happens when you attempt to compile and run the following code? Choose all that apply.

#include

#include

#include <iostream>

using namespace std;

class A

{

int a;

public:

A(int a) {this?>a = a; c++;}

A(const A & a) {this?>a = a.a; c++;}

~A() { c??;}

static int c;

};

int A::c(0);

int main ()

{

A* t[] = {new A(1), new A(2), new A(3),new A(4), new A(5)};

vectorv1(t, t+10);

dequed1(v1.begin(), v1.end());

d1.clear();

v1.clear();

cout<<A::c<< endl;

return 0;

}

Options:
A.

there are 15 A objects created,

B.

there are 5 A objects created,

C.

for all object A the destructor is called

D.

program will display 5

Questions 45

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

#include

#include <iostream>

#include <algorithm>

#include <functional>

using namespace std;

class B { int val;

public:

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

int getV() const {return val;}

B operator ?(const B &b )const { return B(val ? b.val);}};

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

templatestruct Out {

ostream & out;

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

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

int main() {

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

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

vector v1(t1, t1+10);

vector v2(t2, t2+10);

vector v3(10);

transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus());

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

return 0;

}

Program outputs:

Options:
A.

9 7 5 3 1 ?1 ?3 ?5 ?7 ?9

B.

?1 ?3 ?5 ?7 ?9 9 7 5 3 1

C.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

D.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

E.

?9 ?7 ?5 ?3 ?1 1 3 5 7 9

Questions 46

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

#include <iostream>

#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; }

};

struct Even {

bool operator ()(const A & a, const A &b) {

return (a.getA() % 2)==b.getA() % 2;

}

};

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);

deque::iterator it = search_n(d.begin(), d.end(), 3, 2, Even());

cout<< it?d.begin()<<endl;

return 0;

}

Program outputs:

Options:
A.

compilation error

B.

12

C.

3

D.

1

E.

15

Questions 47

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

#include

#include <iostream>

#include <algorithm>

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main() {

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

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

deque d1(t, t+10);

set s1(t, t+10);

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

cout<<includes(s1.begin(),s1.end(), t1,t1+4)<<" "<

<<endl;

return 0;

}

Program outputs:

Options:
A.

1 1

B.

1 0

C.

0 1

D.

0 0

Questions 48

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

#include

#include <iostream>

using namespace std;

class A

{

int a;

public:

A():a(0){} A(int a){ this?>a = a;}

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

int getA() {return a;}

};

ostream &operator<<(ostream & cout, A & a)

{

cout<< a.getA();

return cout;

}

int main ()

{

vectorv(5, new A());

v.push_back(new A(1));

vector::iterator it;

for(it = v.begin(); it != v.end(); it++)

{

cout<<*it<<" ";

}

cout<<endl;

return 0;

}

Options:
A.

program outputs 0 0 0 0 0 1

B.

program outputs 0 0 0 0 0 0

C.

compilation error

D.

program outputs 1 1 1 1 1 1

E.

none of these

Questions 49

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

#include <iostream>

using namespace std;

int main()

{

cout.setf(ios::oct, ios::basefield);

cout<<100<<" ";

cout.setf(ios::showbase);

cout<<100<<" ";

return 0;

}

Program outputs:

Options:
A.

144 0144

B.

144 0x64

C.

0x144 0144

D.

0144 100

E.

compilation error

Questions 50

Which are NOT valid instantiations of priority_queue object:

#include <iostream>

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;list mylist; vector myvector;

priority_queue first;//line I

priority_queue > second;//line II

priority_queue third(first);//line III

priority_queue > fourth(third);//line IV

priority_queue > fifth(myvector.begin(), myvector.end());//line V

return 0;

}

Options:
A.

line I

B.

line II

C.

line III

D.

line IV

E.

line V

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