Chapter 9: Vectors and Arrays I

Chapter Goals

Using Vectors to Collect Data Items

Syntax 9.1: Vector Variable Definition

vector<type_name> variable_name;
vector<type_name> variable_name(initial_size);
Example:
vector<int> scores;
vector<Employee> staff(20);
Purpose: Define a new variable of vector type, and optionally supply an initial size.

Vector Subscripts

Syntax 9.2: Vector Subscripts

vector_expression[integer_expression]
Example:
salaries[i + 1]
Purpose: Access an element in a vector.

Vector Subscripts (salvect.cpp)


Vector Parameters and Return Values

Vector Parameters and Return Values (matches.cpp)


Removing and Inserting Elements

Removing and Inserting Elements (erase2.cpp)

Removing and Inserting Elements (insert.cpp)


Parallel Vectors

Parallel Vectors (bestval1.cpp)

Parallel Vectors (bestval2.cpp)