C++ Institute CPP Exam (page: 9)
C++ Institute C++ Certified Professional Programmer
Updated on: 15-Feb-2026

Viewing Page 9 of 47

Which pieces of code inserted independently into places marked 1 and 2 will cause the program to compile and display: 0 1 2 3 4 5 6 7 8 9? Choose all that apply.

#include <list>
#include <iostream>
using namespace std;
class A { int a; public:
A(int a){ this?>a=a;}
//insert code here 1
};
//insert code here 2
template<class T> void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main() {
A t1[] = { 1, 7, 8, 4, 5 }; list<A> l1(t1, t1 + 5);
A t2[] = { 3, 2, 6, 9, 0 }; list<A> l2(t2, t2 + 5);
l1.sort(); l2.sort(); l1.merge(l2);
print(l1.begin(), l1.end());
print(l2.begin(), l2.end()); cout<<endl;
return 0;
}

  1. place 1: operator int() { return a; }
  2. place 1: operator int() { return a; }
    bool operator < (const A & b) { return this?>a< b.a;}
  3. place 1: bool operator < (const A & b) { return this?>a< b.a;}
  4. place 1: bool operator < (const A & b) { return this?>a< b.a;}
    friend ostream & operator <<(ostream & c, const A & a);
    place 2: ostream & operator <<(ostream & c, const A & a) { c<<a.a; return c;}
  5. place 1: bool operator < (const A & b) { return this?>a< b.a;}
    place 2: ostream & operator <<(ostream & c, const A & a) { c<<a.a; return c;}

Answer(s): A,B,D



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,4,5,1,2,3,4,5};
vector<int> v (t,t+10);
vector<int>::iterator it;
int m1[] = {1, 2, 3};
it = search (v.begin(), v.end(), m1, m1+3);
cout << "found at position: " << it?v.begin() << endl;
return 0;
}

Program outputs:

  1. found at position: 5
  2. found at position: 0
  3. found at position: 6
  4. found at position: 1
  5. found at position: 10

Answer(s): B



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

#include <deque>
#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 Sequence { int start;
Sequence(int start):start(start){}
int operator()() {return 10*(1+(start++ %3));}
};
int main() {
deque<int> d1(10);
generate(d1.begin(), d1.end(), Sequence(1));
sort(d1.begin(), d1.end());
pair<deque<int>::iterator, deque<int>::iterator > result = equal_range(d1.begin(), d1.end(), 20);
for_each(result.first, result.second, Out<int>(cout));cout<<endl;
return 0;
}

Program outputs:

  1. 10 10 10 20 20 20 20 30 30 30
  2. 20 20 20 20
  3. 10 20 20 20 20
  4. 20 20 20 20 30
  5. 10 20 20 20 20 30

Answer(s): B



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"};
map<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));
map<A, string>::iterator i=m.begin(); /* Replace Code Here 4 */
for( ;i!= m.end(); i++) {
cout<<i?>second<<" ";
}
cout<<endl;
return 0;
}

  1. operator int() const { return a;} inserted at Place 1
  2. bool operator < (const A & b) const { return a<b.a;} inserted at Place 1
  3. bool operator < (const A & b) const { return b.a<a;} inserted at Place 1
  4. struct R { bool operator ()(const A & a, const A & b) { return a.getA()<b.getA();} }; inserted at Place 2
    replacing line marked 3 with map<A, string, R> m;
    replacing line marked 4 with map<A, string,R>::iterator i=m.begin();

Answer(s): A,B,D



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 main() {
int t1[]={3,2,4,1,5};
int t2[]={6,10,8,7,9};
vector<int> v1(5);
transform(t1,t1+5,t2,v1.rbegin(), plus<int>());
for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl;
return 0;
}

Program outputs:

  1. 9 12 12 8 14
  2. 14 8 12 12 9
  3. 3 2 4 1 5 6 10 8 7 9
  4. 1 2 3 4 5 6 7 8 9 10
  5. compilation error

Answer(s): A



Viewing Page 9 of 47



Share your comments for C++ Institute CPP exam with other users:

