Last Update 3 hours ago Total Questions : 228
The C++ Certified Professional Programmer content is now fully updated, with all current exam questions added 3 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;
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 < < val < < " "; } };
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 < B > v1(t, t+10);
vector < B > v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(),1));
for_each(v2.rbegin(), v2.rend(), Out < B > (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;
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_intersection(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 < vector >
#include < iostream >
int main ()
{
std::vector < int > v1;
for(int i = 10; i > 0; i??)
{
v1.push_back(i);
}
std::vector < int > ::iterator it = v1.begin();
int sum = 0;
while(it != v1.end())
{
sum+=it++;
}
std::cout < < *v1.erase(v1.begin(),v1.end()?3) < < " " < < sum < < std::endl;
return 0;
}
Which changes introduced independently will allow the code to compile and display “one” “eight” “nine” “ten”? Choose all that apply.
#include < iostream >
#include < map >
#include < string >
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(){
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string s[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","ten"};
multimap < A,string > m; /* Replace Code Here 3 */
for(int i=0; i < 10; i++) {
m.insert(pair < A,string > (A(t[i]),s[i] ));
}
m.erase(m.lower_bound(2),m.upper_bound(7));
multimap < A, string > ::iterator i=m.begin(); /* Replace Code Here 4 */
for( ; i!= m.end(); i++) {
cout < < i? > second < < " ";
}
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;
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[]={5,6,8,2,1};
vector < B > v1(10,0);
sort(t1, t1+5);
sort(t2, t2+5);
set_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin());
for_each(v1.begin(), v1.end(), Out < B > (cout));cout < < endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code? Choose all that apply.
#include < iostream >
#include < fstream >
#include < string >
#include < list >
#include < algorithm >
#include < iomanip >
using namespace std;
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 < int > l(t, t+10);
for_each(l.begin(), l.end(), Out < int > (f));
f.close(); f.open("test.out");
for( ; f.good() ; ) {
int i; f > > i;
cout < < i < < " ";
}
f.close();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
cout < < true < < " " < < boolalpha < < false;
return 0;
}
Program outputs:
