1 Multidimensional Arrays Chapter 13 2 The plural of mongoose starts with a "p" 0 1 2 3 4 01230123 Initializing a multidimensional array Processing by.

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

Chapter 7: Arrays In this chapter, you will learn about
1 Arrays … The Sequel Applications and Extensions Chapter 10.
Let’s Look at Some Functions Boolean Functions – functions that return ‘true’ or ‘false’ Other Functions – some with arguments, some with none.
Arrays. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
TK1914: C++ Programming Array II. Objective In this chapter you will explore how to manipulate data in a two-dimensional array. 2FTSM :: TK1914,
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.
1 Arrays In many cases we need a group of nearly identical variables. Example: make one variable for the grade of each student in the class This results.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Multiple-Subscripted Array
Chapter 5 - Arrays CSC 200 Matt Kayala 2/27/06. Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays.
Chapter 9: Arrays and Strings
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
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.
1 Lecture 22 Chapter 12 Arrays Dale/Weems/Headington.
Multidimensional Arrays C++ also allows an array to have more than one dimension. For example, a two-dimensional array consists of a certain number of.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Chapter 8 Arrays and Strings
Arrays- Part 2 Spring 2013Programming and Data Structure1.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
1 Topic: Array Topic: Array. 2 Arrays Arrays In this chapter, we will : Learn about arrays Learn about arrays Explore how to declare and manipulate data.
Defining a 2d Array A 2d array implements a MATRIX. Example: #define NUMROWS 5 #define NUMCOLS 10 int arr[NUMROWS][NUMCOLS];
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Slide 1 Chapter 5 Arrays. Slide 2 Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays  Arrays in memory.
Chapter 5 Arrays. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 Learning Objectives  Introduction to Arrays  Declaring and referencing.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
1 Arrays and Strings Lecture: Design Problem l Consider a program to calculate class average Why?? ?
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Arrays Version 1.1. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Fall 2013CISC2200 Yanjun Li1 Review. Fall 2013CISC2200 Yanjun Li2 Outline Array Pointer Object-Oriented Programming.
Arrays.
Module 1: Array ITEI222 - Advance Programming Language.
Opening Input/Output Files ifstream infile; ofstream outfile; char inFileName[40]; char outFileName[40]; coutinFileName;
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
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.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Arrays Chapter 12. One-Dimensional Arrays If you wanted to read in 1000 ints and print them in reverse order, it would take a program that’s over 3000.
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
Chapter 5 Arrays Copyright © 2016 Pearson, Inc. All rights reserved.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Arrays.
Two-Dimensional Arrays
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Computer Programming BCT 1113
Arrays … The Sequel Applications and Extensions
Array Data Structure Chapter 6
Array Data Structure B.Ramamurthy 11/21/2018 B.Ramamurthy.
Engr 0012 (04-1) LecNotes
Multidimensional Arrays
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Array Data Structure Chapter 6
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
C++ Array 1.
Arrays.
Presentation transcript:

1 Multidimensional Arrays Chapter 13

2 The plural of mongoose starts with a "p" Initializing a multidimensional array Processing by row Processing by column Printing the contents of an array

3 Two dimensional Arrays n A collection of components –all of the same type –structured in TWO dimensions –each component accessed by a PAIR of indices representing the component’s position in each dimension Which cell is Location (2,3) ?

4 Declaring Two Dimensional Arrays Syntax: data_type array_name [row_dim][col_dim]; Syntax: data_type array_name [row_dim][col_dim]; n Example: n First element is int_table n First element is int_table[0][0] n Last element is int_table n Last element is int_table[4][3] int int_table [5][4];

5 Processing Two-D Arrays n Arrays processed in some pattern –random –along rows –along columns –whole array n We will use the declaration shown below: int int_table [5][4]; int row, col;

6 Processing Two-D Arrays n What does the routine below do with the array? What should we name the function? 0 total_a_row

7 Processing Two-D Arrays n What does this routine below do with the array? What should we name the function? 0 total_column

8 Processing Two-D Arrays n This function initializes an array. n Fill in the blanks with the correct identifiers 3 col tablevalue

9 Printing a Table n We must process each row, item by item n Which will be the inner loop? Which will be the outer loop? n The LCV of the inner loop must be the one which changes the most often What goes here? row col endl

10 Passing Arrays as Parameters n Recall declaration for 1-D array n we didn’t specify the size in the brackets –we sent the size as a separate parameter n Recall name of the array is a pointer constant –tells where the array starts in memory –this is what is passed to the function void whatever ( float num_list [ ], int size);

11 Passing 2-D Arrays as Parameters n For a 2-D array, declare n We are sending the starting address –also how many elements it takes to jump us to the next row –that is -- the number of columns n Note that this could be for an array for ANY number of rows, but exactly 4 columns n As with 1-D, we also send another parameter for the function as a limiting value void whatever ( float num_table [ ][4], int num_rows);

12 Alternate 2-D Array Definition n Think of the 2-D array as an array of arrays n Example Each element of renters is an array of rent_pmts Each element of renters is an array of rent_pmts typedef float rent_pmts [12]; rent_pmts renters [6]; 01…501…5 0 1 … 10 11

13 Multidimensional Arrays n C++ arrays not limited to two dimensions –limitation is amount of memory const int NUM_BLDGS = 10; const int APTS_PER_BLDG = 12; float apt_pmts [NUM_BLDGS][6][APTS_PER_BLDG];

14 Multidimensional Arrays n C++ arrays not limited to two dimensions –limitation is amount of memory const int NUM_BLDGS = 10; const int APTS_PER_BLDG = 12; float apt_pmts [NUM_BLDGS][6][APTS_PER_BLDG]; This gives a 3-D array with 720 items apt_pmt [bldg][tennant][apt]

15 Testing and Debugging n Initialize all components of an array –no guarantee of what is there to start with n Use the same number of indeces as the declaration of array n Make sure indeces are in order –don’t reverse row and column references

16 Testing and Debugging n Use meaningful identifiers for the array name and indeces n Double check upper and lower bounds on indeces –don’t walk off the edge of the array n When declaring multidimensional array as a formal parameter –must state sizes of all but first dimension

17 Testing and Debugging n When calling function with array as parameter –sizes of multi-dim actual parameter must match exactly sizes of formal n Use typedef statement to define multi- dimensional array type –use this for actual and formal parameter declaration