Labour Day Special - 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: c4sdisc65

CPP PDF

$38.5

$109.99

3 Months Free Update

  • Printable Format
  • Value of Money
  • 100% Pass Assurance
  • Verified Answers
  • Researched by Industry Experts
  • Based on Real Exams Scenarios
  • 100% Real Questions

CPP PDF + Testing Engine

$61.6

$175.99

3 Months Free Update

  • Exam Name: C++ Certified Professional Programmer
  • Last Update: Apr 28, 2024
  • Questions and Answers: 228
  • Free Real Questions Demo
  • Recommended by Industry Experts
  • Best Economical Package
  • Immediate Access

CPP Engine

$46.2

$131.99

3 Months Free Update

  • Best Testing Engine
  • One Click installation
  • Recommended by Teachers
  • Easy to use
  • 3 Modes of Learning
  • State of Art Technology
  • 100% Real Questions included

CPP Practice Exam Questions with Answers C++ Certified Professional Programmer Certification

Question # 6

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

#include

#include

#include

using namespace std;

template void print(T start, T end) {

while (start != end) {

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

}

}

class A {

int a;

public:

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

operator int () const { return a;}int getA() const { return a;}

};

struct R {

int val;

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

bool operator ()(const A & a) { return a>val;} };

int main() {

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

list l1(t1, t1 + 10);

R r(4);l1.remove_if(r);

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

return 0;

}

A.

program outputs: 1 2 3 4

B.

program outputs: 5 6 7 8 9 10

C.

program outputs: 1 2 3 4 5

D.

program outputs: 6 7 8 9 10

Question # 7

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

#include

using namespace std;

int main ()

{

std::vectorv1;

v1.push_back(10);

return 0;

}

A.

compilation fails due to error in line 2

B.

compilation fails due to error in line 5

C.

exception is thrown during run time

D.

code compiles and executes successfully

Full Access
Question # 8

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

#include

using namespace std;

int main()

{

cout<

return 0;

}

Program outputs:

A.

true false

B.

1 0

C.

1 false

D.

true 0

E.

compilation error

Full Access
Question # 9

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

};

bool Compare(char a, char b) { return tolower(a) < tolower(b);}

int main() {

char s[]={"qwerty"};

char t1[]={"ert"};

char t2[]={"ERT"};

sort(s, s+6);

cout<

return 0;

}

Program outputs:

A.

0 0

B.

0 1

C.

1 0

D.

1 1

Full Access
Question # 10

Given three files: class.h, class.cpp and main.cpp containing small C++ project, which sentences are TRUE if you attempt to compile and run the program? Assume that the whole compiling environment is properly set.

// File: main.cpp

#include

#include "class.h"

using namespace std;

int main()

{

A a;

cout << a.getV() << endl;

return 0;

}

//File: class.h

#ifndef _CLASS_

#define _CLASS_

template

class A {

T_v;

public:

A() {}

A(T v);

T getV();

};

#endif

//File: class.cpp

#include "class.h"

template

A::A(T v):_v(v) {}

template

T A::getV() { return _v; }

A.

program will display: 0

B.

program will not compile

C.

program will display unpredictable number

D.

program willl be not linked

Full Access
Question # 11

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

#include

#include

#include

using namespace std;

int main(){

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

listv(t, t+10);

set s1(v.begin(),v.end());

if (s1.count(3) == 2) {

s1.erase(3);

}

for(set::iterator i=s1.begin();i!= s1.end(); i++) {

cout<<*i<<" ";

}

return 0;

}

A.

program outputs: 1 2 3 4 5

B.

program outputs: 1 2 4 5

C.

program outputs: 1 1 2 2 3 4 4 5 5

D.

program outputs: 1 1 2 3 3 4 4 5 5

E.

compilation error

Full Access
Question # 12

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

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_union(t1,t1+5,t2,t2+5,v1.begin());

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

return 0;

}

Program outputs:

A.

3 2 4 1 5 6 8 2 1 0

B.

1 2 3 4 5 6 8 2 1 0

C.

1 1 2 2 3 4 5 5 6 8

D.

1 2 3 4 5 6 8 0 0 0

E.

compilation error

Full Access
Question # 13

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, 0, 1, 2, 3, 4, 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()));

}

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

cout<<*i<<" ";

}

return 0;

}

A.

program outputs: 3 4 2 1 0 1 2 3 4 0

B.

program outputs: 00 11 22 33 44

C.

program outputs: 0 0 1 1 2 2 3 3 4 4

D.

program outputs: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4

E.

compilation error

Full Access
Question # 14

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1.1 2.2 3.3?

#include

#include

using namespace std;

int main ()

{

int a,b,c;

cin>>a>>b>>c;

cout<

return 0;

}

Program will output:

A.

123

B.

1 2 3

C.

1.12.23.3

D.

1.1 2.2 3.3

E.

none of these

Full Access
Question # 15

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

#include

#include

#include

using namespace std;

template void print(T start, T end) {

while (start != end) {

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

}

}

