18/12/20151 5.2 Arrays 2D Arrays Defining, Declaring & Processing.

Slides:



Advertisements
Similar presentations
Introduction to arrays
Advertisements

30/04/ Selection Nested If structures & Complex Multiple Conditions.
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
Chapter 11: Classes and Objects
Programming Logic and Design Sixth Edition
Chapter 7 Multidimensional Arrays. Defining a two dimensional array elementType[][] arrayName; // Java pro elementType arrayName[][]; // C++ alternate.
Arrays. What is an Array? An array is a way to structure multiple pieces of data of the same type and have them readily available for multiple operations.
Arrays. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Programming with Microsoft Visual Basic 2005, Third Edition
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
An Introduction to Programming with C++ Fifth Edition
Chapter 2: Input, Processing, and Output
Modules, Hierarchy Charts, and Documentation
Finding the mean from a frequency table E.g. the following table shows the mean height of 30 students in our class. Find the mean height Height (x cm)
1.6 Prime and Composite Numbers
08/09/ Arrays Defining, Declaring & Processing.
Processing Arrays Lesson 8 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Chapter 2 Arithmetic Strategies & Area
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Estimating Square Roots The square root of a number is the value that, when multiplied by itself, gives the original number. 2 x 2 = 4 Square RootSquare.
Chapter 2 - Algorithms and Design
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Chapter 12: How Long Can This Go On?
2 dimensional arrays Steven Wood ©2005. Arrays dimensions Java allows arrays with many subscripts 2-D examples Chess board Excel spreadsheet.
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
Input, Output, and Processing
1 2.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works.
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Creating Classes and Objects Chapter Microsoft Visual Basic.NET: Reloaded 1.
27/05/ Iteration Loops Nested Loops & The Step Parameter.
30/10/ Iteration Loops Do While (condition is true) … Loop.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
22/11/ Selection If selection construct.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Level34567 Place Value and Calculations 2 I can round whole numbers to the nearest 10, 100 or I can find multiples of any numbers up to 12. I can.
Arrays Version 1.1. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
05/02/ Records. 205/02/2016 Learning Objectives State: The difference between records and arrays. The difference between records and arrays. How.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
02/03/ Strings Left, Right and Trim. 202/03/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
2-dimensional Arrays A 2-dimensional array has rows and columns It is actually an “array of arrays” A Tic-Tac-Toe board is an example of a 3 by 3 2-d array.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Do Now: 1. The volume of a cube is 64 cm. What is the length of one side? 2. A square room has 2 foot by 2 foot square tiles comprising the floor. If the.
FACTors and Multiples.
Lab 5 Arrays ► Lab 4 Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Lecture 07 More Repetition Richard Gesick.
Lecture 4B More Repetition Richard Gesick
Do While (condition is true) … Loop
3.1 Iteration Loops For … To … Next 18/01/2019.
Nested Loops & The Step Parameter
2D Arrays Defining, Declaring & Processing
Random Access Files / Direct Access Files
Review of Previous Lesson
8 Records 25/07/2019.
Presentation transcript:

18/12/ Arrays 2D Arrays Defining, Declaring & Processing

218/12/2015 Learning Objectives Explain the concept of 2D arrays. Explain how to declare and reset them.

318/12/2015 Declaring 2D Arrays Dim …(…, …) As … 1D Size 2D Size

418/12/2015 2D Arrays e.g. a firm’s quarterly sales figures for the years 1990 – (quarters) x 10 (years) = 40 items of data 4 (quarters) x 10 (years) = 40 items of data Dim SalesFigures(4, 10) As Decimal

518/12/2015 2D Arrays Each row is a year. Each column is a quarter. e.g. Sales was €56800 in the 3 rd quarter of Sales was €56800 in the 3 rd quarter of SalesFigures(2,0) = Sales was €96400 in the 4 th quarter of Sales was €96400 in the 4 th quarter of SalesFigures(4,9) =

618/12/2015 Uses for 2D Arrays Useful for storing data for some mathematical problems. Limited use for ‘business’ type problems because all data items have to be of the same type.

