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

Need this in 15 minutes please 1. A vector is a data structure holds related dat

ID: 3721525 • Letter: N

Question

Need this in 15 minutes please

1.

A vector is

a data structure

holds related data of the same type

is similar to an array, except that you don't have to predetermine its size

all of the above

2.

Which statement is most true about this declaration?

vector <double> vector1;

this declares a vector object that holds integer data

this declares a vector named double that holds integer data

this declares a vector object that holds double data

this declares an array that holds double data

4.

What does the push_back() method do?

adds a value at the front of a vector

adds a value at the end of a vector

removes a value at the front of a vector

removes a value at the back of a vector

6.

Which statement is true about this code:

vector<string> names;

names[10] = "Tom";

it can be used to automatically set the capacity of the array to 11 items

it can be used anytime, regardless of the size of the array

it can't be used unless the capacity of the array has been previously set to 11

it should only be used if the size of the array is already at least 11

7.

Which statement best describes the vector capacity() and size() methods?

they can be used interchangeably

capacity() returns the current potential number of storage positions and size() returns the actual number of things that are stored

size() returns the current potential number of storage positions and capacity() returns the actual number of things that are stored

a data structure

holds related data of the same type

Explanation / Answer

ANSWER 1: Here option(4) will be correct no need to justify this.

ANSWER 2: vector <double> vector1; it is the declaration of the vector which holds the double values so option(3) will be correct.

ANSWER 4: push_back() thjis method will add an object to the end of the vector so option(2) will correct.

ANSWER 6: vector<string> names; names[10] = "Tom"; since here it is vector so here option(2) will correct.

ANSWER 7: Size is not allowed to differ between multiple compilers. The size of a vector is the number of elements that it contains, which is directly controlled by how many elements you put into the vector.

Capacity is the amount of space that the vector is currently using. Under the hood, a vector just uses an array. The capacity of the vector is the size of that array. This is always equal to or larger than the size. The difference between them is the number of elements that you can add to the vector before the array under the hood needs to be reallocated.

You should almost never care about the capacity. It exists to let people with very specific performance and memory constraints do exactly what they want.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote