
[Sep-2021] Pass CPP Exam in First Attempt UpdatedCPP Actual4Labs Exam Question
C++ Certified Dumps CPP Exam for Full Questions - Exam Study Guide
NEW QUESTION 34
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() {
int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
vector<B> v1(t, t+10);
sort(v1.begin(), v1.end(), greater<B>());
for_each(v1.begin(), v1.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 35
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1.1 2.2 3.3<enter>?
# include <iostream>
# include <string>
using namespace std;
int main ()
{
int a,b,c;
cin>>a>>b>>c;
cout<<a<<b<<c<<endl;
return 0;
}
Program will output:
- A. 0
- B. 1.12.23.3
- C. none of these
- D. 1.1 2.2 3.3
- E. 1 2 3
Answer: C
NEW QUESTION 36
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout<<100<<" ";
cout.flags(ios::showbase);
cout<<100<<" ";
return 0;
}
Program outputs:
- A. 0x64 0x64
- B. 64 64
- C. compilation error
- D. 64 100
- E. 64 0x64
Answer: D
NEW QUESTION 37
What happens when you attempt to compile and run the following code?
# include <string>
# include <list>
# include <iostream>
using namespace std;
template<class T> void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main() {
string t1[] ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
list<string> l1(t1, t1 + 10);
list<string> l2(l1);
l2.reverse(); l1.splice(l1.end(),l2);
l1.unique();
print(l1.begin(), l1.end()); cout<<endl;
return 0;
}
- A. program outputs: 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
- B. program outputs: 1 2 3 4 5 6 7 8 9 10
- C. program outputs: 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
- D. compilation error
Answer: A
NEW QUESTION 38
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, 3, 2};
it = find_first_of (v.begin(), v.end(), m1, m1+3);
cout << "First found at position: " << it?v.begin() << endl;
return 0;
}
- A. program outputs: First found at position: 10
- B. program outputs: First found at position: 6
- C. program outputs: First found at position: 5
- D. program outputs: First found at position: 1
- E. program outputs: First found at position: 0
Answer: E
NEW QUESTION 39
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 40
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());
bool found = s1.find(7);
if (found){
cout<<"Element found!\n";
}else {
cout<<"Element not found!\n";
}
return 0;
}
- A. changing type of variable found to int will make this code compile
- B. code will not compile
- C. program will display "Element found!"
- D. program will display "Element not found!\n"
Answer: B
NEW QUESTION 41
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;
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);
deque<int> d1(t, t + 10);
set<int> s1(t, t + 10);
for_each(v1.begin(), v1.end(), myfunction); // Line I
for_each(d1.begin(), d1.end(), myfunction); // Line II
for_each(s1.begin(), s1.end(), myfunction); // Line III
return 0;
}
- A. program outputs: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
- B. program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1
- C. compilation error in line III
- D. program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 1 2 3 4 5 6 7 8 9 10
- E. compilation error in line I
Answer: D
NEW QUESTION 42
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;
}
- A. place 1: operator int() { return a; }
- B. 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;} - C. place 1: operator int() { return a; }
bool operator < (const A & b) { return this?>a< b.a;} - D. 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;} - E. place 1: bool operator < (const A & b) { return this?>a< b.a;}
Answer: A,C,D
NEW QUESTION 43
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){} B(){}
int getV() const {return 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); deque<B>::iterator it = lower_bound(d1.begin(), d1.end(), 4); 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. 8 10 5 1 4 6 2 7 9 3
- D. 1 2 3 4
- E. 1 2 3 4 5 6 7 8 9 10
Answer: A
NEW QUESTION 44
What happens when you attempt to compile and run the following code?
# include <list>
# include <vector>
# include <iostream>
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5};
vector<int>v1(t, t+5);
list<int>l1;
l1.assign(v1.end(), v1.begin());
for(int i=0; i<l1.size(); i++)
{
cout<<l1.at(i)<<" ";
}
cout<<endl;
return 0;
}
- A. compilation error
- B. program displays 5 4 3 2 1
- C. program displays 1 2 3 4 5
- D. segmentation fault runtime exception
Answer: A
NEW QUESTION 45
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;
}
- A. bool operator < (const A & b) const { return b.a<a;} inserted at Place 1
- B. 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();
- C. operator int() const { return a;} inserted at Place 1
- D. bool operator < (const A & b) const { return a<b.a;} inserted at Place 1
Answer: B,C,D
NEW QUESTION 46
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 47
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 48
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 49
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 50
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;}
operator int () const { return val;} };
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,6,10,8,7,9};
vector<B> v1(t, t+10);
for_each(v1.begin(), v1.end(), bind1st(plus<B>(), 1));
for_each(v1.rbegin(), v1.rend(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
- A. 10 8 9 11 7 6 2 5 3 4
- B. 4 3 5 2 6 7 11 9 8 10
- C. 9 7 8 10 6 5 1 4 2 3
- D. compilation error
- E. 3 2 4 1 5 6 10 8 7 9
Answer: C
NEW QUESTION 51
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));
for_each(it, d1.end(), Out<B>(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. 6 7 8 9 10
- E. 5 6 7 8 9 10
Answer: E
NEW QUESTION 52
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 53
What happens when you attempt to compile and run the following code? Choose all that apply.
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <algorithm>
#include <iomanip>
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<<setw(3)<<hex<<val; } };
int main () {
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fstream f("test.out", ios::trunc|ios::out);
list<B> l(t, t+10);
for_each(l.begin(), l.end(), Out<B>(f));
f.close();
f.open("test.out");
for( ; f.good() ; ) {
int i;
f>>i;
cout<<i<<" ";
}
f.close();
return 0;
}
- A. no file will be created nor opened
- B. file test.out will be opened for reading
- C. file test.out will be truncated
- D. program will display sequence 1 2 3 4 5 6 7 8 9 10
- E. file test.out will be opened writing
Answer: B,C,D,E
NEW QUESTION 54
......
Authentic Best resources for CPP Online Practice Exam: https://www.actual4labs.com/c-plus-plus-institute/CPP-actual-exam-dumps.html