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:
A. 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10
B. compilation error
C. 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
D. 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
E. 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1
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: A. 1 3 5 7 9 6 7 8 9 10 B. 1 3 5 7 9 C. 2 4 6 8 10 D. compilation error
What happens when you attempt to compile and run the following code?
#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 };
list
l1.sort();
list
it++; it++;
l1.splice(l1.end(),l2, it, l2.end());
print(l1.begin(), l1.end()); cout<<"Size:"< print(l2.begin(), l2.end()); cout<<"Size:"< return 0; } A. program outputs: 1 4 5 7 8 6 9 0 Size:8 3 2 Size:2 B. program outputs: 1 4 5 7 8 6 9 0 Size:8 3 2 6 9 0 Size:5 C. compilation error D. program outputs: 0 1 4 5 6 7 8 9 Size:8 3 2 Size:2 E. program outputs: 0 1 4 5 6 7 8 9 Size:8 3 2 6 9 0 Size:5
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;
}
A. program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 1 2 3 4 5 6 7 8 9 10
B. program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1
C. compilation error in line I
D. compilation error in line II
E. compilation error in line III
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 and v) const { return val ostream and operator <<(ostream and out, const B and v) { out< template ostream and out; Out(ostream and o): out(o){} void operator() (const T and 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()); for_each(v1.begin(), v1.end(), Out(cout));cout< } 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
Which keywords can be used to define template type parameters? Choose all possible answers:
A. class
B. typedef
C. typename
D. static
E. volatile
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
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set
cout<<*i<<" ";
}
return 0;
}
A. program outputs: 0 1 8 9
B. program outputs: 2 3 4 5 6 7
C. program outputs: 1 6 5 7
D. program outputs: 3 4 9 8 0
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
ostream and out;
Out(ostream and o): out(o){}
void operator() (const T and val ) { out< struct Add { int operator()(int and a, int and 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(Add(),1)); for_each(v2.rbegin(), v2.rend(), Out 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
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream and out;
Out(ostream and o): out(o){}
void operator() (const T and val ) { out< struct Add : public binary_function int operator() (const int and a, const int and b) const { return a+b; } }; int main() { int t[]={1,2,3,4,5,6,7,8,9,10}; deque deque transform(d1.begin(), d1.end(), d2.begin(), bind2nd(Add(), 1)); for_each(d2.rbegin(), d2.rend(), Out 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
What happens when you attempt to compile and run the following code?
#include
#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
set
pair
cout<<*resultSet.first<<" "<<*resultSet.second< } Program outputs: A. 2 4 B. 4 2 C. 0 5 D. compilation error