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,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector
vector
cout<< it?v.begin()< return 0; } Program outputs: A. 10 B. 3 C. 1 D. 15 E. compilation error
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
ostream and out;
Out(ostream and o): out(o){}
void operator() (const T and val ) { out< 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: A. 1 2 3 4 5 6 10 8 7 9 B. 3 2 4 1 5 6 7 8 9 10 C. 3 2 4 1 5 6 10 8 7 9 D. 1 2 3 4 5 6 7 8 9 10 E. compilation error
Which changes introduced independently will allow the code to compile and display "one" "eight" "nine" "ten"? 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(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string s[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","ten"};
multimap m;/* Replace Code Here 3 */
for(int i=0; i<10; i++) {
m.insert(pair(A(t[i]),s[i]));
}
m.erase(m.lower_bound(2),m.upper_bound(7));
multimap::iterator i=m.begin();/* Replace Code Here 4 */
for( ; i!= m.end(); i++) {
cout<second<<" ";
}
cout< return 0; } A. operator int() const { return a;} inserted at Place 1 B. bool operator < (const A and b) const { return a C. bool operator < (const A and b) const { return b.a D. struct R { bool operator ()(const A and a, const A and b) { return a.getA()
Which lines of the code below contain proper instantiation of queue objects?
#include
#include
#include
#include
#include
using namespace std;
int main()
{
deque
list
vector
queue
queue
queue
queue
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;
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
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 andb )const { return B(val ? b.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[]={1,2,3,4,5,6,7,8,9,10}; B t2[]={1,2,3,4,5,6,7,8,9,10}; vector v1(t1, t1+10); vector v2(t2, t2+10); vector v3(10); transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus()); for_each(v3.rbegin(), v3.rend(), Out(cout));cout< return 0; } Program outputs: A. 9 7 5 3 1 ?1 ?3 ?5 ?7 ?9 B. ?1 ?3 ?5 ?7 ?9 9 7 5 3 1 C. 1 3 5 7 9 ?1 ?3 ?5 ?7 ?9 D. 1 3 5 7 9 ?1 ?3 ?5 ?7 ?9 E. ?9 ?7 ?5 ?3 ?1 1 3 5 7 9
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream and out;
Out(ostream and o): out(o){}
void operator() (const T and val ) { out< }; int main() { char s[]={"qwerty"}; char t1[]={"ert"}; char t2[]={"ERT"}; sort(s, s+6); cout< return 0; } Program outputs: A. 0 0 B. 0 1 C. 1 0 D. 1 1
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;
}
A. program outputs: 6
B. program outputs: 5 7
C. program outputs: 6 7
D. program outputs: 1 5
E. program outputs: 6 5
What happens 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 };
multiset
s1.insert(s1.find(7), 3);
for(multiset
cout<<*i<<" ";
}
return 0;
}
A. program outputs: 0 1 2 3 3 4 5 6 7 8 9
B. program outputs: 0 1 2 3 4 5 6 7 8 9
C. program outputs: 0 1 2 3 4 5 6 7 3 8 9
D. program outputs: 0 1 2 3 4 5 6 3 7 8 9
E. runtime exception
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);
void add(string and a);
};
template
void A
void 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