What happens when you attempt to compile and run the following code?
#include
#include
#include <iostream>
#include <algorithm>
using namespace std;
class B {
int val;
public:
B(int v):val(v){}
operator int() { return val;}
};
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++; } };
bool predicate(int v) { return v%2==0; }
int main() {
vector
generate_n(v1.begin(), 10, Sequence(1));
for_each(v1.begin(), remove_if(v1.begin(), v1.end(), predicate), Out
return 0;}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#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<<it?v.begin()<<" ";it++;
}
cout<< endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
#include
#include
#include
#include <string>
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 <iostream>
#include
using namespace std;
int main ()
{
float f = 10.126;
cout<<f<<" "< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
using namespace std;
bool compare(int a, int b) { return a == b; }
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector
vector
int m1[] = {1, 2, 3};
while ( (it = find_first_of (it, v.end(), m1, m1+3)) != v.end()) {
cout<<it?v.begin()<<" ";
}
cout<< endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
#include
#include <string>
using namespace std;
int main(){
int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};
map
for(int i=0; i<10; i++) {
m.insert(pair
}
if (m[11] == "eleven") {
cout<<"eleven ";
}
for(map
cout<<i?>second<<" ";
}
cout<<m.size();
return 0;
}
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=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<<val<<" "; } };
struct Add {
B operator()(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(), bind1st(Add(),1));
for_each(v2.rbegin(), v2.rend(), Out(cout));cout<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include <iostream>
using namespace std;
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 };
deque
l1.sort();
d1.sort();
l1.merge(d1);
print(l1.begin(), l1.end());
print(d1.begin(), d2.end()); cout<<endl;
return 0;
}
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[]={5,6,8,2,1};
vector
sort(t1, t1+5);
sort(t2, t2+5);
set_symmetric_difference(t1,t1+5,t2,t2+5,v1.begin());
for_each(v1.begin(), v1.end(), Out
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include <iostream>
#include <algorithm>
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
bool Greater(int v1, int v2) { return v1 int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; vector sort(v1.begin(), v1.end(), Greater); for_each(v1.begin(), v1.end(), Out return 0; } Program outputs:
PDF + Testing Engine
|
---|
$57.75 |
Testing Engine
|
---|
$43.75 |
PDF (Q&A)
|
---|
$36.75 |
C++ Institute Free Exams |
---|
![]() |