What happens when you attempt to compile and run the following code?
 #include 
#include
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};
 map
for (int i = 0; i < 10; i++) {
 m.push_back(pair
}
 for (map
cout << i?>first << " ";
}
return 0;
}
What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?
 #include 
 #include 
 #include 
 #include 
 #include 
using namespace std;
 template
ostream & out;
Out(ostream & o): out(o){}
 void operator() (const T & val ) {out<    int main () {  ifstream f("test.in");  list  for( ; f.good() ; )  {   int i;   f>>i;   l.push_back(i);  }  f.close();  for_each(l.begin(), l.end(), Out  return 0;  } Program will output:
Which sentence is correct about the code below?
 #include 
 #include 
 #include 
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; }
void setA(int a) { this?>a = a; }
/* Insert Code Here */
};
struct add10 { void operator()(A & a) { a.setA(a.getA() + 10); } };
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector v1(t, t + 10);
for_each(v1.begin(), v1.end(), add10());
vector::iterator it = find(v1.begin(), v1.end(), A(7));
cout << it?>getA() << endl;
return 0;
}
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
 template
while (start != end) {
std::cout << *start << " "; start++;
}
}
class A {
int a;
public:
A(int a):a(a){}
operator int () const { return a;}int getA() const { return a;}
};
struct R {
int val;
R(int v):val(v){}
bool operator ()(const A & a) { return a>val;} };
int main() {
int t1[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
list l1(t1, t1 + 10);
R r(4);l1.remove_if(r);
 print(l1.begin(), l1.end()); cout<  return 0;  }
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
 template
ostream & out;
Out(ostream & o): out(o){}
 void operator() (const T & val ) { out<    int main() {  int t1[]={3,2,4,1,5};  int t2[]={5,6,8,2,1};  vector  sort(t1, t1+5);  sort(t2, t2+5);  set_union(t1,t1+5,t2,t2+5,v1.begin());  for_each(v1.begin(), v1.end(), Out  return 0;  } Program outputs:
What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?
 #include 
 #include 
 #include 
 #include 
 #include 
using namespace std;
 template
ostream & out;
Out(ostream & o): out(o){}
 void operator() (const T & val ) {out<    int main () {  ifstream f("test.in");  list  for( ; !f.fail() ; ) {   int i;   f>>i;   l.push_back(i);  }  f.close();  for_each(l.begin(), l.end(), Out  return 0;  } Programwill output:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
 #include 
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
 set
 vector
swap_ranges(s1.begin(), s1.end(), v1.begin());
for_each(v1.begin(), v1.end(), myfunction);
for_each(s1.begin(), s1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
#include
 #include 
 #include 
 #include 
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
 vector
 map
 for(vector
 stringstream s; s<<*i<<*i; m.insert(pair
}
 for(map
cout<<*i<<" ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
 deque
int number = count(d.begin(), d.end(), 2);
 cout<< number<  return 0;  } Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
 #include 
 #include 
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
 vector
 deque
 set
for_each(v1.begin(), v1.end(), myfunction); // Line I
for_each(d1.begin(), d1.end(), myfunction); // Line II
for_each(s1.begin(), s1.end(), myfunction); // Line III
return 0;
}
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
 #include 
using namespace std;
 template
ostream & out;
Out(ostream & o): out(o){}
 void operator() (const T & val ) { out<    int main() {  int t1[]={3,2,4,1,5};  int t2[]={6,10,8,7,9};  vector  transform(t1,t1+5,t2,v1.rbegin(), plus  for_each(v1.rbegin(), v1.rend(), Out  return 0;  } Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
using namespace std;
 template 
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
 template 
U get(U a) {
return (U)(_v);
}
};
int main()
{
 A
a.add(10);
cout.setf( ios::showpoint);
 cout << a.getV() << " " << a.get(1.0)<  return 0;  }
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
class A {
int a;
public:
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 v (t,t+10);
vector::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:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
 #include 
using namespace std;
 void print(int v) {  cout<  struct Sequence {  int start;  Sequence(int start):start(start){}  int operator()() { return start++; }  };  bool predicate(int v) { return v%2==0; }  int main() {  vector  generate_n(v1.begin(), 10, Sequence(1));  set  remove_if(s1.begin(), s1.end(), predicate);  for_each(s1.begin(), s1.end(), print);cout<  return 0;  } Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
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  ostream & operator <<(ostream & out, const B & v) { out<  template  ostream  & out;  Out(ostream & o): out(o){}  void operator() (const T & val ) { out<    int main() {  B t1[]={3,2,4,1,5};  B t2[]={5,6,8,2,1};  vector v1(10,0);  sort(t1, t1+5);  sort(t2, t2+5);  set_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin());  for_each(v1.begin(), v1.end(), Out(cout));cout<  return 0;  } Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
 #include 
 #include 
using namespace std;
struct display {
void operator() (int i) {cout << " " << i;}
};
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
 vector
 deque
 set
for_each(v1.begin(), v1.end(), display); //Line I
for_each(d1.begin(), d1.end(), *(new display())); // Line II
for_each(s1.begin(), s1.end(), display()); // Line III
return 0;
}
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
 template
ostream & out;
Out(ostream & o): out(o){}
 void operator() (const T & val ) { out<    int main() {  int t1[]={3,2,4,1,5};  int t2[]={5,6,8,2,1};  vector  sort(t1, t1+5);  sort(t2, t2+5);  set_difference(t1,t1+5,t2,t2+5,v1.begin());  for_each(v1.begin(), v1.end(), Out  return 0;  } Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout<<100<<" ";
cout.unsetf(ios::hex);
cout<<100<<" ";
return 0;
}
Program outputs:
What will happen when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
int main(){
int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
 set
 multiset
s1.insert(s.begin(),s.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
 for(multiset
cout<<*i<<" ";
}
return 0;
}
The output will be:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
 template
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] ={ 1, 7, 8, 4, 5 };
 list
int t2[] ={ 3, 2, 6, 9, 0 };
 deque
l1.sort();
d1.sort();
l1.merge(d1);
print(l1.begin(), l1.end());
 print(d1.begin(), d2.end()); cout<  return 0;  }
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;} };
 ostream & operator <<(ostream & out, const B & v) { out<    template  ostream  & out;  Out(ostream & o): out(o){}  void operator() (const T & val ) { out<    int main() {  B t1[]={3,2,4,1,5};  B t2[]={6,10,8,7,9};  vector v1(5);  transform(t1,t1+5,t2,v1.rbegin(), plus());  for_each(v1.rbegin(), v1.rend(), Out  return 0;  } Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
using namespace std;
bool mycomparison (int first, int second){return first>second;}
 template
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] ={ 1, 7, 8, 4, 5 };
 list
int t2[] ={ 3, 2, 6, 9, 0 };
 list
l1.sort(mycomparison);
l2.sort(mycomparison);
l1.merge(l2,mycomparison);
print(l1.begin(), l1.end());
 print(l2.begin(), l2.end()); cout<  return 0;  }
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
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  ostream & operator <<(ostream & out, const B & v) { out<  template  ostream  & out;  Out(ostream & o): out(o){}  void operator() (const T & val ) { out<  int main() {  int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};  set s1(t, t+10);  sort(s1.begin(), s1.end());  for_each(s1.begin(), s1.end(), Out(cout));cout<  return 0;  } Program outputs:
What will be output of the program when you attempt to compile and run the following code?
 #include 
#include
 #include 
 #include 
using namespace std;
int main(){
int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","zero"};
 multimap
for(int i=0; i<10; i++) {
 m.insert(pair
}
m[0]="ten";
 m.insert(pair
 for(multimap
cout<second<<" ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
bool compare(int a, int b) { return a == b; }
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
 vector
 vector
int m1[] = {1, 2, 3};
while ( (it = find_first_of (it, v.end(), m1, m1+3)) != v.end()) {
 cout<  }  cout<< endl;  return 0;  }
What will happen when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
 template
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main(){
 vector
 set
for(int i=10; i>0; i??) {
v.push_back(i);
s.push_back(i);
}
 print(v.begin(), v.end()); print(s.begin(), s.end());cout<  return 0;  } The output will be:
Which changes introduced independently will allow code to compile and display 0 1 8 9 (choose all that apply)
 #include 
 #include 
 #include 
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 };
vectorv(t, t+10);
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set::iterator i=s1.begin();i!= s1.end(); i++) {
cout<getA()<<" ";
}
 cout<  return 0;  }
What happens when you attempt to compile and run the following code?
 #include 
#include
 #include 
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"};
 map
for(int i=0; i<10; i++) {
 m.insert(pair
}
if (m[11] == "eleven") {
cout<<"eleven ";
}
 for(map
cout<second<<" ";
}
 cout<  return 0;  }
Which keywords can be used to define template type parameters? Choose all possible answers:
What will happen when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
 vector
 set
s1.insert(v.begin(),v.end());
 pair
range = s1.equal_range(6);
 cout<<*range.first<<" "<<*range.second<  return 0;  } The output will be:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
int main(){
int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
 vector
 set
 set
 for(set
cout<<*i<<" ";
}
 for(set
cout<<*i<<" ";
}
 cout<  return 0;  }  
What will happen when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
 vector
 multiset
 multiset
 for(multiset
cout<<*i<<" ";
}
 for(multiset
cout<<*i<<" ";
}
 cout<  return 0;  } The output will be:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
 #include 
using namespace std;
 template
ostream & out;
Out(ostream & o): out(o){}
 void operator() (const T & val ) { out<  int main() {  int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};  deque  sort(d1.begin(), d1.end());  deque  for_each(it, d1.end(), Out  return 0;  } Program outputs:
What happens when you attempt to compile and run the following code?
 #include 
 #include 
using namespace std;
 template 
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T & a);
void add(string & a);
};
 template
 void A
 void A
_v.insert(0, a);
}
int main()
{
 A
string s(" world!");
a.add(s);
 cout << a.getV() <  return 0;  }