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 t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque deque for_each(it, d1.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
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:
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[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20}; deque d1(t, t+10); sort(d1.begin(), d1.end()); 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
using namespace std;
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
friend ostream & operator<<(ostream & c, const A
};
template
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;
int main () {
int t[] = {1,2,3,4,5,1,2,3,5,4};
vector
vector
int m1[] = {1, 3, 2};
it = find_end (v.begin(), v.end(), m1, m1+3);
if (it != v.end())
cout << "Found at position: " << it?v.begin() << endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main ()
{
std::vector
v1.push_back(10);
return 0;
}
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
#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 transform(t1,t1+5,t2,v1.rbegin(), plus for_each(v1.rbegin(), v1.rend(), Out return 0; } Program outputs:
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 t[]={3,2,4,1,5,10,9,7,8,6}; vector sort(v1.begin(), v1.end(), greater cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
using namespace std;
template
void f(A a)
{
cout<<1< } void f(int a) { cout<<2< } int main() { int a = 1; f return 0; }
Which pieces of code inserted independently into places marked 1 and 2 will cause the program to compile and display: 0 1 2 3 4 5 6 7 8 9? Choose all that apply.
#include
#include
using namespace std;
class A { int a; public:
A(int a){ this?>a=a;}
//insert code here 1
};
//insert code here 2
template
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main() {
A t1[] ={ 1, 7, 8, 4, 5 };list l1(t1, t1 + 5);
A t2[] ={ 3, 2, 6, 9, 0 };list l2(t2, t2 + 5);
l1.sort();l2.sort();l1.merge(l2);
print(l1.begin(), l1.end());
print(l2.begin(), l2.end()); cout< return 0; }
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>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 t1[]={3,2,4,1,5}; B t2[]={5,6,8,2,1}; vector v1(10,0); 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(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) { _v+=a; }
void add(string & 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
#include
using namespace std;
class compare {
bool reverse;
public:
compare(bool revparam = false){ reverse = revparam;}
bool operator()(int lhs, int rhs) const{
if (reverse)return (lhs > rhs);
elsereturn (lhs < rhs);
}
};
int main(){
int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
priority_queue
priority_queue
compare(false));
while (first.size() > 0){
cout << first.top() << " "; first.pop();
}
while (second.size() > 0) {
cout << second.top() << " ";second.pop();
}
return 0;
}
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; }
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;
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
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;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
void print(int v) {
cout< } struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return start++; } }; int main() { vector generate_n(v1.begin(), 10, Sequence(1)); for_each(v1.begin(), v1.end(), print); cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code? Choose all that apply.
#include
#include
using namespace std;
int main ()
{
vector
v1.push_back(3);
cout< return 0; }
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
using namespace std;
int main ()
{
float f1 = 10.0;
float f2 = 10.123;
cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code? Choose all possible answers.
#include
using namespace std;
class C {
public:
int _c;
C():_c(0){}
C(int c) { _c = c;}
C operator+=(C & b) {
C tmp; tmp._c = _c+b._c;
return tmp;
} };
ostream & operator<<(ostream & c, const C & v) {
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 << a.getV() < 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;
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
using namespace std;
int main()
{
cout.setf(ios::oct, ios::basefield);
cout<<100<<" ";
cout.setf(ios::showbase);
cout<<100<<" ";
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_backward(t, t+10, v1.rend());
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
using namespace std;
bool mycomparison (int first, int second){return first>second;}
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(mycomparison);
l2.sort(mycomparison);
l1.merge(l2,mycomparison);
print(l1.begin(), l1.end());
print(l2.begin(), l2.end()); cout< 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 struct Add : public binary_function { 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}; deque d1(t, t+10); deque d2(10); transform(d1.begin(), d1.end(), d2.begin(), bind2nd(Add(), 1)); for_each(d2.rbegin(), d2.rend(), Out(cout));cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
int main() {
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector
map
for (vector
stringstream s;s << *i << *i;
m.insert(pair
}
pair
range = m.equal_range(6);
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 t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque sort(d1.begin(), d1.end()); deque for_each(it, d1.end(), Out return 0; } Program outputs:
What will happen 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) { _v+=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
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;
}
Which changes introduced independently will allow code to compile and display 0 1 8 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 };
vectorv(t, t+10);
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set::iterator i=s1.begin();i!= s1.end(); i++) {
cout<getA()<<" ";
}
cout< return 0; }