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<<i?>getA()<<" ";
}
cout<<endl;
return 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 & v) const { return val>v.val;} };
ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { B t[]={3,2,4,1,5,10,9,7,8,6}; vector v1(t,t+10); sort(v1.begin(), v1.end(), greater()); cout<<*min_element(v1.begin(), v1.end()); return 0; } Program outputs:
What happens when you attempt to compile and run the following code? Choose all that apply.
#include
#include
#include
#include
#include
#include
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< int main () { int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; fstream f("test.out", ios::trunc|ios::out); list l(t, t+10); for_each(l.begin(), l.end(), Out(f)); f.close(); f.open("test.out"); for( ; f.good() ; ) { int i; f>>i; cout<<i<<" "; } f.close(); return 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 & v) const { return val>v.val;} };
ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & 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<<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#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 };
list
l1.sort();
list
it++; it++;
l1.splice(l1.end(),l2, it, l2.end());
print(l1.begin(), l1.end()); cout<<"Size:"< print(l2.begin(), l2.end()); cout<<"Size:"< return 0; }
What will happen 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, 0, 3, 4, 1, 2, 0 };
vector
multimap
for (vector
stringstream s;s << *i << *i;
m.insert(pair
}
pair
range = m.equal_range(2);
for (multimap
cout << i?>first << " ";
}
return 0;
}
The output will be:
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
struct display {
void operator() (int i) {cout << " " << i;}
};
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector
deque
set
for_each(v1.begin(), v1.end(), display); //Line I
for_each(d1.begin(), d1.end(), *(new display())); // Line II
for_each(s1.begin(), s1.end(), display()); // Line III
return 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){} B(){}
int getV() const {return val;} };
ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque d1(t, t+10); deque::iterator it = lower_bound(d1.begin(), d1.end(), 4); for_each(it, d1.end(), Out(cout));cout<<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) {
out< struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return start++; } }; int main() { vector vector generate(v1.begin(), v1.end(), Sequence(1)); reverse_copy(v1.begin(),v1.end(), v2.rbegin()); sort(v2.begin(), v2.end(), less_equal for_each(v2.begin(), v2.end(), Out return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};
map
for (int i = 0; i < 10; i++) {
m.push_back(pair
}
for (map
cout << i?>first << " ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & 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:
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 & v) const { return val ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { B t1[]={3,2,4,1,5}; int t2[]={5,6,8,2,1}; vector v1(10,0); sort(t1, t1+5); sort(t2, t2+5); set_union(t1,t1+5,t2,t2+5,v1.begin()); for_each(v1.begin(), v1.end(), Out(cout));cout<<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
using namespace std;
void g(int a)
{
cout<<a?1< } template void g(A a) { cout<<a+1< } int main() { int a = 1; g(a); return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< int main() { int t1[]={3,2,4,1,5}; int t2[]={6,10,8,7,9}; vector transform(t1,t1+5,t2,v1.rbegin(), plus for_each(v1.rbegin(), v1.rend(), Out return 0; } Program outputs:
What will happen when you attempt to compile and run the code below, assuming you enter the following sequence: 1 2 3
#include
using namespace std;
int main ()
{
int a,b,c;
cin>>a>>b>>c;
cout<<a<
return 0;
}
Program will output:
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 & out;
Out(ostream & o): out(o){}
void operator() (const T & 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:
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:
What will happen when you attempt to compile and run the following code? Choose all possible answers.
#include
using namespace std;
class B {};
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
};
int main()
{
A
Ab;
a.add(10);
cout << a.getV() < return 0; }
Which keywords can be used to define template type parameters? Choose all possible answers:
What will happen 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 & a) { _v+=a; }
};
int main()
{
A
string s(" world!");
a.add(s);
cout << a.getV() < return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
};
struct Even {
bool operator ()(const A & a, const A &b) {
return (a.getA() % 2)==b.getA() % 2;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
deque
deque
cout<< it?d.begin()< return 0; } Program outputs:
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):val(v){}
int getV() const {return val;} bool operator < (const B & v) const { return val ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & 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()); set s1(t,t+10); cout<<binary_search(s1.begin(),s1.end(), B(4))<<" "< return 0; } Program outputs:
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<<v1.size()<<" "< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
class A {
public:
virtual int f() { return 10; }
virtual ~A(){}
};
class B: public A {
int f() {return 11; }
virtual ~B(){}
};
int main (){
std::vectorv1;
for(int i = 10; i>0; i??)
{
i%2>0?v1.push_back(new A()):v1.push_back(new B());
}
std::vector::iterator it = v1.begin();
while(it != v1.end())
{
std::cout<<v1.back()?>f()<<" ";
v1.pop_back();++it;
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
public:
B(T v):val(v){}
T getV() const {return val;} bool operator < (const B & v) const { return val template template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< bool Less(const B 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 > v1; v1.assign(t, t+10); stable_sort(v1.begin(), v1.end(), Less); for_each(v1.begin(), v1.end(), Out >(cout));cout<<endl; return 0; } Program outputs:
What will happen when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main ()
{
float f = 10.126;
cout.unsetf(ios::floatfield);
cout<<scientific< return 0; } What will be a mantissa part of the numbers displayed:
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;}
operator int () const { return val;} };
ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { B t[]={3,2,4,1,5,6,10,8,7,9}; vector v1(t, t+10); transform(v1.begin(), v1.end(), v1.begin(), bind2nd(plus(), 1)); for_each(v1.rbegin(), v1.rend(), Out(cout));cout<<endl; return 0; } Program outputs:
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=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< 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
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};
multimap
for (int i = 0; i < 10; i++) {
m.push_back(pair
}
for (multimap
cout << i?>first << " ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main ()
{
float f1 = 10.0;
float f2 = 10.123;
cout<<noshowpoint< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
int calculate(T start, T end)
{
int s = 0;
while (start != end)
s+= *start; start++;return s;
}
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};
vector
deque
cout<<calculate(t,t+10)<<" ";
cout<<calculate(v1.begin()+1,v1.end()?2)<<" ";
cout<<calculate(d1.rbegin()+1,d1.rend()?2)<<" ";
cout<<calculate(t[0],t[10])<<" ";
cout<<endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< int main() { int t[]={3,2,4,1,5,6,10,8,7,9}; vector for_each(v1.begin(), v1.end(), bind1st(plus for_each(v1.rbegin(), v1.rend(), Out return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; int t1[]={1,2,3,4}; deque set sort(d1.begin(), d1.end()); cout<<includes(s1.begin(),s1.end(), t1,t1+4)<<" "< < return 0; } Program outputs:
What will happen when you attempt to compile and run the following code? Choose all that apply.
#include
#include
#include
#include
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
bool operator < (const A & b) const { return a }; class F { A val; public: F(A & v):val(v){} bool operator() (A & v) { if (v.getA() == val.getA()) return true; return false; } }; int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector v1(t, t + 10); set s1(t, t + 10); A a(6); F f(a); find_if(s1.begin(), s1.end(), f); if (find_if(v1.begin(), v1.end(), f) !=v1.end()) { cout<<"Found!\n"; } else { cout<<"Not found!\n"; } return 0; }