2D Arrays Defining, Declaring & Processing

Slides:



Advertisements
Similar presentations
30/04/ Selection Nested If structures & Complex Multiple Conditions.
Advertisements

Chapter 7 Multidimensional Arrays. Defining a two dimensional array elementType[][] arrayName; // Java pro elementType arrayName[][]; // C++ alternate.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
08/09/ Arrays Defining, Declaring & Processing.
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.
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.
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.
27/05/ Iteration Loops Nested Loops & The Step Parameter.
30/10/ Iteration Loops Do While (condition is true) … Loop.
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.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
18/12/ Arrays 2D Arrays Defining, Declaring & Processing.
05/02/ Records. 205/02/2016 Learning Objectives State: The difference between records and arrays. The difference between records and arrays. How.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
02/03/ Strings Left, Right and Trim. 202/03/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
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.
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.
Transparency 5 Click the mouse button or press the Space Bar to display the answers.
Unit 2 Technology Systems
Arrays.
Microsoft Office Access 2010 Lab 1
ALGORITHMS AND FLOWCHARTS
Topics Designing a Program Input, Processing, and Output
INTRODUCTION TO PROBLEM SOLVING
REPETITION CONTROL STRUCTURE
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Objectives Design a form Create a form Create text fields
Chapter 2: Input, Processing, and Output
Superior Pools Marketing Project
Chapter Topics 11.1 Introduction to Menu-Driven Programs
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Standard Algorithms Higher Computing.
Multi-dimensional Array
JavaScript: Functions.
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture 07 More Repetition Richard Gesick.
Lecture 4B More Repetition Richard Gesick
Control Structure Senior Lecturer
More Loops.
If selection construct
Do While (condition is true) … Loop
Patterns to KNOW.
If selection construct
3.1 Iteration Loops For … To … Next 18/01/2019.
Nested Loops & The Step Parameter
Random Access Files / Direct Access Files
Retail Sales is used to illustrate a first dimensional model
ARRAYS 2 GCSE COMPUTER SCIENCE.
CIS16 Application Development and Programming using Visual Basic.net
Using screens and adding two numbers - addda.cbl
Topics Designing a Program Input, Processing, and Output
Loops and Arrays in JavaScript
Lets Play with arrays Singh Tripty
Programming Logic and Design Fifth Edition, Comprehensive
Topics Designing a Program Input, Processing, and Output
BO65: PROGRAMMING WRITING TO TEXT FILES.
Review of Previous Lesson
Decimals - ordering and rounding
Chapter 2: Input, Processing, and Output
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Arrays & Loops.
Arrays & Loops.
3.2 Working with Data Scope of variables 29/07/2019.
8 Records 25/07/2019.
Bishopston Comprehensive School
Python Creating a calculator.
Presentation transcript:

2D Arrays Defining, Declaring & Processing 02/02/2019

Learning Objectives Explain the concept of 2D arrays. Explain how to declare and reset them. 02/02/2019

Dim …(…, …) As … Declaring 2D Arrays 1D Size 2D Size 1 2 3 1 2 1 2 3 1 2 02/02/2019 3 3

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

2D Arrays 1 2 3 1 2 3 4 5 6 7 8 9 Each row is a year. 1 2 3 1 2 3 4 5 6 7 8 9 56800 96400 Each row is a year. Each column is a quarter. e.g. Sales was €56800 in the 3rd quarter of 1991. SalesFigures(2,0) = 56800 Sales was €96400 in the 4th quarter of 1999. SalesFigures(3,8) = 96400 02/02/2019 5 5

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. 02/02/2019 6 6

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 Row =1 To …. Array (Column, Row) = …. Next Row Next Column 02/02/2019

Pseudocode will use the following structures: DECLARE <identifier> : ARRAY[<lbound>:<ubound>] OF <datatype> So for an array of elements numbered from 1 – 10: DECLARE <identifier> : ARRAY[<1>:<10>] OF <datatype> DECLARE <identifier> : ARRAY[<lbound1>:<ubound1>,[<lbound>:<ubound2>] OF <datatype>

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, 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). 02/02/2019

Extension “Tile Designs” Program 5f Ahmed combines white tiles with tiles of one other colour to make a pattern. He draws a design. 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. Asks the user to enter the size of a design. e.g. 2 tiles by 3 tiles 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. Allows the user to reset and start again. 02/02/2019

Plenary Explain the concept of 2D arrays. Explain how to declare and reset them. 02/02/2019

Dim …(…, …) As … Declaring 2D Arrays 1D Size 2D Size 1 2 3 4 1 2 3 02/02/2019 16 16

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 Row =1 To …. Array (Column, Row) = …. Next Row Next Column 02/02/2019