
2021 CPP Premium Files Test pdf - Free Dumps Collection
Get ready to pass the CPP Exam right now using our C++ Certified Exam Package
NEW QUESTION 100
What happens when you attempt to compile and run the following code?
#include <deque>
#include <vector>
#include <iostream>
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5};
vector<int>v1(t, t+5);
deque<int>d1;
d1.assign(v1.end(), v1.begin());
for(int i=0; i<d1.size(); i++)
{
cout<<d1.at(i)<<" ";
}
cout<<endl;
return 0;
}
- A. segmentation fault runtime exception
- B. compilation error in line 8
- C. compilation error in line 10
- D. program outputs 5 4 3 2 1
- E. program outputs 1 2 3 4 5
Answer: A
NEW QUESTION 101
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 102
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 103
What will happen when you attempt to compile and run the following code? Choose all possible answers.
#include <iostream>
using namespace std;
class B {};
template <typename 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> a(1);
A<B>b;
a.add(10);
cout << a.getV() <<endl;
return 0;
}
- A. program will not compile
- B. program will display:11
- C. program will cause runtime exception
- D. program will compile
Answer: B,D
NEW QUESTION 104
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;} }; 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_difference(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 5 0 0 0 0 0 0 0
- C. 3 4 0 0 0 0 0 0 0 0
- D. 6 8 0 0 0 0 0 0 0 0
- E. 1 2 3 4 5 6 8 0 0 0
Answer: A
NEW QUESTION 105
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <map>
# include <vector>
# include <string>
using namespace std;
int main(){
int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","zero"}; map<int,string> m;
for(int i=0; i<10; i++) {
m.insert(pair<int,string>(second[i],first[i]));
}
m[0]="ten";
m.insert(pair<int,string>(1,"eleven"));
for(map<int, string>::iterator i=m.begin();i!= m.end(); i++) {
cout<<i?>second<<" ";
}
return 0;
}
- A. program outputs: ten eleven two three four five six seven eight nine
- B. program outputs: zero one two three four five six seven eight nine
- C. program outputs: 0 1 2 3 4 5 6 7 8 9
- D. program outputs: zero eleven two three four five six seven eight nine
- E. program outputs: ten one two three four five six seven eight nine
Answer: E
NEW QUESTION 106
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<<" "; } }; template<typename A> struct Add : public binary_function<A, A, A> { A operator() (const A & a, const A & b) const { 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(ptr_fun (Add<B>()), 1)); 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 107
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);
sort(v1.begin(), v1.end(), greater<int>());
cout<<min_element(v1.begin(), v1.end());
return 0;
}
Program outputs:
- A. compilation error
- B. 0
- C. 1
- D. 2
- E. 3
Answer: A
NEW QUESTION 108
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 109
What will happen when you attempt to compile and run the following code? Choose all that apply.
#include <iostream>
#include <algorithm>
#include <vector>
#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; }
bool operator < (const A & b) const { return a<b.a;}
};
class F {
A val;
public:
F(A & v):val(v){}
bool operator() (A & v) {
if (v.getA() == val.getA()) return true;
return false;
}
};
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector<A> v1(t, t + 10);
set<A> s1(t, t + 10);
A a(6); F f(a);
find_if(s1.begin(), s1.end(), f);
if (find_if(v1.begin(), v1.end(), f) !=v1.end()) {
cout<<"Found!\n";
} else {
cout<<"Not found!\n";
}
return 0;
}
- A. it will display Not found!
- B. it will display Found!
- C. it will compile successfully
- D. it will not compile successfully
Answer: D
NEW QUESTION 110
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
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];
}
map<int, int>::iterator it = find(m.begin(), m.end(), 5);
cout<<it?>first;
return 0;
}
Program outputs:
- A. compilation error
- B. 0
- C. 1
- D. 2
Answer: A
NEW QUESTION 111
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;
}
- A. compilation error
- B. program outputs 55 5 17 0
- C. runtime exception
- D. program outputs 55 5 17 55
Answer: A
NEW QUESTION 112
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 = find_end (v.begin(), v.end(), m1, m1+3, Compare());
cout << "Found at position: " << it?v.begin() << endl;
return 0;
}
- A. program outputs: Found at position: 7
- B. program outputs: Found at position: 5
- C. compilation error
- D. program outputs: Found at position: 10
***/ - E. program outputs: Found at position: 0
Answer: B
NEW QUESTION 113
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):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 t[]={3,2,4,1,5,10,9,7,8,6};
vector<B> v1(t,t+10);
cout<<*max_element(v1.begin(), v1.end(), greater<B>());
cout<<endl;
return 0;
}
Program outputs:
- A. 0
- B. 1
- C. compilation error
- D. 2
- E. 3
Answer: D
NEW QUESTION 114
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 115
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 116
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 117
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 118
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[]={5,6,8,2,1};
vector<int> v1(10);
sort(t1, t1+5);
sort(t2, t2+5);
set_difference(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 5 0 0 0 0 0 0 0
- B. 6 8 0 0 0 0 0 0 0 0
- C. 1 2 3 4 5 6 8 0 0 0
- D. compilation error
- E. 3 4 0 0 0 0 0 0 0 0
Answer: E
NEW QUESTION 119
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<<" "; } };
int main() {
int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
deque<int> d1(t, t+10);
sort(d1.begin(), d1.end());
deque<int>::iterator it = upper_bound(d1.begin(), d1.end(), 4);
for_each(it, d1.end(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs:
- A. 4 5 6 7 8 9 10
- B. 1 2 3 4
- C. 1 2 3 4 5
- D. 1 2 3 4 5 6 7 8 9 10
- E. 5 6 7 8 9 10
Answer: E
NEW QUESTION 120
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector<int> v1(t, t + 10);
copy(t, t+10, v1.end());
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
- A. 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1
- B. runtime exception/segmentation fault
- C. 10 5 9 6 2 4 7 8 3 1
- D. compilation error
Answer: B
NEW QUESTION 121
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int>v(myints, myints+10);
set<int> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
- A. program outputs: 2 3 4 5 6 7
- B. program outputs: 1 6 5 7
- C. program outputs: 3 4 9 8 0
- D. program outputs: 0 1 8 9
Answer: D
NEW QUESTION 122
What will happen when you attempt to compile and run the following code?
# include <iostream>
# include <set>
# include <vector>
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int>v(t, t+10);
set<int> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
pair<set<int>::iterator,set<int>::iterator> range;
range = s1.equal_range(6);
cout<<*range.first<<" "<<*range.second<<endl;
return 0;
}
The output will be:
- A. 6 6
- B. 1 5
- C. 6 5
- D. 5 7
- E. 6 7
Answer: E
NEW QUESTION 123
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 124
......
Master 2021 Latest The Questions C++ Certified and Pass CPP Real Exam!: https://www.dumps4pdf.com/CPP-valid-braindumps.html