Free Practice C++ Institute CPP-22-02 Exam Questions 2025

Stay ahead with 100% Free CPP - C++ Certified Professional Programmer CPP-22-02 Dumps Practice Questions

Page:    1 / 46      
Total 230 Questions | Updated On: Jan 26, 2025
Add To Cart
Question 1

What happens when you attempt to compile and run the following code?
 #include <iostream>
 #include <algorithm>
 #include <vector>
 using namespace std;
 class A {
 int apublic:
 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:


Answer: B
Question 2

What happens when you attempt to compile and run the following code?
 #include <deque>
 #include <iostream>
 #include <algorithm>
 #include <set>
 using namespace std;
 template<class T>struct Out {
 ostream & out;
 Out(ostream & o): out(o){}
 void operator() (const T & val ) { out<<val<<" "; }
 };
 bool Compare(char a, char b) { return tolower(a) < tolower(b);}
 int main() {
 char s[]={"qwerty"};
 char t1[]={"ert"};
 char t2[]={"ERT"};
 sort(s, s+6);
 cout<<includes(s,s+6, t1,t1+3, Compare)<<" "<<includes(s,s+6, t2,t2+3, Compare)<<endl;
 return 0;
 }
Program outputs:


Answer: D
Question 3

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<<" "; } };
 struct Sequence {
 int start;
 Sequence(int start):start(start){}
 int operator()() { return start++; } };
 int main() {
 vector<int> v1(10);
 generate_n(v1.begin(), 10, Sequence(1));
 random_shuffle(v1.rbegin(), v1.rend());
 sort(v1.begin(), v1.end(), great<int>());
 for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl;
 return 0;
 }
Program outputs:


Answer: C
Question 4

What happens when you attempt to compile and run the following code?
 #include <deque>
 #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() {
 int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};
 deque<B> d1(t, t+10);
 sort(d1.begin(), d1.end(), greater<B>());
 pair<deque<B> ::iterator, deque<B>::iterator > result = equal_range(d1.begin(), d1.end(),
B(20), greater<B>());
 for_each(result.first, result.second, Out<B>(cout));cout<<endl;
 return 0;
 }
Program outputs:


Answer: B
Question 5

What happens when you attempt to compile and run the following code?
 #include <iostream>
 #include <map>
 #include <string>
 using namespace std;
 int main(){
 int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
 string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};
 multimap<int,string> m;
 for(int i=0; i<10; i++) {
 m.insert(pair<int,string>(second[i],first[i]));
 }
 if (m[11] == "eleven") {
 cout<<"eleven ";
 }
 for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++) {
 cout<<i?>second<<" ";
 }cout<<m.size();
 return 0;
 }


Answer: A
Page:    1 / 46      
Total 230 Questions | Updated On: Jan 26, 2025
Add To Cart

© Copyrights TheExamsLab 2025. All Rights Reserved

We use cookies to ensure your best experience. So we hope you are happy to receive all cookies on the TheExamsLab.