What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
void multiply (int a) {
a*2;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector
for_each(v1.begin(), v1.end(), multiply);
iter_swap(v1.begin(),t+9);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
A. 1 5 9 6 2 4 7 8 3 1
B. compilation error
C. 1 2 3 4 5 6 7 8 9 10
D. 10 9 8 7 6 5 4 3 2 1
E. 10 5 9 6 2 4 7 8 3 1
What happens when you attempt to compile and run the following code?
#include
#include
#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< } else { cout<<"Not found!\n"; } return 0; } Program outputs: A. 5 B. Not found! C. 10 D. 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}; 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;
bool identical(int a, int b) {
return b == 2*a?true:false;
}
int main() {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
int u[] = {2,4,6,4,6,10,2,4,14,6,4,2,20,8,8,5};
vector
deque
pair
result = mismatch(d1.begin(), d1.end(), v1.begin(), identical); //Line I
if (result.first == d1.end() andand result.second == v1.end()) {//Line II
cout<<"Identical\n";
} else {
cout<<"Not identical\n";
}
return 0;
}
Program outputs:
A. Identical
B. Not identical
C. compilation error at line marked I
D. compilation error at line marked II
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main(){
int t[] ={ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
list
multiset
if (s1.count(3) == 2) {
s1.erase(3);
}
for(multiset
cout<<*i<<" ";
}
return 0;
}
A. program outputs: 1 2 3 4 5
B. program outputs: 1 2 4 5
C. program outputs: 1 1 2 2 3 4 4 5 5
D. program outputs: 1 1 2 2 3 3 4 4 5 5
E. compilation error
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,3,5,1,2,4,4,5};
vector
vector
while ( (it = adjacent_find (it, v.end())) != v.end()) {
cout< } cout<< endl; return 0; } A. program outputs: 2 3 B. program outputs: 2 7 C. program outputs: 3 8 D. compilation error E. program will run forever
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:
A. 10 5 9 6 2 4 7 8 3 1
B. 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1
C. compilation error
D. runtime exception/segmentation fault
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.push_back(pair
}
for (multimap
cout << i?>first << " ";
}
return 0; }
A. program outputs: 1 2 3 4 5
B. compilation error
C. program outputs: 1 1 2 2 3 3 4 4 5 5
D. program outputs: one two three four five
E. program outputs: one one two two three three four four five five
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;
}
A. destructor of class A will be called
B. destructor of class B will be called
C. code will not compile
D. program outputs 10 11 10 11 10
E. program outputs 10 11 10 11 10 11 10 11 10 11
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