3 Months Free Update
3 Months Free Update
3 Months Free Update
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
while (start != end) {
std::cout << *start << " "; start++;
}
}
class A {
int a;
public:
A(int a):a(a){}
operator int () const { return a;}int getA() const { return a;}
};
struct R {
int val;
R(int v):val(v){}
bool operator ()(const A & a) { return a>val;} };
int main() {
int t1[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
list l1(t1, t1 + 10);
R r(4);l1.remove_if(r);
print(l1.begin(), l1.end()); cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main ()
{
std::vector
v1.push_back(10);
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
cout< 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< }; bool Compare(char a, char b) { return tolower(a) < tolower(b);} int main() { char s[]={"qwerty"}; char t1[]={"ert"}; char t2[]={"ERT"}; sort(s, s+6); cout< return 0; } Program outputs:
Given three files: class.h, class.cpp and main.cpp containing small C++ project, which sentences are TRUE if you attempt to compile and run the program? Assume that the whole compiling environment is properly set.
// File: main.cpp
#include
#include "class.h"
using namespace std;
int main()
{
A
cout << a.getV() << endl;
return 0;
}
//File: class.h
#ifndef _CLASS_
#define _CLASS_
template
class A {
T_v;
public:
A() {}
A(T v);
T getV();
};
#endif
//File: class.cpp
#include "class.h"
template
A
template
T A
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main(){
int t[] ={ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
list
set
if (s1.count(3) == 2) {
s1.erase(3);
}
for(set
cout<<*i<<" ";
}
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[]={5,6,8,2,1}; vector 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 return 0; } Program outputs:
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, 0, 1, 2, 3, 4, 0 };
vector
multimap
for(vector
stringstream s; s<<*i<<*i; m.insert(pair
}
for(multimap
cout<<*i<<" ";
}
return 0;
}
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1.1 2.2 3.3
#include
#include
using namespace std;
int main ()
{
int a,b,c;
cin>>a>>b>>c;
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main() {
string t1[] ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
list
list
l2.reverse(); l1.splice(l1.end(),l2);
l1.unique();
print(l1.begin(), l1.end()); cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map
for(int i=0; i < 10; i++) {
m[i]=t[i];
}
map
cout<
return 0;
}
Program outputs:
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; }
What happens when you attempt to compile and run the following code? Choose all possible answers.
#include
using namespace std;
class C {
public:
int _c;
C():_c(0){}
C(int c) { _c = c;}
C operator+=(C & b) {
C tmp; tmp._c = _c+b._c;
return tmp;
} };
ostream & operator<<(ostream & c, const C & v) {
c< 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 A a.add(C()); cout << a.getV() < return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main ()
{
float f = 10.126;
cout< 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 second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};
map
for(int i=0; i<10; i++) {
m.insert(pair
}
if (m[11] == "eleven") {
cout<<"eleven ";
}
for(map
cout<second<<" ";
}
cout< 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=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< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
using namespace std;
template
void g(int a)
{
cout< } template void g(A a) {
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A
{
int a;
public:
A():a(0){} A(int a){ this?>a = a;}
void setA(int a) {this?>a = a;}
int getA() {return a;}
};
ostream &operator<<(ostream & cout, A & a)
{
cout<< a.getA();
return cout;
}
int main ()
{
vectorv(5, new A());
v.push_back(new A(1));
vector::iterator it;
for(it = v.begin(); it != v.end(); it++)
{
cout<<*it<<" ";
}
cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
int main ()
{
std::vector
for(int i = 0; i<10; i++) {v1.push_back(i); }
v1.resize(4);
std::vector
v1.insert(v1.end()?1, 4);
for(int i=0 ; i<= v1.size(); i++) {std::cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
cout.setf(ios::oct, ios::basefield);
cout<<100<<" ";
cout.setf(ios::showbase);
cout<<100<<" ";
return 0;
}
Program outputs:
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:
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 will happen 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};
deque
vector
cout< cout< d1.resize(12); v1.resize(12); cout< cout< d1.reserve(20);v1.reserve(20); cout< cout< 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[]={5,6,8,2,1}; vector sort(t1, t1+5); sort(t2, t2+5); set_symmetric_difference(t1,t1+5,t2,t2+5,v1.begin()); 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
using namespace std;
template
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] ={ 1, 2, 3, 4, 5};
list
l1.remove(2);
print(l1.begin(), l1.end()); cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
set
vector
swap(s1, v1);
for_each(v1.begin(), v1.end(), myfunction);
for_each(s1.begin(), s1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A
{
int a,b;
public:
A(const A & c) { a = c.a; }
A():a(0),b(0){}
void setA(int a) {this?>a = a;} void setB(int b) {this?>b = b;}
int getA() {return a;} int getB() {return b;}
};
int main ()
{
vectorv;
A a;
a.setA(10); a.setB(11);
v.push_back(a);
cout< return 0; }
What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?
#include
#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[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; fstream f("test.out"); list for_each(l.begin(), l.end(), Out f.close(); 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< bool Greater(int v1, int v2) { return v1 int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; vector sort(v1.begin(), v1.end(), Greater); for_each(v1.begin(), v1.end(), Out return 0; } Program outputs: