Which changes introduced independently will allow code to compile and display 0 1 8 9 (choose all that apply)
#include <iostream>
#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<<i?>getA()<<" ";
}
cout<<endl;
return 0;
}
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):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<<v.getV(); return out;}
template
ostream & out; Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
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<<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<<" "; } };
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(), bind1st(1,Add()));
for_each(v2.rbegin(), v2.rend(), Out
return 0;
}
Program outputs:
Which lines of the code below contain proper instantiation of queue objects?
#include <iostream>
#include
#include
#include
#include
using namespace std;
int main()
{
deque
list
vector
queue
queue
queue
queue
queue
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;} };
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<<" "; } };
struct Add {
B operator()(B & a, B & b) { return a+b; } };
int main() {
B 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(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 <iostream>
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<<endl;
return 0;
}
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};
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<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#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;
}
PDF + Testing Engine
|
---|
$57.75 |
Testing Engine
|
---|
$43.75 |
PDF (Q&A)
|
---|
$36.75 |
C++ Institute Free Exams |
---|
![]() |