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;
}
bool classifier(int v) {
return v%2==0;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector
set
replace(v1.begin(), v1.end(),classifier, 10);
for_each(v1.begin(), v1.end(), myfunction);
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() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque d1(t, t+10); sort(d1.begin(), d1.end()); deque::iterator it = upper_bound(d1.begin(), d1.end(), B(4)); for_each(it, d1.end(), Out(cout)); cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector
vector
cout<< it?v.begin()< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main ()
{
int t[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
vector
deque
deque
d2 = d1;
d2.insert(d1.rbegin(), 10);
for(int i = 0; i { cout< } 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++;
}
}
int main(){
vector
multiset
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; }
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 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_intersection(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
#include
#include
using namespace std;
template
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main() {
string t1[] ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
list
list
l2.reverse(); l1.splice(l1.end(),l2);
l1.unique();
print(l1.begin(), l1.end()); cout< return 0; }
What will happen when you attempt to compile and run the following code?
#include
using namespace std;
template
class A {
T_v;
public:
A(T v);
};
template
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector
vector
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:
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3
#include
#include
#include
using namespace std;
int main ()
{
string s;
getline(cin, s);
stringstream input(s);
stringstream output;
for( ; !input.fail() ; )
{
int i;
input>>i;
output< } cout< return 0; } Program will output:
Which method added to class B at the marked spot will allow the code below to compile? Choose all possible solutions.
#include
#include
#include
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< 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}; vector v1(t, t+10); sort(v1.begin(), v1.end(), greater()); for_each(v1.begin(), v1.end(), Out(cout));cout< 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 t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque set cout< return 0; } Choose all possible outputs (all that apply):
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[]={6,10,8,7,9}; vector v1(10); sort(t1, t1+5); sort(t2, t2+5); merge(t1,t1+5,t2,t2+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
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector
copy(t, t+10, v1.end());
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
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< bool Greater(int v1, int v2) { return v1 int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; vector sort(v1.begin(), v1.end(), Greater); for_each(v1.begin(), v1.end(), Out return 0; } Program outputs:
What will happen when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
class A
{
int a;
public:
A(int a) {this?>a = a; c++;}
~A() { c??;}
static int c;
};
int A::c(0);
int main ()
{
A t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8 , 9};
vectorv1(t, t+10);
dequed1(v1.begin(), v1.end());
deque d2;
d2 = d1;
cout< return 0; } How many objects of type A will be created:
What happens when you attempt to compile and run the following code? Choose all possible answers.
#include
using namespace std;
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
friend ostream & operator<<(ostream & c, const A
c< } }; int main() { A 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< } }; struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return start++; } }; struct Odd { bool operator()(int v) { return v%2==0; }}; int main() { vector generate(v1.begin(), v1.end(), Sequence(1)); partition(v1.begin(),v1.end(), Odd()); for_each(v1.begin(), v1.end(), Out return 0; } Choose all possible outputs:
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.insert(pair
}
if (m.count(3) == 2) {
m.erase(3);
}
for (map
cout << i?>first << " ";
}
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; }
What will happen when you attempt to compile and run the following code? Choose all that apply.
#include
#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 < (const A & b) const { return a }; class F { A val; public: F(A & v):val(v){} bool operator() (A & v) { if (v.getA() == val.getA()) return true; return false; } }; int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector v1(t, t + 10); set s1(t, t + 10); A a(6); F f(a); find_if(s1.begin(), s1.end(), f); if (find_if(v1.begin(), v1.end(), f) !=v1.end()) { cout<<"Found!\n"; } else { cout<<"Not found!\n"; } 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_symmetric_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
#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(s1, v1);
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
int main ()
{
std::vector
for(int i = 0; i<10; i++) {v1.push_back(i); }
std::vector
std::vector
for( ; it != v2.end(); it++) {std::cout<<*it++<<" "; }std::cout< 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() { string t[]={"aaa","Aaa", "aAa","aaA","bbb","Bbb", "bBb", "bbB"}; vector sort(v1.begin(), 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
class A {
public:
virtual int f() { return 10; }
virtual ~A(){}
};
class B: public A {
int f() {return 11; }
virtual ~B(){}
};
int main (){
std::vectorv1;
for(int i = 10; i>0; i??)
{
i%2>0?v1.push_back(new A()):v1.push_back(new B());
}
std::vector::iterator it = v1.begin();
while(it != v1.end())
{
std::cout<
v1.pop_back();++it;
}
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< struct Add { int operator()(int a, int b) { return a+b; } }; int main() { int t[]={1,2,3,4,5,6,7,8,9,10}; vector vector transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add()), 1)); for_each(v2.rbegin(), v2.rend(), Out return 0; } Program outputs:
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 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"};
multimap
for (int i = 0; i < 10; i++) {
m.insert(pair
}
if (m.count(3) == 2) {
m.erase(3);
}
for (multimap
cout << i?>first << " ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#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>v.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 t[]={3,2,4,1,5,10,9,7,8,6}; vector v1(t,t+10); cout<<*max_element(v1.begin(), v1.end(), greater()); cout< return 0; } Program outputs: