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;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
operator int () const { return 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 < < " "; } };
struct Add {
B operator()(B & a, B & b) { return a+b; } };
int main() {
B 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(), bind2nd(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 < iostream >
#include < deque >
#include < list >
#include < queue >
#include < vector >
using namespace std;
int main()
{
deque < int > mydeck; list < int > mylist; vector < int > myvector;
queue < int > first; queue < int > second(mydeck);
queue < int > third(second); queue < int, list < int > > fourth(mylist);
fourth.push(10);fourth.push(11);fourth.push(12);
queue < int, vector < int > > fifth(myvector);
fifth.push(10);fifth.push(11);fifth.push(12); // Line I
while(!fifth.empty())
{
cout < < fifth.front() < < " "; // Line II
fifth.pop(); // Line III
}
while (!fourth.empty())
{
cout < < fourth.front() < < " ";
fourth.pop(); // Line IV
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < vector >
#include < set >
#include < deque >
using namespace std;
void myfunction(int i) {
cout < < " " < < i;
}
int add (int a, int b) { return a+b; }
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector < int > v1(t, t+10);
set < int > s1(t, t+10);
deque < int > d1;
d1.resize(s1.size());
transform(s1.begin(), s1.end(), v1.begin(), d1.begin(), add);
for_each(d1.begin(), d1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < deque >
#include < vector >
#include < iostream >
using namespace std;
template < typename T >
int calculate(T start, T end)
{
int s = 0;
while (start != end)
s+= *start; start++; return s;
}
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};
vector < int > v1(t, t+5);
deque < int > d1(t+5, t+10);
cout < < calculate(t,t+10) < < " ";
cout < < calculate(v1.begin()+1,v1.end()?2) < < " ";
cout < < calculate(d1.rbegin()+1,d1.rend()?2) < < " ";
cout < < calculate(t[0],t[10] ) < < " ";
cout < < endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < deque >
#include < list >
#include < stack >
#include < vector >
using namespace std;
int main()
{
deque < int > mydeck; list < int > mylist; vector < int > myvector;
stack < int > first;
stack < int > second(mydeck);
stack < int > third(second);
stack < int, list < int > > fourth(mylist);
fourth.push(10);fourth.push(11);fourth.push(12);
stack < int, vector < int > > fifth(myvector);
fifth.push(10);fifth.push(11);fifth.push(12);
while(!fifth.empty())
{
cout < < fifth.top() < < " ";
fifth.pop();
}
while (!fourth.empty())
{
cout < < fourth.front() < < " ";
fourth.pop();
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include < vector >
#include < iostream >
using namespace std;
class A
{
int a,b;
public:
A & operator =(const A & c) { a = c.a; return *this;}
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 ()
{
vector < A > v;
A a;
a.setA(10); a.setB(11);
v.push_back(a);
A b = v.front(); v.pop_back();
cout < < b.getB() < < " " < < b.getA() < < endl;
return 0;
}
Which changes introduced independently will allow the code to compile and display 0 0 1 1 8 8 9 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 };
set < A > s(t, t+10); /* Replace Code Here 3 */
multiset < A > s1(s.begin(),s.end()); /* Replace Code Here 4 */
s1.insert(s.begin(),s.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
multiset < A > ::iterator i=s1.begin(); /* Replace Code Here 5 */
for( ;i!= s1.end(); i++)
{
cout < < i? > getA() < < " ";
}
cout < < endl;
return 0;
}
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: true false < enter > ?
#include < iostream >
#include < string >
using namespace std;
int main ()
{
bool a,b;
cin > > boolalpha > > a > > b;
cout < < a < < b < < endl;
return 0;
}
Program will output:
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 < 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 () {
ifstream f("test.in");
list < int > l;
for( ; f.good() ; ) {
int i;
f > > i;
l.push_back(i);
}
f.close();
for_each(l.begin(), l.end(), Out < int > (cout));
return 0;
}
Program will output:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < deque >
#include < list >
#include < queue >
#include < vector >
using namespace std;
class compare {
bool reverse;
public:
compare(bool revparam = false) { reverse = revparam; }
bool operator()(int lhs, int rhs) const {
if (reverse) return (lhs > rhs);
else return (lhs < rhs);
}
};
int main(){
int myints[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
priority_queue < int, deque < int > > first(myints, myints + 10);
priority_queue < int, vector < int > , compare > second(myints, myints + 10,
compare(false));
while (first.size() > 0){
cout < < first.top() < < " "; first.pop();
}
while (second.size() > 0) {
cout < < second.top() < < " "; second.pop();
}
return 0;
}
