What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
#include
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector
set
replace(v1.begin(), v1.end(), 1, 10);
replace(s1.begin(), s1.end(), 1, 10);
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 <iostream>
#include <algorithm>
#include <functional>
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<<v.getV(); return out;}
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
template<typename A>
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<<endl;
return 0;
}
Program outputs:
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: true false<enter>?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
bool a,b;
cin>>boolalpha>>a>>b;
cout<<a<
return 0;
}
Program will output:
What happens when you attempt to compile and run the following code?
#include
#include <iostream>
#include <algorithm>
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) {
out<<val<<" "; }};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() {
return start++; } };
int main() {
vector
vector
generate(v1.begin(), v1.end(), Sequence(1));
reverse_copy(v1.begin(),v1.end(), v2.rbegin());
sort(v2.begin(), v2.end(), less_equal
for_each(v2.begin(), v2.end(), Out
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include <iostream>
#include <algorithm>
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<<v.getV(); return out;} template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { B t1[]={3,2,4,1,5}; int t2[]={5,6,8,2,1}; vector v1(10,0); sort(t1, t1+5); sort(t2, t2+5); set_union(t1,t1+5,t2,t2+5,v1.begin()); for_each(v1.begin(), v1.end(), Out(cout));cout<<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include <iostream>
#include <algorithm>
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
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 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 <iostream>
#include
#include <string>
#include
#include <algorithm>
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out<<val<<" "; } };
int main () {
ifstream f("test.in");
list
for( ; f.good() ; ) {
int i;
f>>i;
l.push_back(i);
}
f.close();
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 <iostream>
#include <algorithm>
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<<v.getV(); return out;} template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; 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<<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <typename T>
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)<<endl;
return 0;
}
What will happen when you attempt to compile and run the following code?
#include
#include
#include <iostream>
using namespace std;
int main ()
{
vector
deque
for(int i=0; i<5; i++)
{
v1.push_back(i);v1.push_front(i);
d1.push_back(i);d1.push_front(i);
}
for(int i=0; i { cout<<d1[i]<<" "< } cout<<endl; return 0; } What will be its output:
PDF + Testing Engine
|
---|
$66 |
Testing Engine
|
---|
$50 |
PDF (Q&A)
|
---|
$42 |
C++ Institute Free Exams |
---|
![]() |