Last Update 4 hours ago Total Questions : 228
The C++ Certified Professional Programmer content is now fully updated, with all current exam questions added 4 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 < 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 < < " "; } };
int main() {
int t1[]={3,2,4,1,5};
int t2[]={5,6,8,2,1};
vector < int > v1(10);
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 < 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 < deque >
#include < vector >
using namespace std;
bool identical(int a, int b) {
return b == 2*a?true:false;
}
int main() {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
int u[] = {2,4,6,4,6,10,2,4,14,6,4,2,20,8,8,5};
vector < int > v1(t, t + 15);
deque < int > d1(u, u + 15);
pair < deque < int > ::iterator, vector < int > ::iterator > result;
result = mismatch(d1.begin(), d1.end(), v1.begin(), identical); //Line I
if (result.first == d1.end() & & result.second == v1.end()) { //Line II
cout < < "Identical\n";
} else {
cout < < "Not identical\n";
}
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < vector >
#include < set >
using namespace std;
int main() {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector < int > v1(t, t + 15);
set < int > s1(t, t + 15);
pair < set < int > ::iterator, vector < int > ::iterator > resultSet = mismatch(s1.begin(), s1.end(), v1.begin());
cout < < *resultSet.first < < " " < < *resultSet.second < < endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < map >
using namespace std;
void myfunction(pair < int, int > i) {
cout < < " " < < i.first;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map < int, int > m;
for(int i=0; i < 10; i++) {
m[i]=t[i] ;
}
for_each(m.begin(), m.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < fstream >
#include < string >
#include < list >
#include < algorithm >
#include < iomanip >
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
operator int() const { return val; };};
template < class T > struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out < < setw(3) < < hex < < val; } };
int main () {
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fstream f("test.out", ios::trunc|ios::out);
list < B > l(t, t+10);
for_each(l.begin(), l.end(), Out < B > (f));
f.close();
f.open("test.out");
for( ; f.good() ; ) {
B i;
f > > i;
cout < < i < < " ";
}
f.close();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
using namespace std;
template < class T >
class A {
T _v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T & a) { _v+=a; }
void add(string & a) {
_v.insert(0, a);
}
};
int main()
{
A < string > a("Hello");
string s(" world!");
a.add(s);
cout < < a.getV() < < endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < vector >
using namespace std;
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector < int > v (t,t+15);
vector < int > ::iterator it = search_n(v.begin(), v.end(), 4, 2);
cout < < it?v.begin() < < endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < vector >
#include < iostream >
#include < algorithm >
#include < functional >
using namespace std;
template < class T > struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out < < val < < " "; } };
int Add(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(), bind2nd(ptr_fun (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 < vector >
#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 < v.val;} };
ostream & operator < < (ostream & out, const B & v) { out < < v.getV(); return out;}
template < class T > struct 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[]={6,10,8,7,9};
vector < B > v1(10);
sort(t1, t1+5);
sort(t2, t2+5);
merge(t1,t1+5,t2,t2+5,v1.begin());
for_each(v1.begin(), v1.end(), Out < B > (cout));cout < < endl;
return 0;
}
Program outputs:
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 64 100 < enter > ?
#include < iostream >
#include < string >
#include < sstream >
#include < iomanip >
using namespace std;
int main ()
{
string s;
getline(cin, s);
stringstream input(s);
stringstream output;
for( ; !input.fail() ; )
{
int i;
input > > hex > > i;
output < < setw(4) < < i;
}
cout < < output.str();
return 0;
}
What will be the result assuming that user will enter following sequence: 64 100:
