C++ Certified Professional Programmer v6.0

Page:    1 / 16   
Exam contains 228 questions

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:

  • A. 0 0
  • B. 0 1
  • C. 1 0
  • D. 1 1


Answer : D

What happens when you attempt to compile and run the following code?
#include <vector>
using namespace std;
int main ()
{
std::vector<int>v1;
v1.push_back(10);
return 0;
}

  • A. compilation fails due to error in line 2
  • B. compilation fails due to error in line 5
  • C. exception is thrown during run time
  • D. code compiles and executes successfully


Answer : D

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. program will display "Element found!"
  • B. program will display "Element not found!\n"
  • C. code will not compile
  • D. changing type of variable found to int will make this code compile


Answer : C

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;
}
bool classifier(int v) {
return v%2==0;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector<int> v1(t, t+10);
set<int> s1(t, t+10);
replace(v1.begin(), v1.end(),classifier, 10);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:

  • A. 1 5 10 5 10 10 10 3 3 1
  • B. 1 5 2 5 2 4 4 3 3 1
  • C. compilation error
  • D. 10 10 2 10 2 4 4 10 10 10


Answer : C

What happens when you attempt to compile and run the following code?
#include <deque>
#include <list>
#include <iostream>
using namespace std;
int main ()
{
list<int>l1;
deque<int>d1;
for(int i=0; i<5; i++)
{
l1.push_back(i);l1.push_front(i);
d1.push_back(i);d1.push_front(i);
}
for(int i=0; i<d1.size(); i++)
{
cout<<d1[i]<<" "<<l1[i]<<" ";
}
cout<<endl;
return 0;
}

  • A. program displays 4 4 3 3 2 2 1 1 0 0 0 0 1 1 2 2 3 3 4 4
  • B. runtime exception
  • C. compilation error due to line 11
  • D. compilation error due to line 12
  • E. compilation error due to line 16


Answer : E

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[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
vector<int> v1(t, t + 10);
deque<int> d1(v1.begin(), v1.end());
deque<int> d2;
d2 = d1;
d2.insert(d1.rbegin(), 10);
for(int i = 0; i<d1.size(); i++)
{
cout<<d1[i]<<" ";
}
return 0;
}

  • A. program outputs: 0 1 2 3 4 5 6 7 8 9 10
  • B. program outputs: 10 0 1 2 3 4 5 6 7 8 9
  • C. program outputs: 0 1 2 3 4 5 6 7 8 9
  • D. compilation error


Answer : D

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout<<100<<" ";
cout.setf(ios::hex);
cout<<100<<" ";
return 0;
}
Program outputs:

  • A. 100 64
  • B. 100 0x64
  • C. 0x64 0x64
  • D. 64 0x64
  • E. 100 100


Answer : E

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. 64 64
  • B. 64 0x64
  • C. 0x64 0x64
  • D. 64 100
  • E. compilation error


Answer : D

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,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector<int> v (t,t+15);
vector<int>::iterator it = search_n(v.begin(), v.end(), 4, 2); cout<< it?v.begin()<<endl; return 0;
}
Program outputs:

  • A. 10
  • B. 3
  • C. 1
  • D. 15
  • E. compilation error


Answer : D

What happens when you attempt to compile and run the following code?
#include <deque>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
template<typename T>
void print(T start, T end)
{
while (start != end)
cout<<*start++;
}
int main ()
{
string t[] = {"one", "two" ,"three" ,"four", "five"};
vector<string>v1(t, t+5);
deque<string>d1(v1.rbegin(), v1.rend());
d1.push_back("zero");
print(d1[0].rbegin(),d1[0].rend());
return 0;
}

  • A. program outputs: orez
  • B. program outputs: evif
  • C. compilation error
  • D. program outputs: five


Answer : B

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: operator int() { return a; } bool operator < (const A & b) { return this?>a< b.a;}
  • C. place 1: 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;} place 2: ostream & operator <<(ostream & c, const A & a) { c<<a.a; return c;}


Answer : ABD

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, 2, 3};
it = search (v.begin(), v.end(), m1, m1+3);
cout << "found at position: " << it?v.begin() << endl; return 0;
}
Program outputs:

  • A. found at position: 5
  • B. found at position: 0
  • C. found at position: 6
  • D. found at position: 1
  • E. found at position: 10


Answer : B

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<<" "; } }; struct Sequence { int start;
Sequence(int start):start(start){}
int operator()() {return 10*(1+(start++ %3));}
};
int main() {
deque<int> d1(10);
generate(d1.begin(), d1.end(), Sequence(1));
sort(d1.begin(), d1.end());
pair<deque<int>::iterator, deque<int>::iterator > result = equal_range(d1.begin(), d1.end(),
20);
for_each(result.first, result.second, Out<int>(cout));cout<<endl; return 0;
}
Program outputs:

  • A. 10 10 10 20 20 20 20 30 30 30
  • B. 20 20 20 20
  • C. 10 20 20 20 20
  • D. 20 20 20 20 30
  • E. 10 20 20 20 20 30


Answer : B

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. operator int() const { return a;} inserted at Place 1
  • B. bool operator < (const A & b) const { return a<b.a;} inserted at Place 1
  • C. bool operator < (const A & b) const { return b.a<a;} inserted at Place 1
  • D. 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();


Answer : ABD

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 t1[]={3,2,4,1,5}; int t2[]={6,10,8,7,9}; vector<int> v1(5); transform(t1,t1+5,t2,v1.rbegin(), plus<int>()); for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl; return 0;
}
Program outputs:

  • A. 9 12 12 8 14
  • B. 14 8 12 12 9
  • 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 : A

Page:    1 / 16   
Exam contains 228 questions

Talk to us!


Have any questions or issues ? Please dont hesitate to contact us

Certlibrary.com is owned by MBS Tech Limited: Room 1905 Nam Wo Hong Building, 148 Wing Lok Street, Sheung Wan, Hong Kong. Company registration number: 2310926
Certlibrary doesn't offer Real Microsoft Exam Questions. Certlibrary Materials do not contain actual questions and answers from Cisco's Certification Exams.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Certlibrary. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.
Terms & Conditions | Privacy Policy