Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. You want to write a program that ask the user for her/his name, save it as an

ID: 3685424 • Letter: 1

Question

1. You want to write a program that ask the user for her/his name, save it as an array of characters, then you display the characters in the name one at a time.

select all the header file that you need:

iostream

array

string

vector

2. Which of the following statements allow to declare and initialize a vector v of size 7?

vector<int> v;

vector<int> v(7);

vector<int> v(3, 7);

vector<int> v({1,2,3,4,5,6});

3. Let consider:

vector<double>elts;

How to initialize the first element of vector elts with 12.78?

elts.pop_back(12.78);

elts[1] = 12.78;

elts[0] = 12.78;

D. elts.push_back(12.78);

4.

Consider the instruction:

double weight [ ] = {120, 80.5, 230, 145.8, 95.5 };

Which expression represents 80.5?

weight[1]

weight(80.5)

weight(1)

weight[2]

A.

iostream

B.

array

C.

string

D.

vector

Explanation / Answer

1. You want to write a program that ask the user for her/his name, save it as an array of characters, then you display the characters in the name one at a time.

select all the header file that you need: A (for IO operations), B (for character array.)

iostream

array

string

vector

2. Which of the following statements allow to declare and initialize a vector v of size 7? B Creates a vector of size 7 integers.

vector<int> v;

vector<int> v(7);

vector<int> v(3, 7);

vector<int> v({1,2,3,4,5,6});

3. Let consider:

vector<double>elts;

How to initialize the first element of vector elts with 12.78? D. The declaration only declares the vector, but not initializes any space, so push_back() will add the required space, with specified value.

elts.pop_back(12.78);

elts[1] = 12.78;

elts[0] = 12.78;

D. elts.push_back(12.78);

4.

Consider the instruction:

double weight [ ] = {120, 80.5, 230, 145.8, 95.5 }; A. weight is an array, and therefore, array subscript should be specified with square braces, and array index starts with 0.

Which expression represents 80.5?

weight[1]

weight(80.5)

weight(1)

weight[2]

A.

iostream

B.

array

C.

string

D.

vector