Documente Academic
Documente Profesional
Documente Cultură
Fifth Edition
Chapter 11 Arrays
Objectives
Declare and initialize a one-dimensional array Manipulate a one-dimensional array Explain the bubble sort algorithm Pass a one-dimensional array to a function Use parallel one-dimensional arrays
Objectives (continued)
Declare and initialize a two-dimensional array Enter data into a two-dimensional array Search a two-dimensional array Utilize a one-dimensional array in a .NET C++ program
Concept Lesson
Using Arrays One-Dimensional Arrays Storing Data in a One-Dimensional Array Manipulating One-Dimensional Arrays Passing a One-Dimensional Array to a Function
Using Arrays
Simple variable is unrelated to other variables in computers internal memory
Also called a scalar variable
One-Dimensional Arrays
Visualize a one-dimensional array as a column of variables
Subscript (or index) identifies each variable
Indicates the variables position in the array Subscript of first variable is 0
Element
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Two-Dimensional Arrays
Two-dimensional array resembles a table
Elements are in rows and columns Each element is identified by two subscripts
Subscripts specify the variables row and column position in the array
39
40
41
42
43
44
45
46
47
48
49
Summary
An array is a group of variables that have the same name and data type and are related in some way
One-dimensional
Visualize as a column of variables
Two-dimensional
Visualize as a table
You must declare an array before you can use it Each elements in a one-dimensional array is assigned a subscript
First element has subscript 0
An Introduction to Programming with C++, Fifth Edition 50
Summary (continued)
Parallel arrays are two or more arrays whose elements are related by their subscript in the arrays To create a two-dimensional array specify the number of rows and columns
Each element is identified by two subscripts
First subscript represents the elements row location Second subscript represents its column location
51
Lab 11.3
Modified program will use a value-returning function, calcTotal(), to calculate the total rainfall amount