What happens when you attempt to compile and run the following code?
#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==(A & b) { return a == b.a; }
};
struct Compare{
bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};
};
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector v (t,t+10);
vector::iterator it;
A m1[] = {A(1), A(2), A(3)};
it = find_end (v.begin(), v.end(), m1, m1+3, Compare());
cout << "Found at position: " << it?v.begin() << endl;
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() { int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20}; deque d1(t, t+10); sort(d1.begin(), d1.end(), greater()); pair for_each(result.first, result.second, Out(cout));cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T & a);
void add(string & a);
};
template
void A
void A
_v.insert(0, a);
}
int main()
{
A
string s(" world!");
a.add(s);
cout << a.getV() < 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=0):val(v){}
int getV() const {return val;}
B operator +(const B &b )const { return B(val + b.val);} };
ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< template A operator() (const A & a, const A & b) const { 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(), bind1st(ptr_fun (Add()), 1)); for_each(v2.rbegin(), v2.rend(), Out(cout));cout< 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 will happen when you attempt to compile and run the following code?
#include
using namespace std;
class C {};
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
};
int main()
{
A
A
a.add(C());
cout << b.getV() < return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#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++ ; } }; int main() { vector generate(v1.begin(), v1.end(), Sequence(1)); set deque reverse(v1.begin(),v1.end()); reverse(s1.begin(), s1.end()); reverse(d1.begin(), d1.end()); for_each(v1.begin(), v1.end(), Out for_each(s1.begin(), s1.end(), Out for_each(d1.begin(), d1.end(), Out return 0; } Program outputs:
What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?
#include
#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[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; fstream f("test.out"); list for_each(l.begin(), l.end(), Out f.close(); 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=0):val(v){}
int getV() const {return val;}
operator int () 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 t[]={3,2,4,1,5,6,10,8,7,9}; vector v1(t, t+10); transform(v1.begin(), v1.end(), v1.begin(), bind2nd(plus(), 1)); for_each(v1.rbegin(), v1.rend(), Out(cout));cout< return 0; } Program 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"};
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
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;
}
What will happen when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main ()
{
float f = 10.126;
cout.unsetf(ios::floatfield);
cout< return 0; } What will be a mantissa part of the numbers displayed:
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,0); sort(t1, t1+5); sort(t2, t2+5); copy(t1,t1+5,v1.begin()); copy(t2,t2+5,v1.begin()+5); inplace_merge(v1.begin(), v1.begin()+5,v1.end()); for_each(v1.begin(), v1.end(), Out(cout));cout< return 0; } Program outputs:
What will happen when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector
multiset
multiset
for(multiset
cout<<*i<<" ";
}
for(multiset
cout<<*i<<" ";
}
cout< return 0; } The output will be:
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 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(), bind2nd(Add(),1)); for_each(v2.rbegin(), v2.rend(), Out return 0; } Program outputs:
What will happen when you attempt to compile and run the code below, assuming you enter the following sequence: 1 2 3
#include
using namespace std;
int main ()
{
int a,b,c;
cin>>a>>b>>c;
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() && result.second == v1.end()) {//Line II
cout<<"Identical\n";
} else {
cout<<"Not identical\n";
}
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;
}
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:
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 end
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out< int main () { list for( ; !cin.bad() ; ) { int i; cin>>i; l.push_back(i); } for_each(l.begin(), l.end(), Out return 0; } Program will output:
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int t[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
deque
queue
queue
queue
queue
mylist.clear();third.clear();
cout< cout< return 0; }
Which sentence is correct about the code below? Choose all that apply.
#include
#include
#include
using namespace std;
class F {
int val;
public:
F(int v):val(v){}
bool operator() (int v) {
if (v == val) return true;
return false;
}
};
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector
if (find(v1.begin(), v1.end(), 6) == find(v1.begin(), v1.end(), F(6))) {
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;
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 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;}
operator int () const { return val;} };
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< int main() { B t[]={3,2,4,1,5,6,10,8,7,9}; vector v1(t, t+10); for_each(v1.begin(), v1.end(), bind1st(plus(), 1)); for_each(v1.rbegin(), v1.rend(), Out(cout));cout< return 0; } Program outputs:
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;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
operator int() const { return val; };};
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & 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 l(t, t+10); for_each(l.begin(), l.end(), Out(f)); f.close(); f.open("test.out"); for( ; f.good() ; ) { int i; f>>i; cout< } f.close(); 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[]={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
using namespace std;
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
template
U get(U a) {
return (U)(_v);
}
};
int main()
{
A
a.add(10);
cout.setf( ios::showpoint);
cout << a.getV() << " " << a.get(1.0)< return 0; }
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)<<" "< 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 10*(1+(start++ %3));} }; int main() { deque generate(d1.begin(), d1.end(), Sequence(1)); sort(d1.begin(), d1.end()); pair for_each(result.first, result.second, Out return 0; } Program outputs:
Which changes introduced independently will allow the code to compile and display 0 0 1 1 8 8 9 9 (choose all that apply)?
#include
#include
#include
using namespace std;
class A {
int a;
public:
A(int a):a(a){}
int getA() const { return a;}
/* Insert Code Here 1 */
};
/* Insert Code Here 2*/
int main(){
A t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
sets(t, t+10);/* Replace Code Here 3 */
multiset s1(s.begin(),s.end());/* Replace Code Here 4 */
s1.insert(s.begin(),s.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
multiset::iterator i=s1.begin();/* Replace Code Here 5 */
for( ;i!= s1.end(); i++)
{
cout<getA()<<" ";
}
cout< return 0; }
What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?
#include
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out< int main () { ifstream f("test.in"); list for( ; !f.fail() ; ) { int i; f>>i; l.push_back(i); } f.close(); for_each(l.begin(), l.end(), Out return 0; } Programwill output:
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 Add(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(), bind2nd(ptr_fun (Add),1)); for_each(v2.rbegin(), v2.rend(), Out return 0; } Program outputs: