Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 1 / 19 Exam : CPP-22-02 Title : https://www.cert007.com/exam/cpp-22-02/ C++ Certified Professional Programmer Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 2 / 19 1 What happens 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); multiset<int> s1(v.begin(),v.end()); s1.insert(v.begin(),v.end()); pair<multiset<int>::iterator,multiset<int>::iterator> range; range = s1.equal_range(6); while (range.first != range.second) { cout<<*range.first<<" "; range.first++; } return 0; } A.program outputs: 6 6 B.program outputs: 5 7 C.program outputs: 5 5 6 6 7 7 D.program outputs: 5 5 7 7 E.program outputs: 1 1 6 6 5 5 Answer: A 2 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); generate(v1.rbegin(), v1.rend(), Sequence(1)); Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 3 / 19 rotate(v1.begin(),v1.begin() + 1, v1.end() ); 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.10 9 8 7 6 5 4 3 2 1 C.9 8 7 6 5 4 3 2 1 10 D.1 10 9 8 7 6 5 4 3 2 Answer: C 3 What happens when you attempt to compile and run the following code? #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() ; ) { B i; f>>i; cout<<i<<" "; } f.close(); return 0; } A.file test.out will be opened writing Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 4 / 19 B.file test.out will be truncated C.file test.out will be opened for reading D.compilation error E.program will display sequence 1 2 3 4 5 6 7 8 9 10 Answer: D 4 What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: one two three<enter>? #include <iostream> #include <string> using namespace std; int main () { string a; cin>>a; cout<<a<<endl; return 0; } Program will output: A.one B.one two three C.runtime exception D.compilation error E.the result is unspecified Answer: A 5 What will happen 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, 0, 3, 4, 1, 2, 0 }; vector<int> v(t, t + 10); multimap<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<multimap<int, string>::iterator, multimap<int, string>::iterator> range; range = m.equal_range(2); for (multimap<int, string>::iterator i = range.first; i != range.second; i++) { Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 5 / 19 cout << i?>first << " "; } return 0; } The output will be: A.2 2 B.1 2 C.1 3 D.2 E.0 2 Answer: A 6 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_intersection(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 8 0 0 0 C.1 2 3 4 5 6 8 2 1 0 D.5 2 1 0 0 0 0 0 0 0 E.1 2 5 0 0 0 0 0 0 0 Answer: D Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 6 / 19 7 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.program displays 5 4 3 2 1 B.program displays 1 2 3 4 5 C.compilation error D.segmentation fault runtime exception Answer: C 8 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); Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 7 / 19 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.1 2 3 4 5 6 10 8 7 9 B.3 2 4 1 5 6 7 8 9 10 C.3 2 4 1 5 6 10 8 7 9 D.1 2 3 4 5 6 7 8 9 10 E.compilation error Answer: E 9 Which sentence is correct about the code below? #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; } /* Insert Code Here */ }; struct add10 { void operator()(A & a) { a.setA(a.getA() + 10); } }; int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector<A> v1(t, t + 10); for_each(v1.begin(), v1.end(), add10()); vector<A>::iterator it = find(v1.begin(), v1.end(), A(7)); cout << it?>getA() << endl; return 0; } A.it will compile and print 7 B.it will not compile C.it will compile but the program result is unpredictable D.adding code: bool operator !=(const A & b) const { if (this?>a != b.a) { return true; } return false; } at Place 1 will allow the program to compile Answer: B 10 What happens when you attempt to compile and run the following code? Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 8 / 19 #include <iostream> #include <algorithm> #include <vector> using namespace std; void myfunction(int i) { cout << " " << i; } void multiply (int a) { a*2; } int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector<int> v1(t, t+10); for_each(v1.begin(), v1.end(), multiply); iter_swap(v1.begin(),t+9); for_each(v1.begin(), v1.end(), myfunction); return 0; } Program outputs: A.1 5 9 6 2 4 7 8 3 1 B.compilation error C.1 2 3 4 5 6 7 8 9 10 D.10 9 8 7 6 5 4 3 2 1 E.10 5 9 6 2 4 7 8 3 1 Answer: A 11 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.3 B.1 Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 9 / 19 C.6 D.10 E.compilation error Answer: D 12 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_intersection(t1,t1+5,t2,t2+5,v1.begin()); 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 8 0 0 0 C.1 2 3 4 5 6 8 2 1 0 D.1 1 2 2 3 4 5 5 6 8 E.1 2 5 0 0 0 0 0 0 0 Answer: E 13 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 }; Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 10 / 19 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: 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 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.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 D.compilation error in line I E.compilation error in line III Answer: A 14 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]; } pair<const int,int> p(5,5); map<int, int>::iterator it = find(m.begin(), m.end(), p); if (it != m.end()) { cout<<it?>first<<endl; } else { cout<<"Not found!\n"; } return 0; } Program outputs: A.5 B.Not found! C.10 D.compilation error Answer: B Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 11 / 19 15 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.10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 B.compilation error 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 10 9 8 7 6 5 4 3 2 1 Answer: B 16 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); set<int> s1(v.begin(),v.end()); if (s1.count(3) == 2) { s1.erase(3); } for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) { cout<<*i<<" "; } return 0; } Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 12 / 19 A.program outputs: 1 2 3 4 5 B.program outputs: 1 2 4 5 C.program outputs: 1 1 2 2 3 4 4 5 5 D.program outputs: 1 1 2 3 3 4 4 5 5 E.compilation error Answer: A 17 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<<" "; } }; int Add(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(), bind2nd(ptr_fun (Add),1)); vector<int>::iterator it = find_if(v2.begin(), v2.end(),bind2nd(equal_to<int>(),10)); cout<<*it<<endl; return 0; } Program outputs: A.false B.true C.10 D.0 E.compilation error Answer: C 18 What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <vector> #include <deque> using namespace std; void myfunction(int i) { Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 13 / 19 cout << " " << i; } int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; deque<int> d1(t, t+10); vector<int> v1(d1.rbegin(), d1.rend()); sort(d1.begin(), d1.end()); swap_ranges(v1.begin(), v1.end(), d1.begin()); for_each(v1.begin(), v1.end(), myfunction); for_each(d1.begin(), d1.end(), myfunction); return 0; } Program outputs: A.10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 B.compilation error 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 1 3 8 7 4 2 6 9 5 10 E.1 3 8 7 4 2 6 9 5 10 1 2 3 4 5 6 7 8 9 10 Answer: D 19 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_union(t1,t1+5,t2,t2+5,v1.begin()); for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl; return 0; } Program outputs: A.3 2 4 1 5 6 8 2 1 0 B.1 2 3 4 5 6 8 2 1 0 C.1 1 2 2 3 4 5 5 6 8 D.1 2 3 4 5 6 8 0 0 0 Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 14 / 19 E.compilation error Answer: D 20 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.3 B.1 C.6 D.10 E.compilation error Answer: E 21 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; Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 15 / 19 cin>>i; l.push_back(i); } for_each(l.begin(), l.end(), Out<int>(cout)); return 0; } Program will output: A.1 2 3 B.1 2 3 end C.1 D.compilation error E.program runs forever without output Answer: E 22 What happens when you attempt to compile and run the following code? #include <iostream> #include <set> #include <vector> using namespace std; template<class T> void print(T start, T end) { while (start != end) { std::cout << *start << " "; start++; } } int main(){ vector<int>v; multiset<int> s; for(int i=10; i>0; i??) { v.push_back(i); s.push_back(i); } print(v.begin(), v.end()); print(s.begin(), s.end());cout<<endl; return 0; } A.program outputs: 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 B.program outputs: 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1 C.program outputs: 10 9 8 7 6 5 4 3 2 1 and unpredictable sequence of numbers range 1 to 10 D.compilation error Answer: D 23 What happens when you attempt to compile and run the following code? #include <iostream> #include <map> using namespace std; int main() { Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 16 / 19 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.program outputs: 1 2 3 4 5 B.compilation error C.program outputs: 1 1 2 2 3 3 4 4 5 5 D.program outputs: one two three four five E.program outputs: one one two two three three four four five five Answer: B 24 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.5 6 7 8 9 10 B.4 5 6 7 8 9 10 C.compilation error Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 17 / 19 D.1 2 3 4 5 E.1 2 3 4 Answer: C 25 Which stack initialization (line numbers) are correct? Choose all that apply. #include <iostream> #include <deque> #include <list> #include <stack> #include <vector> using namespace std; int main() { deque<int> mydeck; list<int> mylist; vector<int> myvector; stack<int> first;// Line I stack<int> second(mydeck);// Line II stack<int> third(second);// Line III stack<int, list<int> > fourth(mylist);// Line IV stack<int, vector<int> > fifth(myvector);// Line V return 0; } A.line I B.line II C.line III D.line IV E.line V Answer: A,B,C,D,E 26 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<<" "; } }; Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 18 / 19 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.5 6 7 8 9 10 B.4 5 6 7 8 9 10 C.6 7 8 9 10 D.1 2 3 4 5 E.1 2 3 4 Answer: A 27 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.6 8 3 4 0 0 0 0 0 0 B.3 4 0 0 0 0 0 0 0 0 C.6 8 0 0 0 0 0 0 0 0 Pass C++ Institute CPP-22-02 Exam | Latest CPP-22-02 Dumps & Practice Exams - Cert007 19 / 19 D.compilation error E.3 4 6 8 0 0 0 0 0 0 Answer: E 28 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<<" "; } }; int main() { int t[]={3,2,4,1,5,6,10,8,7,9}; vector<int> v1(t, t+10); for_each(v1.begin(), v1.end(), bind2nd(plus<int>(), 1)); for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl; return 0; } Program outputs: A.3 2 4 1 5 6 10 8 7 9 B.4 3 5 2 6 7 11 9 8 10 C.9 7 8 10 6 5 1 4 2 3 D.10 8 9 11 7 6 2 5 3 4 E.compilation error Answer: C