[Q119-Q136] Latest CPP Exam with Accurate C++ Certified Professional Programmer PDF Questions [Sep 24, 2021]

Share

[Sep 24, 2021] Latest CPP Exam with Accurate C++ Certified Professional Programmer PDF Questions

Practice To CPP - Actual4Dumps Remarkable Practice On your C++ Certified Professional Programmer Exam

NEW QUESTION 119
What happens when you attempt to compile and run the following code?
#include <set>
#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() {
int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
set<B> s1(t, t+10);
sort(s1.begin(), s1.end());
for_each(s1.begin(), s1.end(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:

  • A. compilation error
  • B. 8 10 5 1 4 6 2 7 9 3
  • C. 1 2 3 4 5 6 7 8 9 10
  • D. 10 9 8 7 6 5 4 3 2 1

Answer: A

 

NEW QUESTION 120
What happens when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
using namespace std;
class A
{
int a;
public:
A():a(0){} A(int a){ this?>a = a;}
void setA(int a) {this?>a = a;}
int getA() {return a;}
};
ostream &operator<<(ostream & cout, A & a)
{
cout<< a.getA();
return cout;
}
int main ()
{
vector<A*>v(5, new A());
v.push_back(new A(1));
vector<A*>::iterator it;
for(it = v.begin(); it != v.end(); it++)
{
cout<<*it<<" ";
}
cout<<endl;
return 0;
}

  • A. program outputs 0 0 0 0 0 1
  • B. none of these
  • C. program outputs 0 0 0 0 0 0
  • D. program outputs 1 1 1 1 1 1
  • E. compilation error

Answer: B

 

NEW QUESTION 121
What happens when you attempt to compile and run the following code?
# include <vector>
# include <set>
# 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<<" "; } };
bool Greater(int v1, int v2) { return v1<v2; }
int main() {
int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
vector<int> v1(t, t+10);
sort(v1.begin(), v1.end(), Greater);
for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs:

  • A. 8 10 5 1 4 6 2 7 9 3
  • B. 1 2 3 4 5 6 7 8 9 10
  • C. 10 9 8 7 6 5 4 3 2 1
  • D. compilation error

Answer: B

 

NEW QUESTION 122
What happens when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
B operator +(const B &b )const { return B(val + b.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<<" "; } };
B Add(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(), bind2nd(ptr_fun(Add),1));
for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:

  • A. 11 10 9 8 7 6 5 4 3 2
  • B. 1 2 3 4 5 6 7 8 9 10
  • C. 10 9 8 7 6 5 4 3 2 1
  • D. compilation error
  • E. 2 3 4 5 6 7 8 9 10 11

Answer: A

 

NEW QUESTION 123
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[]={6,10,8,7,9};
vector<int> 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<int>(cout));cout<<endl;
return 0;
}
Program outputs:

  • A. 1 2 3 4 5 6 7 8 9 10
  • B. 3 2 4 1 5 6 7 8 9 10
  • C. 1 2 3 4 5 6 10 8 7 9
  • D. compilation error
  • E. 3 2 4 1 5 6 10 8 7 9

Answer: A

 

NEW QUESTION 124
What happens when you attempt to compile and run the following code?
include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector<int> v1(t, t + 10);
deque<int> d1(t, t + 10);
set<int> s1(t, t + 10);
cout<<find(v1.begin(), v1.end(), 6)<<" "<<find(d1.begin(), d1.end(), 6)<<" "<<find(s1.begin(), s1.end(),
6);
return 0;
}

  • A. compilation error
  • B. program outputs: 6 6 6
  • C. none of these
  • D. program outputs: 3 3 5
  • E. program outputs: 3 6 5

Answer: A

 

NEW QUESTION 125
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:

  • A. 64 100
  • B. 100 256
  • C. 0x100 0x256 0x256
  • D. 100 256 256
  • E. 0x64 0x100

Answer: D

 

NEW QUESTION 126
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;
}

  • A. compilation error in line II
  • B. program outputs: 10 11 12 10 11 12
  • C. compilation error in line IV
  • D. compilation error in line I
  • E. compilation error in line III

Answer: E

 

NEW QUESTION 127
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <class T>
class A {
T_v;
public:
A(T v);
};
template<class T>

  • A. program will compile
  • B. program will not compile
  • C. :A(T v):_v(v) {}
    int main()
    {
    A<int> a(2);
    cout<<1<<endl;
    return 0;
    }
  • D. program will cause runtime exception
  • E. program will display: 1

Answer: E

 

