Last Update 10 hours ago Total Questions : 228
The C++ Certified Professional Programmer content is now fully updated, with all current exam questions added 10 hours ago. Deciding to include CPP practice exam questions in your study plan goes far beyond basic test preparation.
You'll find that our CPP exam questions frequently feature detailed scenarios and practical problem-solving exercises that directly mirror industry challenges. Engaging with these CPP sample sets allows you to effectively manage your time and pace yourself, giving you the ability to finish any C++ Certified Professional Programmer practice test comfortably within the allotted time.
What happens when you attempt to compile and run the following code?
#include < list >
#include < deque >
#include < iostream >
using namespace std;
template < class T >
void print(T start, T end) {
while (start != end) {
std::cout < < *start < < " "; start++;
}
}
int main()
{
int t1[] = { 1, 7, 8, 4, 5 };
list < int > l1(t1, t1 + 5);
int t2[] = { 3, 2, 6, 9, 0 };
deque < int > 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;
}
What happens when you attempt to compile and run the following code?
#include < vector >
#include < iostream >
#include < algorithm >
using namespace std;
template < class T > struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out < < val < < " "; } };
struct Add {
int operator()(int & a, int & b) {
return a+b;
}
};
int main() {
int t[]={1,2,3,4,5,6,7,8,9,10};
vector < int > v1(t, t+10);
vector < int > v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(1,Add()));
for_each(v2.rbegin(), v2.rend(), Out < int > (cout));cout < < endl;
return 0;
}
Program outputs:
What will happen when you attempt to compile and run the following code?
#include < deque >
#include < vector >
#include < iostream >
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};
vector < A > v1(t, t+10);
deque < A > d1(v1.begin(), v1.end());
deque < A > d2;
d2 = d1;
cout < < A::c < < endl;
return 0;
}
How many objects of type A will be created:
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 < iostream >
#include < fstream >
#include < string >
#include < list >
#include < algorithm >
using namespace std;
template < class T > struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out < < val < < " "; } };
int main (){
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fstream f("test.out");
list < int > l(t, t+10);
for_each(l.begin(), l.end(), Out < int > (f));
f.close();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < set >
#include < vector >
using namespace std;
int main(){
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
multiset < int > s1(t,t+10);
s1.insert(s1.find(7), 3);
for(multiset < int > ::iterator i=s1.begin();i!= s1.end(); i++) {
cout < < *i < < " ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include < vector >
#include < iostream >
#include < algorithm >
using namespace std;
template < class T > struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out < < val < < " "; } };
struct Add {
int operator()(int & a, int & b) {
return a+b;
}
};
int main() {
int t[]={1,2,3,4,5,6,7,8,9,10};
vector < int > v1(t, t+10);
vector < int > v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(),1));
for_each(v2.rbegin(), v2.rend(), Out < int > (cout));cout < < endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < vector >
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; }
bool operator==(A & b) { return a == b.a; }
};
struct Compare{
bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};
};
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector < A > v (t,t+10);
vector < A > ::iterator it;
A m1[] = {A(1), A(2), A(3)};
it = find_end (v.begin(), v.end(), m1, m1+3, Compare());
cout < < "Found at position: " < < it?v.begin() < < endl;
return 0;
}
Which changes introduced independently will allow code to compile and display 0 1 8 9 (choose all that apply)
#include < iostream >
#include < set >
#include < vector >
using namespace std;
class A {
int a;
public:
A(int a):a(a){}
int getA() const { return a;}
/* Insert Code Here 1 */
};
/* Insert Code Here 2 */
int main(){
A t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector < A > v(t, t+10);
set < A > s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set < A > ::iterator i=s1.begin();i!= s1.end(); i++) {
cout < < i? > getA() < < " ";
}
cout < < endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < vector >
using namespace std;
void myfunction(int i) {
cout < < " " < < i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector < int > v1(t, t + 10);
copy_backward(t, t+10, v1.rend());
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < map >
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};
map < int, string > m;
for (int i = 0; i < 10; i++) {
m.insert(pair < int, string > (t[i], s[i] ));
}
if (m.count(3) == 2) {
m.erase(3);
}
for (map < int, string > ::iterator i = m.begin(); i != m.end(); i++) {
cout < < i? > first < < " ";
}
return 0;
}
