Multidimensional Arrays - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Multidimensional Arrays

Description:

Understand how to program parallel arrays. Understand how to create two-dimensional arrays. ... To create parallel arrays, just create them as you would any ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 16
Provided by: bobmo3
Category:

less

Transcript and Presenter's Notes

Title: Multidimensional Arrays


1
Multidimensional Arrays
2
Goals
  • By the end of this lecture you should
  • Understand how to program parallel arrays.
  • Understand how to create two-dimensional arrays.
  • Understand how to access elements in a
    two-dimensional array.

3
Parallel (Corresponding) Arrays
  • Parallel arrays give you the ability to store
    multiple pieces of information about a single
    entity in an application.
  • The subscripts of each array should correspond to
    one another for individual entities.

4
Conceptual Example of Parallel Arrays
fltExam1Scores
strStudents
strSID
5
Creating Parallel Arrays
  • To create parallel arrays, just create them as
    you would any other arrayvar strSID new
    Array()var strStudents new Array() var
    fltExamScores new Array()
  • The arrays are separate arrays in memory, treat
    them as one in your application

6
Assigning Values to Parallel Arrays
  • To assign values for a single entity to parallel
    arrays, use the same index number for each
    assignmentstrSID5 025769strStudents5
    RavifltExamScores5 .82

7
Take the next few minutes to examine the file
called multidimensionalArrays_01.html.
8
Another Approach
  • Another way that we can model tables of data is
    to use a multidimensional array.
  • A multidimensional array is an "array of arrays."
    When we use one, we need to specify multiple
    index numbers to assign/read elements.

9
Creating a 2-D Array
  • To create a 2-D array, we first declare a simple
    arrayvar arr2D_Array new Array()
  • Then, for each "row" that we add to the 2D array,
    we create a new array in an index of the parent
    arrayarr2D_Array0 new Array()

10
Accessing 2D Array Elements
  • To read or assign values to elements in a 2D
    array, we need to specify two subscripts. The
    first is the "row" number (from the parent) the
    second represents the "column" number (from the
    child) arr2D_Array00 "Hi"

11
Schematic Model of a 2D Array
Child (Second) Subscript
Parent (First) Subscript
12
Take the next few minutes to examine the file
called multidimensionalArrays_02.html.
13
Summary
  • We can use parallel arrays to store information
    about a single entity across multiple arrays.
  • In a set of parallel arrays, we store values
    related to a single entity so they share the same
    subscript number across the arrays in the
    parallel set.
  • continued

14
Summary
  • Multidimensional arrays are arrays of arrays.
  • We can use a two-dimensional array to model a
    table of data. The rows represent the subscripts
    from the parent array the columns represent the
    subscripts from the children arrays.
  • continued

15
Summary
  • In a two-dimensional array, we access array
    elements by specifying two subscripts the first
    representing the "row" number (from the parent)
    and the second representing the "column" number
    (from the child).
Write a Comment
User Comments (0)
About PowerShow.com