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 and v) const { return val>v.val;} };
ostream and operator <<(ostream and out, const B and v) { out< template ostream and out; Out(ostream and o): out(o){} void operator() (const T and 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: A. compilation error B. 1 2 3 4 5 6 8 0 0 0 C. 1 2 3 4 5 6 8 2 1 0 D. 5 2 1 0 0 0 0 0 0 0 E. 1 2 5 0 0 0 0 0 0 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 and v) const { return val ostream and operator <<(ostream and out, const B and v) { out< template ostream and out; Out(ostream and o): out(o){} void operator() (const T and val ) { out< int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque d1(t, t+10); sort(d1.begin(), d1.end()); deque::iterator it = upper_bound(d1.begin(), d1.end(), B(4)); for_each(it, d1.end(), Out(cout)); cout< return 0; } Program outputs: A. 5 6 7 8 9 10 B. 4 5 6 7 8 9 10 C. 6 7 8 9 10 D. 1 2 3 4 5 E. 1 2 3 4
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 and v) const { return val ostream and operator <<(ostream and out, const B and v) { out< template ostream and out; Out(ostream and o): out(o){} void operator() (const T and 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_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin()); for_each(v1.begin(), v1.end(), Out(cout));cout< return 0; } Program outputs: A. 6 8 3 4 0 0 0 0 0 0 B. 3 4 0 0 0 0 0 0 0 0 C. 6 8 0 0 0 0 0 0 0 0 D. compilation error E. 3 4 6 8 0 0 0 0 0 0
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
set
s1.insert(v.begin(),v.end());
bool found = s1.find(7);
if (found){
cout<<"Element found!\n";
}else {
cout<<"Element not found!\n";
}
return 0;
}
A. program will display "Element found!"
B. program will display "Element not found!\n"
C. code will not compile
D. changing type of variable found to int will make this code compile
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; } A. place 1: operator int() { return a; } B. place 1: operator int() { return a; } bool operator < (const A and b) { return this?>a< b.a;} C. place 1: bool operator < (const A and b) { return this?>a< b.a;} D. place 1: bool operator < (const A and b) { return this?>a< b.a;} friend ostream and operator <<(ostream and c, const A and a); place 2: ostream and operator <<(ostream and c, const A and a) { c< E. place 1: bool operator < (const A and b) { return this?>a< b.a;} place 2: ostream and operator <<(ostream and c, const A and a) { c<
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 and a) { _v+=a; }
void add(string and a) {
_v.insert(0, a);
}
};
int main()
{
A
string s(" world!");
a.add(s);
cout << a.getV() < return 0; } A. program will display: Hello world! B. compilation error C. program will display: world!Hello D. program will run without any output
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: A. 1 2 3 4 5 6 7 8 9 10 B. 0 0 0 0 0 0 0 0 0 0 C. compilation error D. no output
Which are NOT valid instantiations of priority_queue object:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
deque
priority_queue
priority_queue
priority_queue
priority_queue
priority_queue
return 0;
}
A. line I
B. line II
C. line III
D. line IV
E. line V
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};
vector
deque
d1.assign(v1.end(), v1.begin());
for(int i=0; i { cout< } cout< return 0; } A. program outputs 5 4 3 2 1 B. program outputs 1 2 3 4 5 C. compilation error in line 8 D. compilation error in line 10 E. segmentation fault runtime exception
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, 6 , 7, 8 , 9, 10};
vector
deque
d1.empty();
v1.empty();
if (v1.isempty())
{
cout<<"I am empty ";
}
else
{
cout<<"I am not empty ";
}
cout< return 0; } A. program outputs: I am empty 0 0 B. program outputs: I am not empty 0 0 C. compilation error D. program outputs: I am not empty 10 10