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 will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 end
#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 () { list for( ; !cin.bad() ; ) { int i; cin>>i; l.push_back(i); } for_each(l.begin(), l.end(), Out return 0; } Program will output: A. 1 2 3 B. 1 2 3 end C. 1 D. compilation error E. program runs forever without output
Which changes introduced independently will allow the code to compile and display 0 0 1 1 8 8 9 9 (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(){
A t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
sets(t, t+10);/* Replace Code Here 3 */
multiset s1(s.begin(),s.end());/* Replace Code Here 4 */
s1.insert(s.begin(),s.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
multiset::iterator i=s1.begin();/* Replace Code Here 5 */
for( ;i!= s1.end(); i++)
{
cout<getA()<<" ";
}
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()
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< struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return start++; } }; int main() { vector generate_n(v1.begin(), 10, Sequence(1)); random_shuffle(v1.rbegin(), v1.rend()); sort(v1.begin(), v1.end(), great for_each(v1.begin(), v1.end(), Out return 0; } Program outputs: A. 8 10 5 1 4 6 2 7 9 3 B. 1 2 3 4 5 6 7 8 9 10 C. compilation error D. 10 9 8 7 6 5 4 3 2 1
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< struct Add { int operator()(int and a, int and 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(), bind2nd(Add(),1)); for_each(v2.rbegin(), v2.rend(), Out return 0; } Program outputs: A. 1 2 3 4 5 6 7 8 9 10 B. 2 3 4 5 6 7 8 9 10 11 C. 10 9 8 7 6 5 4 3 2 1 D. 11 10 9 8 7 6 5 4 3 2 E. compilation error
What happens when you attempt to compile and run the following code?
#include
#include
#include
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< return 0; } A. program outputs: 0 1 2 3 4 5 6 7 8 9 0 2 3 6 9 B. program outputs: 0 1 2 3 4 5 6 7 8 9 C. program outputs: 9 8 7 6 5 4 3 2 1 0 D. compilation error
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< template T start; T step; Sequence(T start, T step):start(start), step(step){} T operator()() { T v = start; start+=step; return v; } }; bool Less(float a, float b) { return int(a) int main() { float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13}; vector stable_sort(v1.begin(), v1.end(), Less); for_each(v1.begin(), v1.end(), Out return 0; } Program outputs: A. 1.66 1.32 1.96 1.13 2.28 2.3 2.98 2.62 3.94 3.64 B. 1.13 1.32 1.66 1.96 2.28 2.3 2.62 2.98 3.64 3.94 C. compilation error D. 3.94 3.64 2.98 2.62 2.3 2.28 1.96 1.66 1.32 1.13 E. the exact output is impossible to determine
What will be output of the program when you attempt to compile and run the following code? #include
#include
#include
#include
using namespace std;
int main(){
int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","zero"};
multimap
for(int i=0; i<10; i++) {
m.insert(pair
}
m[0]="ten";
m.insert(pair
for(multimap
cout<second<<" ";
}
return 0;
}
A. zero one two three four five six seven eight nine
B. ten one two three four five six seven eight nine
C. zero eleven two three four five six seven eight nine
D. ten eleven two three four five six seven eight nine
E. compilation error
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
template
public:
B(T v):val(v){}
T getV() const {return val;} };
template template ostream and out; Out(ostream and o): out(o){} void operator() (const T and val ) { out< string tolower(const string and s) { string tmp(s); for(unsigned i = 0; i< tmp.size(); ++i){ tmp[i] = tolower(tmp[i]); } return tmp; } bool Less(const B int main() { string t[]={"aaa","bbb","Aaa", "Bbb","aAa","bBb","aaA","bbB"}; vector > v1; v1.assign(t, t+8); stable_sort(v1.begin(), v1.end(), Less); for_each(v1.begin(), v1.end(), Out >(cout));cout< return 0; } Program outputs: A. Aaa aaa aAa aaA bbb Bbb bBb bbB B. Aaa aaa aAa aaA bbb Bbb bbB bBb C. aaa Aaa aAa aaA bbb Bbb bBb bbB D. the exact output is impossible to determine