J. Michael Moore From James Tam’s material Multi-Dimensional Arrays CSCE 110.

Slides:



Advertisements
Similar presentations
James Tam Linked Lists in Pascal Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
Advertisements

Selection Process If … then … else.... Condition Process 2 Process 1 Y.
1 Arrays in JavaScript Name of array (Note that all elements of this array have the same name, c ) Position number of the element within array c c[6] c[0]
Topic 9C – Multiple Dimension Arrays. CISC105 – Topic 9C Multiple Dimension Arrays A multiple dimension array is an array that has two or more dimensions.
J. Michael Moore Text Files CSCE 110 From James Tam’s material.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
James Tam Pointers In this section of notes you will learn about another type of variable that stores addresses rather than data.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type arrays.
James Tam Arrays In this section of notes you will be introduced to a composite type where all elements must be of the same type (homogeneous): arrays.
J. Michael Moore Scope & Testing Modules CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
J. Michael Moore Arrays CSCE 110 From James Tam’s material.
J. Michael Moore Modules: Getting information out CPSC 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Getting Started With Pascal Programming What is the basic structure of a Pascal Program Variables in Pascal Performing input and output with.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
J. Michael Moore Input and Output (IO) CSCE 110 Drawn from James Tam's material.
James Tam Composite Types You will learn in this section of notes how to create single and generic instances of non-homogeneous composite types that are.
J. Michael Moore From James Tam’s material Multi-Dimensional Arrays CSCE 110.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
James Tam Arrays / Lists In this section of notes you will be introduced to new type of variable that consists of other types.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
J. Michael Moore From James Tam's material Records CSCE 110.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
J. Michael Moore Modules – the Basics CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
J. Michael Moore Arrays CSCE 110. J. Michael Moore Typical (although simplified) Problem Write a program that will track student grades in a class. The.
James Tam Pointers In this section of notes you will learn about another type of variable that stores addresses rather than data.
James Tam Pointers In this section of notes you will learn about a third type of variable that stores addresses rather than data.
Chapter 8 Arrays and Strings
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
J. Michael Moore Scope & Testing Modules CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Lists In this section of notes you will be introduced to new type of variable that consists of other types.
James Tam Pointers In this section of notes you will learn about another type of variable that stores addresses rather than data.
J. Michael Moore Modules – the Basics CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
ARRAYS 1.Basic Ideas 2.The Array Type 3.Processing Arrays 4.Parallel Arrays 5.Two-dimensional Array 6.Arrays as Parameters.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
Introduction to Pascal The Basics of Program writing.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Pascal Programming Today Chapter 11 1 Chapter 11.
1 STRINGS String data type Basic operations on strings String functions String procedures.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
CSC Programming for Science Lecture 28: Multi-dimensional Arrays.
Computer Programming for Engineers
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
CSE 251 Dr. Charles B. Owen Programming in C1 Intro to Arrays Storing List of Data.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the.
Data Structures: Multi-Dimensional Arrays Damian Gordon.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Multidimensional Arrays
Multidimensional Arrays
Multidimensional array
Arrays In this section of notes you will be introduced to a homogeneous composite type, one-dimensional arrays One-dimensional arrays in Pascal.
Arrays In this section of notes you will be introduced to a composite type where all elements must be of the same type (homogeneous): arrays Homogeneous.
Brent M. Dingle Texas A&M University Chapter 5 – Section 2-3
C++ Array 1.
Presentation transcript:

J. Michael Moore From James Tam’s material Multi-Dimensional Arrays CSCE 110

J. Michael Moore When To Use Arrays Of Different _______________ Determined by the data – the number ____________________ ___________ determines the number ______________ to use. Examples: (1D array) Tracking grades for a class Each cell contains the grade for a student i.e., grades[i] There is _________________ that specifies which student’s grades are being accessed (2D array) Expanded grades program Again there is ____________ that specifies which student’s grades are being accessed The __________________ can be used to specify which lab assignment One dimension (which student)

J. Michael Moore When To Use Arrays Of Different Dimensions (2D array continued) Student Lab grade First student Second student Third student … Lab1 Lab2 Lab3 Lab4 Lab5 : LabN

