CSE 1301 Lecture 14 2D Arrays Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
CSE 1301 Lecture 5B Conditionals & Boolean Expressions Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Arrays. INTRODUCTION TO ARRAYS Just as with loops and conditions, arrays are a common programming construct and an important concept Arrays can be found.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Numbers and Arrays. Widening and narrowing Numeric types are arranged in a continuum: double float long int short byte, char You can easily assign a narrower.
1 CSE1301 Computer Programming: Lecture 35 Revision.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Data Representation and Alignment Topics Simple static allocation and alignment of basic types and data structures Policies Mechanisms.
CSE1301 Computer Programming: Revision. Topics Type of questions What do you need to know? About the exam Exam technique Sample questions.
CSE 1301 J Lecture 13 Sorting Richard Gesick. CSE 1301 J 2 of 30 Sorting an Array When an array's elements are in random order, our Sequential Search.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
C Static Arrays Pepper. What is an array? Memory locations – same type – next to each other (contiguous) – Same name – Indexed by position number of type.
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
CSCI 171 Presentation 4. Execution of a C Program Execution starts in main( ) Top down style –sequential flow Unrealistic to expect sequence in more complicated.
CSE 1301 Lecture 5 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CS-1030 Dr. Mark L. Hornick 1 C++ Language Basic control statements and data types.
CSE 1301 Lecture 8 Conditionals & Boolean Expressions Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
ITEC 320 Lecture 11 Application Part Deux Look Ahead.
CSE 1301 Lecture 6 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1.2 Primitive Data Types and Variables
Chapter One Lesson Three DATA TYPES ©
CS 31 Discussion, Week 5 Faisal Alquaddoomi, Office Hours: BH 2432, MW 4:30-6:30pm, F 12:00-1:00pm (today)
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
CS 180 Recitation 7 Arrays. Used to store similar values or objects. An array is an indexed collection of data values of the same type. Arrays are the.
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
CS 31 Discussion, Week 7 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Object Oriented Programming Lecture 2: BallWorld.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
CSE 1301 Lecture 12 Arrays Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Java Programming Language Lecture27- An Introduction.
Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
The Hardware/Software Interface CSE351 Winter 2013
Lecture 9 Arrays Richard Gesick.
Unit-2 Objects and Classes
Lecture 13 Dynamic Collections Richard Gesick
Computers & Programming Languages
Lecture 6 2d Arrays Richard Gesick.
Lecture 4 2d Arrays CSE /26/2018.
1D Arrays and Lots of Brackets
INC 161 , CPE 100 Computer Programming
Lecture 14 2D Arrays Richard Gesick.
1D Arrays and Lots of Brackets
Ps Module 7 – Part II 2D Arrays and LISTS 5/26/2019 CSE 1321 Module 7.
1D Arrays and Lots of Brackets
Ps Module 7 – Part II 2D Arrays and LISTS 8/29/2019 CSE 1321 Module 7.
Presentation transcript:

CSE 1301 Lecture 14 2D Arrays Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick

CSE D vs 1D Arrays Still hold several values of the same type (homogeneous) Still based on a slot number (the index number), but has two now Still have instant access Still Static

CSE 1301 What 2D arrays look like myArray [6,0] [6,1][6,2][6,3][6,4][6,5][6,6] [5,0] [5,1][5,2][5,3][5,4][5,5][5,6] [4,0] [4,1][4,2][4,3][4,4][4,5][4,6] [3,0] [3,1][3,2][3,3][3,4][3,5][3,6] [2,0] [2,1][2,2][2,3][2,4][2,5][2,6] [1,0] [1,1][1,2][1,3][1,4][1,5][1,6] [0,0] [0,1][0,2][0,3][0,4][0,5][0,6]......

CSE 1301 Creating 2D Arrays [,] = new [, ]; Notice – The comma – The columns and rows values

CSE 1301 Examples An array of shorts: short[,] someArray = new short[50,5]; An array of floats: float[,] myArray = new float[25,10]; An array of booleans: bool[,] list = new bool[640,480]; An array of chars: char[,] characters = new char[2,2];

CSE 1301 Modifying a 2D Array myArray [6,0] [6,1][6,2][6,3][6,4][6,5][6,6] [5,0] [5,1][5,2][5,3][5,4][5,5][5,6] [4,0] [4,1][4,2][4,3][4,4][4,5][4,6] [3,0] [3,1][3,2][3,3][3,4][3,5][3,6] [2,0] [2,1][2,2][2,3][2,4][2,5][2,6] [1,0] [1,1][1,2][1,3][1,4][1,5][1,6] [0,0] [0,1][0,2][0,3][0,4][0,5][0,6] myArray[2,3] = 42

CSE 1301 Iterating Through 2D Arrays Working with 2D arrays, you will use two loops (nested) Example: byte[,] myPic = new byte[480,640]; for (int x=0; x < 480; x++) { for (int y=0; y < 640; y++) { myPic[x,y] = 0; }

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; }

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 0 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 0 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 0 y What happens?

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 0 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 1 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 1 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 1 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 2 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 2 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 2 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 2 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 3 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 0 x 3 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 1 x

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 1 x

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 1 x 0 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 1 x 0 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 1 x 0 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 1 x 1 y

CSE 1301 Now skipping ahead a bit

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 2 x 1 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 2 x 2 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 2 x 2 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 2 x 2 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 2 x 3 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 2 x 3 y

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 3 x

CSE 1301 Line by Line (a smaller example) byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic 3 x

CSE 1301 Done! byte[,] myPic = new byte[3,3]; for (int x=0; x < 3; x++) { for (int y=0; y < 3; y++) { myPic[x,y] = 1; } myPic...

CSE 1301 Summary 2D Arrays are similar to 1D arrays Usually requires nested loops