What happens when you attempt to compile and run the following code?
#include
#include
#include <algorithm>
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
int t[]={3,2,4,1,5,6,10,8,7,9};
vector
for_each(v1.begin(), v1.end(), bind1st(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
int main ()
{
std::vector
for(int i = 10; i>0; i??)
{
v1.push_back(i);
}
std::vector
int sum = 0;
while(it != v1.end())
{
sum+=it++;
}
std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<<sum <<std::endl;
return 0;
}
What happens when you attempt to compile and run the following code? Choose all that apply.
#include
#include
#include
#include
#include <algorithm>
#include
using namespace std;
template
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
for_each(l.begin(), l.end(), Out
f.close(); f.open("test.out");
for( ; f.good() ; ) {
int i; f>>i;
cout<<i<<" ";
}
f.close();
return 0;
}
Which method added to class B at the marked spot will allow the code below to compile? Choose all possible solutions.
#include
#include
#include <algorithm>
using namespace std;
class B { int val;
public:
B(int v):val(v){}
int getV() const {return val;}
/* Insert Code Here */
};
ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}
template
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};
vector v1(t, t+10);
sort(v1.begin(), v1.end(), greater());
for_each(v1.begin(), v1.end(), Out(cout));cout<<endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include <algorithm>
#include
using namespace std;
template
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
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 <algorithm>
#include
using namespace std;
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map
for(int i=0; i < 10; i++) {
m[i]=t[i];
}
pair
map
if (it != m.end())
{
cout<<it?>first<<endl;
}
else
{
cout<<"Not found!\n";
}
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include <algorithm>
using namespace std;
template
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
sort(t1, t1+5); sort(t2, t2+5);
copy(t1,t1+5,v1.begin());
copy(t2,t2+5,v1.begin()+5);
merge(v1.begin(), v1.begin()+5,v1.end());
for_each(v1.begin(), v1.end(), Out
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include <algorithm>
#include
using namespace std;
template
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
set
cout<<binary_search(s1.begin(),s1.end(), 4)<<" "<<binary_search(d1.begin(),d1.end(), 4)<<endl;
return 0;
}
Choose all possible outputs (all that apply):