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
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;
}
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;
}
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:
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;
}
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;
}
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:
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:
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:
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;
}
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;
}
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:
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:
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;
}
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:
Answer : A
Have any questions or issues ? Please dont hesitate to contact us