Kettie 10/12/2023 1:18:00 AM

this is very helpful content
Anonymous


SB 7/21/2023 3:18:00 AM

please provide the dumps
UNITED STATES


David 8/2/2023 8:20:00 AM

it is amazing
Anonymous


User 8/3/2023 3:32:00 AM

quesion 178 about "a banking system that predicts whether a loan will be repaid is an example of the" the answer is classification. not regresion, you should fix it.
EUROPEAN UNION


quen 7/26/2023 10:39:00 AM

please upload apache spark dumps
Anonymous


Erineo 11/2/2023 5:34:00 PM

q14 is b&c to reduce you will switch off mail for every single alert and you will switch on daily digest to get a mail once per day, you might even skip the empty digest mail but i see this as a part of the daily digest adjustment
Anonymous


Paul 10/21/2023 8:25:00 AM

i think it is good question
Anonymous


Unknown 8/15/2023 5:09:00 AM

good for students who wish to give certification.
INDIA


Ch 11/20/2023 10:56:00 PM

is there a google drive link to the images? the links in questions are not working.
AUSTRALIA


Joey 5/16/2023 5:25:00 AM

very promising, looks great, so much wow!
Anonymous


alaska 10/24/2023 5:48:00 AM

i scored 87% on the az-204 exam. thanks! i always trust
GERMANY


nnn 7/9/2023 11:09:00 PM

good need more
Anonymous


User-sfdc 12/29/2023 7:21:00 AM

sample questions seems good
Anonymous


Tamer dam 8/4/2023 10:21:00 AM

huawei is ok
UNITED STATES


YK 12/11/2023 1:10:00 AM

good one nice
JAPAN


de 8/28/2023 2:38:00 AM

please continue
GERMANY


DMZ 6/25/2023 11:56:00 PM

this exam dumps just did the job. i donot want to ruffle your feathers but your exam dumps and mock test engine is amazing.
UNITED KINGDOM


Jose 8/30/2023 6:14:00 AM

nice questions
PORTUGAL


Tar01 7/24/2023 7:07:00 PM

the explanation are really helpful
Anonymous


DaveG 12/15/2023 4:50:00 PM

just passed my exam yesterday on my first attempt. these dumps were extremely helpful in passing first time. the questions were very, very similar to these questions!
Anonymous


A.K. 6/30/2023 6:34:00 AM

cosmos db is paas not saas
Anonymous


S Roychowdhury 6/26/2023 5:27:00 PM

what is the percentage of common questions in gcp exam compared to 197 dump questions? are they 100% matching with real gcp exam?
Anonymous


Bella 7/22/2023 2:05:00 AM

not able to see questions
Anonymous


Scott 9/8/2023 7:19:00 AM

by far one of the best sites for free questions. i have pass 2 exams with the help of this website.
CANADA


donald 8/19/2023 11:05:00 AM

excellent question bank.
Anonymous


Ashwini 8/22/2023 5:13:00 AM

it really helped
Anonymous


sk 5/13/2023 2:07:00 AM

excelent material
INDIA


Christopher 9/5/2022 10:54:00 PM

the new versoin of this exam which i downloaded has all the latest questions from the exam. i only saw 3 new questions in the exam which was not in this dump.
CANADA


Sam 9/7/2023 6:51:00 AM

question 8 - can cloudtrail be used for storing jobs? based on aws - aws cloudtrail is used for governance, compliance and investigating api usage across all of our aws accounts. every action that is taken by a user or script is an api call so this is logged to [aws] cloudtrail. something seems incorrect here.
UNITED STATES


Tanvi Rajput 8/14/2023 10:55:00 AM

question 13 tda - c01 answer : quick table calculation -> percentage of total , compute using table down
UNITED KINGDOM


PMSAGAR 9/19/2023 2:48:00 AM

pls share teh dump
UNITED STATES


zazza 6/16/2023 10:47:00 AM

question 44 answer is user risk
ITALY


Prasana 6/23/2023 1:59:00 AM

please post the questions for preparation
Anonymous


test user 9/24/2023 3:15:00 AM

thanks for the questions
AUSTRALIA