CPP C++ Certified Professional Programmer

Loading demo links...

Showing 4–6 of 15 questions

Question 4 (Volume B)

What happens when you attempt to compile and run the following code? Choose all that apply.

#include #include

using namespace std; int main ()

{

vectorv1(10, 3); v1.push_back(3);

cout<<>

return 0; }

Select all that apply, then click Submit answer.

  • program displays 4 4

  • program displays 10 3

  • size of vector v1 is 11

  • all elements of vector v1 are of the same value

Question 5 (Volume B)

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 b(2); A a (5); a.add(C());

cout << a.getV() <

Select all that apply, then click Submit answer.

  • program will display:5

  • program will not compile

  • program will compile

  • program will cause runtime exception

Question 6 (Volume A)

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; templatestruct Out { ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) {out<<><>

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<

}

f.close();

return 0; }

Select all that apply, then click Submit answer.

  • file test.out will be opened writing

  • file test.out will be truncated

  • file test.out will be opened for reading

  • no file will be created nor opened

  • program will display sequence 1 2 3 4 5 6 7 8 9 10