COMFUN2 Chapter 11 12
COMFUN2 Chapter 11 12
COMFUN2 Chapter 11 12
Summary
❖ A two-dimensional array resembles a
table in that elements are in rows and
columns
❖ Each element has the same data type
❖ You can determine the number of
elements in a two-dimensional array by
multiplying the number of rows by the
number of columns
❖ Each element in a two-dimensional array
is identified by a unique combination of
two subscripts representing the element’s
row and column, respectively.
❖ Accumulating the Values Stored in a
Two-Dimensional Array
❖ Program for the Jenko Booksellers
company uses a two-dimensional array to
store the sales made in each of the
company’s three bookstores
❖ Array contains three rows and two
columns
❖ First column contains sales amount for
paperback books sold in each of three
stores
❖ Second column contains sales amounts
for hardcover books in the three stores
❖ Program calculates total sales by
accumulating amounts stored in array
and displays total sales
❖ When declaring a two-dimensional array,
you must provide the number of rows as
well as the number of columns
❖ You can use an assignment statement or
the extraction operator to enter data into
an array
❖ You need to use two loops to access
every element in a two-dimensional array
❖ One of the loops keeps track of the row
subscript, and the other keeps track of
the column subscript
❖ To pass a two-dimensional array to a
function, you include the array’s name in
the statement that calls the function
❖ Array’s corresponding formal parameter
in the function header must specify the
formal parameter’s data type and name,
followed by two sets of square brackets
❖ First bracket contains the number of
rows, and the second bracket contains
the number of columns