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;
}
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
#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:
A. 1 5 10 5 10 10 10 3 3 1
B. 1 5 2 5 2 4 4 3 3 1
C. compilation error
D. 10 10 2 10 2 4 4 10 10 10
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< int main() { int t1[]={1,2,3,4,5,6,7,8,9,10}; int t2[]={1,2,3,4,5,6,7,8,9,10}; vector vector vector transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus for_each(v3.rbegin(), v3.rend(), Out return 0; } Program outputs: A. 9 7 5 3 1 ?1 ?3 ?5 ?7 ?9 B. ?1 ?3 ?5 ?7 ?9 9 7 5 3 1 C. 1 3 5 7 9 ?1 ?3 ?5 ?7 ?9 D. 1 3 5 7 9 ?1 ?3 ?5 ?7 ?9 E. ?9 ?7 ?5 ?3 ?1 1 3 5 7 9
What happens when you attempt to compile and run the following code? Choose all that apply.
#include
#include
#include
#include
#include
#include
using namespace std;
template
ostream and out;
Out(ostream and o): out(o){}
void operator() (const T and val ) {out< 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< } f.close(); return 0; } A. file test.out will be opened writing B. file test.out will be truncated C. file test.out will be opened for reading D. no file will be created nor opened E. program will display sequence 1 2 3 4 5 6 7 8 9 10
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
#include
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
B operator +(const B andb )const { return B(val + b.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< B Add(B a, B b) { return a+b; } int main() { int t[]={1,2,3,4,5,6,7,8,9,10}; vector v1(t, t+10); vector v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind2nd(ptr_fun(Add),1)); for_each(v2.rbegin(), v2.rend(), Out(cout));cout< 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
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5};
vector
deque
d1.assign(v1.end(), v1.begin());
for(int i=0; i { cout< } cout< return 0; } A. program outputs 5 4 3 2 1 B. program outputs 1 2 3 4 5 C. compilation error in line 8 D. compilation error in line 10 E. segmentation fault runtime exception
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 and b) const { return a }; class F { A val; public: F(A and v):val(v){} bool operator() (A and 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; } A. it will compile successfully B. it will display Found! C. it will display Not found! D. it will not compile successfully
What happens when you attempt to compile and run the following code?
#include
using namespace std;
template
void f(A anda)
{
cout<<1< } void f(int anda) { cout<<2< } int main() { int a = 1; f(a); return 0; } A. program displays: 1 B. program displays: 2 C. compilation error D. runtime exception