Free Cheat-test Samples and Demo Questions Download
Adobe exams Adobe
Apple exams Apple
Avaya exams Avaya
Check Point exams Check Point
Cisco exams Cisco
Citrix exams Citrix
CIW exams CIW
CompTIA exams CompTIA
CWNP exams CWNP
EC-Council exams EC-Council
EMC exams EMC
Exin exams Exin
Fortinet exams Fortinet
GIAC exams GIAC
Hitachi exams Hitachi
HP exams HP
IBM exams IBM
Isaca exams Isaca
ISC exams ISC
ISEB exams ISEB
Juniper exams Juniper
LPI exams LPI
McAfee exams McAfee
Microsoft exams Microsoft
Oracle exams Oracle
PMI exams PMI
Riverbed exams Riverbed
SNIA exams SAP
Sun exams SAS
Symantec exams Symantec
VMware exams VMware
All certification exams

C++ Institute CPP Exam - Cheat-Test.com

Free CPP Sample Questions:

Q: 1
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
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> v1(t, t + 15);
set<int> s1(t, t + 15);
pair<set<int>::iterator, vector<int>::iterator > resultSet = mismatch(s1.begin(), s1.end(),
v1.begin());
cout<<*resultSet.first<<" "<<*resultSet.second<<endl;
return 0;
}
Program outputs:
A. 2 4
B. 4 2
C. 0 5
D. compilation error
Answer: B

Q: 2
Which changes introduced independently will allow the code to compile and display 0 0 1 1 8 8 9 9 (choose all that apply)?
#include <iostream>
#include <set>
#include <vector>
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(){
A t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
set<A>s(t, t+10);/* Replace Code Here 3 */
multiset<A> s1(s.begin(),s.end());/* Replace Code Here 4 */
s1.insert(s.begin(),s.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
multiset<A>::iterator i=s1.begin();/* Replace Code Here 5 */
for( ;i!= s1.end(); i++)
{
cout<<i?>getA()<<" ";
}
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 set<A, R>s(t, t+10);
replacing line marked 4 with multiset<A,R> s1(s.begin(),s.end());
replacing line marked 5 with multiset<A,R>::iterator i=s1.begin();
Answer: A,B,D

Q: 3
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);
deque<int>::iterator it = lower_bound(d1.begin(), d1.end(), 4);
for_each(it, d1.end(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs:
A. 8 10 5 1 4 6 2 7 9 3
B. 4 5 6 7 8 9 10
C. 1 2 3 4 5 6 7 8 9 10
D. compilation error
E. 1 2 3 4
Answer: A

Q: 4
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. file test.out will be opened writing
B. file test.out will be truncated
C. file test.out will be opened for reading
D. no file will be created nor opened
E. program will display sequence 1 2 3 4 5 6 7 8 9 10
Answer: A,B,C,E

Q: 5
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 t[]={3,2,4,1,5,10,9,7,8,6};
vector<B> v1(t,t+10);
sort(v1.begin(), v1.end(), greater<B>());
cout<<*min_element(v1.begin(), v1.end());
return 0;
}
Program outputs:
A. 3
B. 1
C. 6
D. 10
E. compilation error
Answer: E

Q: 6
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 64 100<enter>?
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
int main ()
{
string s;
getline(cin, s);
stringstream input(s);
stringstream output;
for( ; !input.fail() ; )
{
int i;
input>>hex>>i;
output<<setw(4)<<i;
}
cout<<output.str();
return 0;
}
What will be the result assuming that user will enter following sequence: 64 100:
A. 64 100
B. 100 256
C. 100 256 256
D. 0x64 0x100
E. 0x100 0x256 0x256
Answer: C

Q: 7
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));
for_each(v2.rbegin(), v2.rend(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs:
A. 1 2 3 4 5 6 7 8 9 10
B. 2 3 4 5 6 7 8 9 10 11
C. 10 9 8 7 6 5 4 3 2 1
D. 11 10 9 8 7 6 5 4 3 2
E. compilation error
Answer: D

Q: 8
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:
A. 8 10 5 1 4 6 2 7 9 3
B. 1 2 3 4 5 6 7 8 9 10
C. compilation error
D. 10 9 8 7 6 5 4 3 2 1
Answer: C

Q: 9
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
void myfunction(pair<int, int> i) {
cout << " " << i.first;
}
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];
}
for_each(m.begin(), m.end(), myfunction);
return 0;
}
Program outputs:
A. 10 5 9 6 2 4 7 8 3 1
B. 0 1 2 3 4 5 6 7 8 9
C. 9 8 7 6 5 4 3 2 1 0
D. 1 3 8 7 4 2 6 9 5 10
E. compilation error
Answer: B

Q: 10
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout<<true<<" "<<boolalpha<<false;
return 0;
}
Program outputs:
A. true false
B. 1 0
C. 1 false
D. true 0
E. compilation error
Answer: C


© 2014 Cheat-Test.com, All Rights Reserved