Comp Sci Ch 9 Ch 10 Flashcards
what types of ordered list types does c++ suppport
arrays and vectors
how do you declare vectors
vector<type> name (elements)</type>
how do you access an index of a vector
name.at(i);
why are vectors safer than arrays
because it uses () that check the .at while the [] in arrays are not
AND
arrays do not have the size feature
what is a vector
an ordered list of items of a given data type
what is an element in a vector
each item
what do you need to include to use vectors
include < vector>
If a vector has N elements
what is the last element index
N - 1
if a vector has last index N, how many elements does it have
N + 1
The index of a vector to access must be
an unsigned int type and not a floating type number
what does size return for a vector
the number of elements
when a vector is initialized with a number of elements
vector<type> name (numOfElements);</type>
what are the elements initialized to
0
how to initialize all the elements of a vector to one value
vector <type> name ( numOfElements, valueToSetTo);</type>
how to initialize each element in a vector to different values
vector <type> name = {num, num, ...};</type>
for a large vector how should you initialize it
a for loop
normal loop header for iterating through a vector
for ( unsigned int i = 0; i < v.size(); ++i) {
//loop body;
}
you already have the vector size
how should you input stuff into the vector
for ( unsigned int i = 0; i < v.size; ++i) {
cin»_space; v.at(i);
}
If you have multiple vectors….
both vectors should have same amount of elements
–0 corresponds to 0 and 1 to 1 and so on
how do you append items to a vector
.push_back