Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

Topic 9C – Multiple Dimension Arrays. CISC105 – Topic 9C Multiple Dimension Arrays A multiple dimension array is an array that has two or more dimensions.
CHAPTER 10 ARRAYS II Applications and Extensions.
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 Lecture 21:Arrays and Strings(cont.) Introduction to Computer Science Spring 2006.
1 Lecture 20:Arrays and Strings Introduction to Computer Science Spring 2006.
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.
Chapter 9: Arrays and Strings
Aalborg Media Lab 28-Jun-15 Software Design Lecture 8 “Arrays”
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Prepared by MURLI MANOHAR PGT (COMPUTER SCIENCE) KV,B.E.G., PUNE.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
IE 212: Computational Methods for Industrial Engineering
Chapter 8 Arrays and Strings
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.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
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.
Java Programming: From Problem Analysis to Program Design, 4e
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 9: Arrays J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
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.
Arrays Array –Group of consecutive memory locations –Same name and type To refer to an element, specify –Array name –Position number Format: arrayname.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
© 2004 Pearson Addison-Wesley. All rights reserved October 13, D Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor:
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Chapter overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
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.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
1 Arrays and Strings Lecture: Design Problem l Consider a program to calculate class average Why?? ?
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
Arrays.
1 Chapter 9 Arrays Java Programming from Thomson Course Tech, adopted by kcluk.
Module 1: Array ITEI222 - Advance Programming Language.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Opening Input/Output Files ifstream infile; ofstream outfile; char inFileName[40]; char outFileName[40]; coutinFileName;
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
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.
1 Chapter 9 Arrays Java Programming from Thomson Course Tech, adopted by kcluk.
1.8 Multidimensional Arrays academy.zariba.com 1.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
Arrays. Arrays are objects that help us organize large amounts of information.
 2005 Pearson Education, Inc. All rights reserved Arrays.
1 Two-Dimensional Arrays. 2 Terminology Two-dimensional arrays represent matrices A matrix contains a number of values of the same data type The values.
1 Arrays and Variable Length Parameter List  The syntax to declare a variable length formal parameter (list) is: dataType... identifier.
EGR 2261 Unit 10 Two-dimensional Arrays
Two-Dimensional Arrays
Chapter 8: Arrays Starting Out with C++ Early Objects Ninth Edition
Computer Programming BCT 1113
Lecture 9 Objectives Learn about arrays.
Multidimensional array
Dr. Khizar Hayat Associate Prof. of Computer Science
Arrays.
Presentation transcript:

Arrays (Part II)

Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two dimensions –Sometimes called matrices or tables Declaration syntax: where intexp1 and intexp2 are expressions yielding positive integer values, and specify the number of rows and the number of columns, respectively, in the array C++ Programming: From Problem Analysis to Program Design, Fifth Edition2

Two- and Multidimensional Arrays (cont'd.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition3

Accessing Array Components Syntax: where indexexp1 and indexexp2 are expressions yielding nonnegative integer values, and specify the row and column position C++ Programming: From Problem Analysis to Program Design, Fifth Edition4

Accessing Array Components (cont'd.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition5

Two-Dimensional Array Initialization During Declaration Two-dimensional arrays can be initialized when they are declared: –Elements of each row are enclosed within braces and separated by commas –All rows are enclosed within braces –For number arrays, if all components of a row aren’t specified, unspecified ones are set to 0 C++ Programming: From Problem Analysis to Program Design, Fifth Edition6

Processing Two-Dimensional Arrays Ways to process a two-dimensional array: –Process the entire array –Process a particular row of the array, called row processing –Process a particular column of the array, called column processing Each row and each column of a two- dimensional array is a one-dimensional array –To process, use algorithms similar to processing one-dimensional arrays C++ Programming: From Problem Analysis to Program Design, Fifth Edition7

Processing Two-Dimensional Arrays (cont'd.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition8

Initialization To initialize row number 4 (i.e., fifth row) to 0: To initialize the entire matrix to 0: C++ Programming: From Problem Analysis to Program Design, Fifth Edition9

Print To output the components of matrix : C++ Programming: From Problem Analysis to Program Design, Fifth Edition10

Input To input data into each component of matrix : C++ Programming: From Problem Analysis to Program Design, Fifth Edition11

Sum by Row To find the sum of row number 4 of matrix : To find the sum of each individual row: C++ Programming: From Problem Analysis to Program Design, Fifth Edition12

Sum by Column To find the sum of each individual column: C++ Programming: From Problem Analysis to Program Design, Fifth Edition13

Largest Element in Each Row and Each Column C++ Programming: From Problem Analysis to Program Design, Fifth Edition14

Multidimensional Arrays Multidimensional array: collection of a fixed number of elements (called components) arranged in n dimensions (n >= 1) –Also called an n-dimensional array Declaration syntax: To access a component: C++ Programming: From Problem Analysis to Program Design, Fifth Edition15

Multidimensional Arrays (cont'd.) When declaring a multidimensional array as a formal parameter in a function –Can omit size of first dimension but not other dimensions As parameters, multidimensional arrays are passed by reference only A function cannot return a value of the type array There is no check if the array indices are within bounds C++ Programming: From Problem Analysis to Program Design, Fifth Edition16