Resetting 2D arrays To reset 2D arrays you will need to 2 nested loops to loop through each column and each row. For Column = 1 To …. For Column = 1 To …. For Row =1 To …. Array (Column, Row) = …. Array (Column, Row) = …. Next Row Next Column Next Column 718/12/2015

Pseudocode will use the following structures: DECLARE : ARRAY[ : ] OF So for an array of elements numbered from 1 – 10: DECLARE : ARRAY[ : ] OF DECLARE : ARRAY[ :,[ : ] OF

Extension “Store BIKE IDs” Program 5.2a Super Bikes owns a rectangular parking area with 30 rows; each row has 4 bike spaces. Each bike is always parked in the same space. The array BikeSpace[30,4] stores the bike registrations. Soni uses a flowchart to help him design a module to populate the array with the bike registrations. Input is terminated using the rogue value “BK000”. Write this program and allow the user to see the contents of the array. Also include a “Reset” option.

Extension “Chess Board1” Program 5.2b Liliane wants to write a program to play chess. She will represent the board of 4 x 4 squares, using a 2-dimensional array. If a chess piece is on a square, it will take a value of 1. Write a program to accept row and column numbers and place a 1 at this position and re- display the board. To display the initially empty board: Remember to use: Console.Write(…) Console.WriteLine() As appropriate and as used in presentation 3.2,3.2 Allow a Reset option

Extension “Chess Board2” Program 5.2c Produce a different version of the previous “Chess Board1” program. Liliane's next task is to indicate that there are pieces occupying the first two rows of the 4 x 4 board. Each square in rows 1 and 2 will be given the value 1. Add initial code that occupies the first two rows of the 4 x 4 board with 1’s and clears the other rows. This is all this version needs to do.

Extension “Chess Board3” Program 5d Produce a new version of the previous “Chess Board2” program that uses DO While Loops (as you probably used For To Next Loops originally). Occupies the first two rows of the 4 x 4 board with 1’s and clears the other rows but with DO While Loops.

Extension “Tiles” Program 5e Ahmed runs his own business. He lays floor tiles in rooms for customers by combining white tiles with tiles of one other colour to make a pattern. Here is one example: The width and length of a room will measure at least 100 cm and less than 1000 cm. The size of one floor tile is 30 cm × 30 cm. If the room measurements are not exact multiples of 30 cm, the number of tiles must be rounded up so that Ahmed has enough tiles. Ahmed wants the program to add an extra 10% to the number of tiles required in case any tiles get broken during the work. The program must calculate the total number of tiles required, TilesRequired, after the values for RoomLength and RoomWidth have been input and validated (using 1 logic expression). 1318/12/2015

Extension “Tile Designs” Program 5f 14 18/12/2015 Ahmed combines white tiles with tiles of one other colour to make a pattern. He draws a design. Here is one example: Here is one example: Ali stores the design in a 2-dimensional array, FloorDesign. The length and width of the room will be no more than 9 tiles each. Write a program for Ahmed which: Initially, makes every tile white. Initially, makes every tile white. Asks the user to enter the size of a design. Asks the user to enter the size of a design. e.g. 2 tiles by 3 tiles Asks the user to enter the design Asks the user to enter the design e.g. Note that with this method the user will enter each row of the design and be expected to know to press the Enter key after each row. If you can think of a better way please do so. Then calculates the number of white tiles and the number of coloured tiles in the design. Then calculates the number of white tiles and the number of coloured tiles in the design. Allows the user to reset and start again. Allows the user to reset and start again.

1518/12/2015 Plenary Explain the concept of 2D arrays. Explain how to declare and reset them.

1618/12/2015 Declaring 2D Arrays Dim …(…, …) As … 1D Size 2D Size

Resetting 2D arrays To reset 2D arrays you will need to 2 nested loops to loop through each column and each row. For Column = 1 To …. For Column = 1 To …. For Row =1 To …. Array (Column, Row) = …. Array (Column, Row) = …. Next Row Next Column Next Column 1718/12/2015