int main() {

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

list l1(t1, t1 + 10);

list l2(l1);

l2.reverse(); l1.splice(l1.end(),l2);

l1.unique();

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

return 0;

}

A.

compilation error

B.

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

C.

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

D.

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

Full Access
Question # 16

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

#include

#include

#include

using namespace std;

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

}

map::iterator it = find(m.begin(), m.end(), 5);

cout<first;

return 0;

}

Program outputs:

A.

5

B.

4

C.

10

D.

compilation error

Full Access
Question # 18

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

#include

using namespace std;

class C {

public:

int _c;

C():_c(0){}

C(int c) { _c = c;}

C operator+=(C & b) {

C tmp; tmp._c = _c+b._c;

return tmp;

} };

ostream & operator<<(ostream & c, const C & v) {

c<

template

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

T getV() { return _v; }

void add(T & a) { _v+=a; }

};

int main()

{

A b(2);

Aa (5);

a.add(C());

cout << a.getV() <

return 0;

}

A.

program will display:5

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Full Access
Question # 19

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

#include

#include

using namespace std;

int main ()

{

float f = 10.126;

cout<

return 0;

}

Program outputs:

A.

10.126 10

B.

10.126 10.12

C.

compilation error

D.

10.126 10.13

Full Access
Question # 20

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

#include

#include

#include

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<second<<" ";

}

cout<

return 0;

}

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

Full Access
Question # 21

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

#include

#include

#include

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<

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<

return 0;

}

Program outputs:

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

Full Access
Question # 22

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

#include

using namespace std;

template

void g(int a)

{

cout<

}

template

void g(A a)

{

cout<

}

int main()

{

int a = 1;

g(a);

return 0;

}

A.

program displays: 1

B.

program displays: 2

C.

compilation error

D.

runtime exception

Full Access
Question # 23

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

#include

#include

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<

return 0;

}

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

Full Access
Question # 24

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

#include

#include

int main ()

{

std::vectorv1;

for(int i = 0; i<10; i++) {v1.push_back(i); }

v1.resize(4);

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

v1.insert(v1.end()?1, 4);

for(int i=0 ; i<= v1.size(); i++) {std::cout<

return 0;

}

A.

compilation error

B.

program outputs 0 1 2 3 4

C.

program outputs 0 2 4 8 6 and exception

D.

program outputs 0 2 4 6 8

E.

program outputs 0 2 4 8 6

Full Access
Question # 25

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

#include

using namespace std;

int main()

{

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

cout<<100<<" ";

cout.setf(ios::showbase);

cout<<100<<" ";

return 0;

}

Program outputs:

A.

144 0144

B.

144 0x64

C.

0x144 0144

D.

0144 100

E.

compilation error

Full Access
Question # 26

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

#include

#include

#include

using namespace std;

void print(int v) {

cout<

}

struct Sequence {

int start;

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

int operator()() {

return start++;

}

};

int main() {

vector v1(10);

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

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

cout<

return 0;

}

Program outputs:

A.

1 2 3 4 5 6 7 8 9 10

B.

0 0 0 0 0 0 0 0 0 0

C.

compilation error

D.

no output

Full Access
Question # 27

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

#include

#include

#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()<

return 0;

}

Program outputs:

A.

compilation error

B.

12

C.

3

D.

1

E.

15

Full Access
Question # 28

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

#include

#include

#include

using namespace std;

int main ()

{

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

dequed1(t, t+10);

vectorv1(t, t+10);

cout<

cout<

d1.resize(12); v1.resize(12);

cout<

cout<

d1.reserve(20);v1.reserve(20);

cout<

cout<

return 0;

}

A.

the output is 10 10 10 10 12 12 12 12 20 20

B.

reserve and resize means exactly the same

C.

there are compilation errors

D.

capacity is always smaller then size

Full Access
Question # 29

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

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<

return 0;

}

Program outputs:

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

Full Access
Question # 30

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

#include

#include

using namespace std;

template

void print(T start, T end) {

while (start != end) {

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

}

}

int main()

{

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

list l1(t1, t1 + 5);

l1.remove(2);

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

return 0;

}

A.

program outputs: 1 2 4 5

B.

program outputs: 3 4 5

C.

program outputs: 1 3 4 5

D.

program outputs: 4 5

Full Access
Question # 31

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

#include

#include

#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(s1, v1);

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

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

return 0;

}

Program outputs:

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.

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

Full Access
Question # 32

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

{

vectorv;

A a;

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

v.push_back(a);

cout<

return 0;

}

A.

program outputs 10 11

B.

the result is unpredictable

C.

program outputs 10 0

D.

program outputs 11 0

E.

compilation error

Question # 33

What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?

#include

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main (){

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

fstream f("test.out");

list l(t, t+10);

for_each(l.begin(), l.end(), Out(f));

f.close();

return 0;

}

A.

file test.out will be created and opened for writing

B.

file test.out will be created and opened for reading

C.

no file will be created nor opened

D.

file test.out will contain sequence 1 2 3 4 5 6 7 8 9 10

E.

compilation error

Full Access
Question # 34

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

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<

return 0;

}

Program outputs:

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

Full Access