[Sep 14, 2021] CPP Dumps Full Questions - Exam Study Guide [Q20-Q38]

Share

[Sep 14, 2021] CPP Dumps Full Questions - Exam Study Guide

C++ Certified  Free Certification Exam Material from Free4Torrent with 230 Questions

NEW QUESTION 20
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 = 0; i<10; i++) {v1.push_back(i); }
v1.resize(4);
std::vector<int>::iterator it = v1.end();
v1.insert(v1.end()?1, 4);
for(int i=0 ; i<= v1.size(); i++) {std::cout<<v1.at(i)+v1[i]<<" "; }std::cout<<std::endl; return 0;
}

  • A. program outputs 0 1 2 3 4
  • B. program outputs 0 2 4 8 6
  • C. compilation error
  • D. program outputs 0 2 4 6 8
  • E. program outputs 0 2 4 8 6 and exception

Answer: E

 

NEW QUESTION 21
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 Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return 10*(1+(start++ %3)); }
};
int main() {
vector<int> v1(10);
generate(v1.begin(), v1.end(), Sequence(1));
unique(v1.begin(),v1.end());
for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;
return 0;
}
Program outputs:

  • A. 30 10 20
  • B. 20 30 10
  • C. 20 30 10 20 30 10 20 30 10 20
  • D. compilation error

Answer: C

 

NEW QUESTION 22
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<<" "; } };
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(ptr_fun (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 23
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::oct, ios::basefield);
cout<<100<<" ";
cout.setf(ios::showbase);
cout<<100<<" ";
return 0;
}
Program outputs:

  • A. 144 0x64
  • B. 0144 100
  • C. 0x144 0144
  • D. compilation error
  • E. 144 0144

Answer: E

 

NEW QUESTION 24
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(1,Add()));
for_each(v2.rbegin(), v2.rend(), Out<B>(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 25
What will happen when you attempt to compile and run the following code?
#include <deque>
#include <vector>
#include <iostream>
using namespace std;
class A
{
int a;
public:
A(int a) {this?>a = a; c++;}
~A() { c??;}
static int c;
};
int A::c(0);
int main ()
{
A t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8 , 9};
vector<A>v1(t, t+10);
deque<A>d1(v1.begin(), v1.end());
deque<A> d2;
d2 = d1;
cout<<A::c<< endl;
return 0;
}
How many objects of type A will be created:

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

Answer: A

 

NEW QUESTION 26
Which are NOT valid instantiations of priority_queue object:
# include <iostream>
# include <deque>
# include <list>
# include <queue>
# include <vector>
using namespace std;
int main()
{
deque<int> mydeck;list<int> mylist; vector<int> myvector;
priority_queue<int> first;//line I
priority_queue<int, deque<int> > second;//line II
priority_queue<int> third(first);//line III
priority_queue<int, list<int> > fourth(third);//line IV
priority_queue<int, vector<int> > fifth(myvector.begin(), myvector.end());//line V return 0;
}

  • A. line II
  • B. line V
  • C. line III
  • D. line IV
  • E. line I

Answer: D

 

NEW QUESTION 27
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<<" "; } };
template <typename T> struct Sequence {
T start; T step;
Sequence(T start, T step):start(start), step(step){}
T operator()() { T v = start; start+=step; return v; } };
bool Less(float a, float b) { return int(a)<int(b);}
int main() {
float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};
vector<float> v1; v1.assign(t, t+10);
stable_sort(v1.begin(), v1.end(), Less);
for_each(v1.begin(), v1.end(), Out<float>(cout));cout<<endl;
return 0;
}
Program outputs:

  • A. the exact output is impossible to determine
  • B. 1.13 1.32 1.66 1.96 2.28 2.3 2.62 2.98 3.64 3.94
  • C. 1.66 1.32 1.96 1.13 2.28 2.3 2.98 2.62 3.94 3.64
  • D. compilation error
  • E. 3.94 3.64 2.98 2.62 2.3 2.28 1.96 1.66 1.32 1.13

Answer: C

 