J. Michael Moore When To Use Arrays Of Different Dimensions (2D array continued) Notice that each row is merely a _________ A _________ is an array containing rows of _________ [1][2][3][4] [1] [2] [3] [4] [5] Columns Rows

J. Michael Moore When To Use Arrays Of Different Dimensions (3D array – take the ________ but allow for multiple ______). The _______________________ specifies which section grades are being tracked. Student (X = column) Lab Assignment (Y = row) Section (Z) Note: 1.The standard approach for specifying the dimensions is to specify the row coordinate (Y) and then the column coordinate (X). 2.The size of a _________ must be the same for all elements along that _______ e.g., all ____ must be of the same ____

J. Michael Moore When To Use Arrays Of Different Dimensions Lab6 Lab1 Lab2 Lab3 Lab7 Lab5 Lab4 Student 3…Student 2Student 1 Section 501 Section 502 Section 503

J. Michael Moore Format: (Two dimensional arrays) Name : array [min..max, min..max] of type; (Three dimensional arrays) Name : array [min..max, min..max, min..max] of type; Examples: var johnFinances : array [1..3, 1..7] of real; var cube : array [1..6, 1..6, 1..6] of char; Declaring Multi-Dimensional Arrays ____________

J. Michael Moore Declaring Multi-Dimensional Arrays As A Type Format: Type declaration Type name = array [min..max, min..max] of element type; name = array [min..max, min..max, min..max] of element type; Variable declaration array name : Type name;

J. Michael Moore Declaring Multi-Dimensional Arrays As A Type Example: Type declaration Finances = array [1..3, 1..7] of real; Cube = array [1..6, 1..6, 1..6] of char; Variable declaration var johnFinances : Finances; var aCube : Cube;

J. Michael Moore Accessing / Assigning Values To Elements Format: name [row][column] := value; Example: finances [1][1] := 4500; writeln (finances[1][1]); OR finances [1, 1] := 4500; writeln (finances[1, 1]);

J. Michael Moore Multi-Dimensional Arrays And Input/Output Arrays of ___________________ (including multi-dimensional _________________ arrays) cannot be passed as parameters to: read, readln, write, writeln. Only ______________________ can be passed as parameters to these procedures.

J. Michael Moore A Character-Based Grid program gridExample (input, output); const MAX_ROWS = 4; MAX_COLUMNS = 4; NUM_COMBINATIONS = 10; type Grid = array[1..MAX_ROWS, 1..MAX_COLUMNS] of char;

J. Michael Moore A Character-Based Grid (2) function generateElement (temp : integer) : char; var anElement : char; begin case (temp) of 1, 2, 3, 4, 5, 6 : anElement := ' '; 7, 8, 9: anElement := '*'; 10: anElement := '.';

J. Michael Moore A Character-Based Grid (3) else {still in case statement} begin writeln(' >'); writeln('<< Value should be 1-',NUM_COMBINATIONS, ' but random value is ', temp); anElement := '!'; end; generateElement := anElement; end;

J. Michael Moore A Character-Based Grid procedure initialize (var aGrid : Grid); var r : integer; c : integer; temp : integer; begin for r := 1 to MAX_ROWS do begin for c := 1 to MAX_COLUMNS do begin temp := random(NUM_COMBINATIONS) + 1; aGrid[r][c] := generateElement(temp); end;

J. Michael Moore A Character-Based Grid (5) procedure display (aGrid : Grid); var row: integer; column: integer; begin for row := 1 to MAX_ROWS do begin for column := 1 to MAX_COLUMNS do begin write(aGrid[row][column]); end; writeln; end;

J. Michael Moore A Character-Based Grid (6) procedure displayLines (aGrid : Grid); var row : integer; column : integer; begin for row := 1 to MAX_ROWS do begin writeln(' '); for column := 1 to MAX_COLUMNS do begin write('|', aGrid[row][column]); end; writeln('|'); end; writeln(' '); end;

J. Michael Moore A Character-Based Grid (7) begin var aGrid : Grid; initialize(aGrid); writeln('Displaying grid'); writeln('==============='); display(aGrid); writeln; writeln('Displaying grid with bounding lines'); writeln('=========================='); displayLines(aGrid); end.