
Best Preparations of CPP Exam 2021 C++ Certified Unlimited 230 Questions
Focus on CPP All-in-One Exam Guide For Quick Preparation.
NEW QUESTION 112
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() {
vector<int> v1(10,1);
fill(v1.begin()+2, v1.end()?2,2);
fill_n(v1.begin()+4,2,3);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
- A. 1 1 2 2 3 3 2 2 1 1
- B. none of these
- C. 1 1 2 2 2 2 2 2 1 1
- D. compilation error
Answer: A
NEW QUESTION 113
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:
- A. 3 4 6 8 0 0 0 0 0 0
- B. 3 4 0 0 0 0 0 0 0 0
- C. 6 8 3 4 0 0 0 0 0 0
- D. 6 8 0 0 0 0 0 0 0 0
- E. compilation error
Answer: A
NEW QUESTION 114
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));
random(v1.begin(),v1.end());
for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;
return 0;
}
Program outputs:
- A. compilation error
- B. 1 2 3 4 5 6 7 8 9 10
- C. 10 9 8 7 6 5 4 3 2 1
- D. 8 2 4 9 5 7 10 6 1 3
Answer: A
NEW QUESTION 115
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 116
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 117
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[]={6,10,8,7,9}; vector<B> 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<B>(cout));cout<<endl; return 0;
}
Program outputs:
- A. compilation error
- B. 1 2 3 4 5 6 7 8 9 10
- C. 3 2 4 1 5 6 7 8 9 10
- D. 1 2 3 4 5 6 10 8 7 9
- E. 3 2 4 1 5 6 10 8 7 9
Answer: A
NEW QUESTION 118
What happens when you attempt to compile and run the following code?
# include <deque>
# 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};
deque<B> d1(t, t+10);
sort(d1.begin(), d1.end());
set<B> s1(t,t+10);
cout<<binary_search(s1.begin(),s1.end(), 4)<<" "<<binary_search(d1.begin(),d1.end(),
4 )<<endl;
return 0;
}
Program outputs:
- A. compilation error
- B. false false
- C. true true
- D. 1 0
- E. 1 1
Answer: A
NEW QUESTION 119
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[]={6,10,8,7,9};
vector<B> v1(10,0);
sort(t1, t1+5); sort(t2, t2+5);
copy(t1,t1+5,v1.begin());
copy(t2,t2+5,v1.begin()+5);
inplace_merge(v1.begin(), v1.begin()+5,v1.end());
for_each(v1.begin(), v1.end(), Out<B>(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 120
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;
}
struct sequence {
int val,inc;
sequence(int s, int i):val(s),inc(i){}
int operator()(){
int r = val; val += inc;
return r;
}
};
int main() {
vector<int> v1(10);
fill(v1.begin(), v1.end(), sequence(1,1));
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
- A. compilation error
- B. 0
- C. 1 2 3 4 5 6 7 8 9 10
- D. 0 0 0 0 0 0 0 0 0 0
Answer: A
NEW QUESTION 121
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 end<enter>?
#include <iostream>
# 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 ()
{
list<int> l;
for( ; !cin.bad() ; )
{
int i;
cin>>i;
l.push_back(i);
}
for_each(l.begin(), l.end(), Out<int>(cout));
return 0;
}
Program will output:
- A. 1 2 3 end
- B. 0
- C. compilation error
- D. program runs forever without output
- E. 1 2 3
Answer: D
NEW QUESTION 122
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main() {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector<int> v1(t, t + 15);
set<int> s1(t, t + 15);
pair<set<int>::iterator, vector<int>::iterator > resultSet = equal(s1.begin(), s1.end(), v1.begin());
cout<<*resultSet.first<<" "<<*resultSet.second<<endl;
return 0;
}
Program outputs:
- A. compilation error
- B. 2 4
- C. 4 2
- D. 0 5
Answer: A
NEW QUESTION 123
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
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; }
bool operator==(A & b) { return a == b.a; }
};
struct Compare{
bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};
};
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector<A> v (t,t+10);
vector<A>::iterator it;
A m1[] = {A(1), A(2), A(3)};
it = search (v.begin(), v.end(), m1, m1+3, Compare());
cout << "First found at position: " << it?v.begin() << endl;
return 0;
}
Program outputs:
- A. First found at position: 0
- B. First found at position: 5
- C. First found at position: 7
- D. compilation error
- E. First found at position: 10
Answer: A
NEW QUESTION 124
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <set>
# include <list>
using namespace std;
int main(){
int t[] ={ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
list<int>v(t, t+10);
multiset<int> s1(v.begin(),v.end());
if (s1.count(3) == 2) {
s1.erase(3);
}
for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
- A. program outputs: 1 1 2 2 3 4 4 5 5
- B. program outputs: 1 2 3 4 5
- C. program outputs: 1 1 2 2 3 3 4 4 5 5
- D. program outputs: 1 2 4 5
- E. compilation error
Answer: C
NEW QUESTION 125
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 t[]={3,2,4,1,5,10,9,7,8,6};
vector<int> v1(t,t+10);
cout<<*max_element(v1.begin(), v1.end());
return 0;
}
Program outputs:
- A. 0
- B. 1
- C. 2
- D. compilation error
- E. 3
Answer: C
NEW QUESTION 126
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main() {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector<int> v1(t, t + 15);
set<int> s1(t, t + 15);
pair<set<int>::iterator, vector<int>::iterator > resultSet = mismatch(s1.begin(), s1.end(), v1.begin()); cout<<*resultSet.first<<" "<<*resultSet.second<<endl; return 0;
}
Program outputs:
- A. 2 4
- B. 0 5
- C. 4 2
- D. compilation error
Answer: C
NEW QUESTION 127
What happens when you attempt to compile and run the following code? Choose all possible answers.
#include <iostream>
using namespace std;
class C {
public:
int _c;
C():_c(0){}
C(int c) { _c = c;}
C operator+=(C & b) {
C tmp; tmp._c = _c+b._c;
return tmp;
} };
ostream & operator<<(ostream & c, const C & v) {
c<<v._c; return c; }
template <class T>
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T & a) { _v+=a; }
};
int main()
{
A<int> b(2);
A<C>a (5);
a.add(C());
cout << a.getV() <<endl;
return 0;
}
- A. program will not compile
- B. program will cause runtime exception
- C. program will display:5
- D. program will compile
Answer: C,D
NEW QUESTION 128
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <deque>
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; }
};
struct Even {
bool operator ()(const A & a, const A &b) {
return (a.getA() % 2)==b.getA() % 2;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
deque<int> d (t,t+15);
deque<int>::iterator it = search_n(d.begin(), d.end(), 3, 2, Even());
cout<< it?d.begin()<<endl;
return 0;
}
Program outputs:
- A. 0
- B. 1
- C. 2
- D. compilation error
- E. 3
Answer: C
NEW QUESTION 129
What will happen when you attempt to compile and run the following code?
# include <iostream>
# include <string>
using namespace std;
template <class T>
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T & a) { _v+=a; }
};
int main()
{
A<string>a("Hello");
string s(" world!");
a.add(s);
cout << a.getV() <<endl;
return 0;
}
- A. program will not compile
- B. program will display: Hello
- C. program will run without any output
- D. program will display: Hello world!
Answer: D
NEW QUESTION 130
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <set>
#include <list>
using namespace std;
int main(){
int t[] ={ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
list<int>v(t, t+10);
multiset<int> s1(v.begin(),v.end());
if (s1.count(3) == 2) {
s1.erase(3);
}
for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
- A. program outputs: 1 1 2 2 3 4 4 5 5
- B. program outputs: 1 2 3 4 5
- C. program outputs: 1 1 2 2 3 3 4 4 5 5
- D. program outputs: 1 2 4 5
- E. compilation error
Answer: C
NEW QUESTION 131
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(s1, v1);
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. 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10
Answer: A
NEW QUESTION 132
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
void myfunction(pair<int, int> i) {
cout << " " << i.first;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map<int, int> m;
for(int i=0; i < 10; i++) {
m[i]=t[i];
}
for_each(m.begin(), m.end(), myfunction);
return 0;
}
Program outputs:
- A. 9 8 7 6 5 4 3 2 1 0
- B. 10 5 9 6 2 4 7 8 3 1
- C. compilation error
- D. 0 1 2 3 4 5 6 7 8 9
- E. 1 3 8 7 4 2 6 9 5 10
Answer: D
NEW QUESTION 133
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 134
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <deque>
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; }
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
deque<int> d (t,t+15);
int number = count(d.begin(), d.end(), 2);
cout<< number<<endl;
return 0;
}
Program outputs:
- A. 0
- B. compilation error
- C. 1
- D. 2
- E. 3
Answer: D
NEW QUESTION 135
What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?
#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 (){
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fstream f("test.out");
list<int> l(t, t+10);
for_each(l.begin(), l.end(), Out<int>(f));
f.close();
return 0;
}
- A. file test.out will be created and opened for reading
- B. file test.out will be created and opened for writing
- C. compilation error
- D. file test.out will contain sequence 1 2 3 4 5 6 7 8 9 10
- E. no file will be created nor opened
Answer: E
NEW QUESTION 136
......
Guaranteed Success with CPP Dumps: https://www.dumpstorrent.com/CPP-exam-dumps-torrent.html