NEW QUESTION 28
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 Sequence {
int start;
Sequence(int start):start(start){}
int operator()() {
return start++; } };
int main() {
vector<int> v1(10);
vector<int> v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
reverse_copy(v1.begin(),v1.end(), v2.rbegin());
sort(v2.begin(), v2.end(), less_equal<int>());
for_each(v2.begin(), v2.end(), Out<int>(cout) );cout<<endl;
return 0;
}
Program outputs:

  • A. no output
  • 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 29
What happens 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<<showpoint<<f<<fixed<<" "<<setprecision(2)<<f<<endl;
return 0;
}
Program outputs:

  • A. 10.126 10.13
  • B. 10.126 10.12
  • C. 10.1260 10.13
  • D. 10.126 10

Answer: C

 

NEW QUESTION 30
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <map>
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"}; map<int, string> m;
for (int i = 0; i < 10; i++) {
m.push_back(pair<int, string>(t[i], s[i]));
}
for (map<int, string>::iterator i = m.begin(); i != m.end(); i++) {
cout << i?>first << " ";
}
return 0;
}

  • A. compilation error
  • B. program outputs: 1 1 2 2 3 3 4 4 5 5
  • C. program outputs: one one two two three three four four five five
  • D. program outputs: 1 2 3 4 5
  • E. program outputs: one two three four five

Answer: A

 

NEW QUESTION 31
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
operator int() const {return a;}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
set<A> s (t,t+15);
cout<<equal(s.begin(), s.end(), t)<<endl;
return 0;
}
Program outputs:

  • A. false
  • B. 0
  • C. 1
  • D. compilation error
  • E. true

Answer: B

 

NEW QUESTION 32
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()
{
int t[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
deque<int> mydeck(t, t+10);list<int> mylist(t,t+10);
queue<int> first;
queue<int> second(mydeck);
queue<int> third(second);
queue<int, list<int> > fourth(mylist);
mylist.clear();third.clear();
cout<<third.size()<< " "<<mydeck.size()<< endl;
cout<<fourth.size()<< " "<<mylist.size()<<endl;
return 0;
}

  • A. compilation error
  • B. program outputs: 10 0
    0 10
  • C. program outputs: 10 10
    1 0 10
  • D. program outputs: 0 0
    0 0
  • E. program outputs: 10 0
    10 0

Answer: A

 

NEW QUESTION 33
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<<" "; } };
struct Add : public binary_function<int, int, int> {
int operator() (const int & a, const int & b) const {
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. 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 34
What happens when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
int main ()
{
int t[]={1,2,3,4,5};
std::vector<int>v1(t,t+5);
std::vector<int>v2(v1);
v1.resize(10);
v2.reserve(10);
std::vector<int>::iterator i = v1.begin();int ii = 0;
while (i != v1.end()) { std::cout<<i[ii]<<" ";ii??;i++; }
i = v2.begin();ii=0;
while (i != v2.end()) { std::cout<<i[ii]<<" ";ii??;i++; }
return 0;
}

  • A. program outputs 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5
  • B. program outputs 1 2 3 4 5 0 0 0 0 0 1 2 3 4 5 0 0 0 0 0
  • C. compilation error
  • D. program outputs 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Answer: D

 

NEW QUESTION 35
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <map>
# include <vector>
# include <sstream>
# include <string>
using namespace std;
int main() {
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int> v(t, t + 10);
map<int, string> m;
for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
stringstream s;s << *i << *i;
m.insert(pair<int, string>(*i, s.str()));
}
pair<map<int, string>::iterator, map<int, string>::iterator> range;
range = m.equal_range(6);
for (map<int, string>::iterator i = range.first; i != range.second; i++) { cout << i?>first << " ";
}
return 0;
}

  • A. program outputs: 6 7
  • B. program outputs: 6 5
  • C. program outputs: 5 7
  • D. program outputs: 6
  • E. program outputs: 1 5

Answer: D

 

NEW QUESTION 36
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 37
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::oct, ios::basefield);
cout<<100<<" ";
cout.setf(ios::showbase);
cout<<100<<" ";
return 0;
}
Program outputs:

  • A. 144 0x64
  • B. 0144 100
  • C. 0x144 0144
  • D. compilation error
  • E. 144 0144

Answer: E

 

NEW QUESTION 38
......

Dumps Brief Outline Of The CPP Exam: https://www.free4torrent.com/CPP-braindumps-torrent.html