C++ Institute CPP - C++ Certified Professional Programmer Exam Practice Test

Page: 1 / 14
Total 228 questions
Question 1

What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?

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

ifstream f("test.in");

list l;

for( ; f.good() ; ) {

int i;

f>>i;

l.push_back(i);

}

f.close();

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

return 0;

}

Program will output:



Answer : A


Question 2

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

#include

#include

#include

#include

using namespace std;

template

void print(T start, T end)

{

while (start != end)

cout<<*start++;

}

int main ()

{

string t[] = {"one", "two" ,"three" ,"four", "five"};

vectorv1(t, t+5);

dequed1(v1.rbegin(), v1.rend());

d1.push_back("zero");

print(d1[0].rbegin(),d1[0].rend());

return 0;

}



Answer : B


Question 3

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

include

#include

#include

#include

#include

using namespace std;

int main() {

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

vector v1(t, t + 10);

deque d1(t, t + 10);

set s1(t, t + 10);

cout<

s1.end(), 6);

return 0;

}



Answer : D


Question 4

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

#include

#include

#include

using namespace std;

class A

{

int a;

public:

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

~A() { c??;}

static int c;

};

int A::c(0);

int main ()

{

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

vectorv1(t, t+10);

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

deque d2;

d2 = d1;

cout<

return 0;

}

How many objects of type A will be created:



Answer : D


Question 5
Question 6

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;

}



Answer : B


Question 7

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

};

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:



Answer : A


Page:    1 / 14   
Total 228 questions