NEW QUESTION 128
What happens when you attempt to compile and run the following code?
#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; }
};
int main() {
char s[]={"qwerty"};
char t1[]={"ert"};
char t2[]={"ERT"};
sort(s, s+6);
cout<<includes(s,s+6, t1,t1+3)<<" "<<includes(s,s+6, t2,t2+3)<<endl;
return 0;
}
Program outputs:

  • A. 1 0
  • B. 0 1
  • C. 0 0
  • D. 1 1

Answer: A

 

NEW QUESTION 129
What happens when you attempt to compile and run the following code? Choose all that apply.
#include <deque>
#include <vector>
#include <iostream>
using namespace std;
class A
{
int a;
public:
A(int a) {this?>a = a; c++;}
A(const A & a) {this?>a = a.a; c++;}
~A() { c??;}
static int c;
};
int A::c(0);
int main ()
{
A* t[] = {new A(1), new A(2), new A(3),new A(4), new A(5)};
vector<A*>v1(t, t+10);
deque<A*>d1(v1.begin(), v1.end());
d1.clear();
v1.clear();
cout<<A::c<< endl;
return 0;
}

  • A. program will display 5
  • B. there are 5 A objects created,
  • C. there are 15 A objects created,
  • D. for all object A the destructor is called

Answer: A,B

 

NEW QUESTION 130
What happens when you attempt to compile and run the following code?
# include <deque>
# 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() {
int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
deque<B> d1(t, t+10);
sort(d1.begin(), d1.end());
deque<B>::iterator it = upper_bound(d1.begin(), d1.end(), B(4), greater<B>()); for_each(it, d1.end(), Out<B>(cout)); cout<<endl;
return 0;
}
Program outputs:

  • A. compilation error
  • B. 4 5 6 7 8 9 10
  • C. 1 2 3 4
  • D. 1 2 3 4 5
  • E. 5 6 7 8 9 10

Answer: A

 

NEW QUESTION 131
What happens when you attempt to compile and run the following code?
# include <vector>
# include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
B operator ?(const B &b )const { return B(val ? b.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[]={1,2,3,4,5,6,7,8,9,10};
B t2[]={1,2,3,4,5,6,7,8,9,10};
vector<B> v1(t1, t1+10);
vector<B> v2(t2, t2+10);
vector<B> v3(10);
transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus<B>());
for_each(v3.rbegin(), v3.rend(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:

  • A. 1 3 5 7 9 ?1 ?3 ?5 ?7 ?9
  • B. ?1 ?3 ?5 ?7 ?9 9 7 5 3 1
  • C. 1 3 5 7 9 ?1 ?3 ?5 ?7 ?9
  • D. ?9 ?7 ?5 ?3 ?1 1 3 5 7 9
  • E. 9 7 5 3 1 ?1 ?3 ?5 ?7 ?9

Answer: E

 

NEW QUESTION 132
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:

  • A. compilation error
  • B. 11 10 9 8 7 6 5 4 3 2
  • C. 1 2 3 4 5 6 7 8 9 10
  • D. 10 9 8 7 6 5 4 3 2 1
  • E. 2 3 4 5 6 7 8 9 10 11

Answer: A

 

NEW QUESTION 133
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
bool classifier(int v) {
return v%2==0;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector<int> v1(t, t+10);
set<int> s1(t, t+10);
replace(v1.begin(), v1.end(),classifier, 10);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:

  • A. 1 5 2 5 2 4 4 3 3 1
  • B. compilation error
  • C. 10 10 2 10 2 4 4 10 10 10
  • D. 1 5 10 5 10 10 10 3 3 1

Answer: B

 

NEW QUESTION 134
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
set<int> s1(t, t+10);
vector<int> v1(s1.rbegin(), s1.rend());
swap_ranges(s1.begin(), s1.end(), v1.begin());
for_each(v1.begin(), v1.end(), myfunction);
for_each(s1.begin(), s1.end(), myfunction);
return 0;
}
Program outputs:

  • A. compilation error
  • B. 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1
  • C. 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
  • D. 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
  • E. 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10

Answer: A

 

NEW QUESTION 135
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
float f = 10.126;
cout.unsetf(ios::floatfield);
cout<<scientific<<f<<" "<<setprecision(3)<<f<<endl;
return 0;
}
What will be a mantissa part of the numbers displayed:

  • A. 1.0126 1.013
  • B. 1.0126 1.01
  • C. 1.012600 1.013
  • D. 10.01260 10.013
  • E. 1.012600 10.013

Answer: C

 

NEW QUESTION 136
......

Exam Questions and Answers for  CPP Study Guide Questions and Answers!: https://www.actual4dumps.com/CPP-study-material.html