×

Special Offer! Sale of the Month | Extra 20% OFF - Ends In Coupon code: TEL20

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: Apr 23, 2025
Add To Cart
Question 1

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:


Answer: A
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 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;
 }


Answer: A
Question 4

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:


Answer: A
Question 5

What happens when you attempt to compile and run the following code?
 #include <vector>
 #include <iostream>
 #include <algorithm>
 using namespace std;
 template<typename T>class B { T val;
 public:
 B(T v):val(v){}
 T getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} };
 template<class T>ostream & operator <<(ostream & out, const B<T> & 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<<" "; } };
 bool Less(const B<float> &a, const B<float> &b) { return int(a.getV())<int(b.getV());}
 int main() {
 float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};
 vector<B<float> > v1; v1.assign(t, t+10);
 stable_sort(v1.begin(), v1.end(), Less);
 for_each(v1.begin(), v1.end(), Out<B<float> >(cout));cout<<endl;
 return 0;
 }
Program outputs:


Answer: A
Page:    1 / 46      
Total 230 Questions | Updated On: Apr 23, 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.