PROGRAMMING ARRAYS.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Arrays: Higher Dimensional Arrays.
Advertisements

Programming and Data Structure
Arrays Storing Multiple Values. Motels l If you have a room in a motel and they give you room 5, which room is it?
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Arrays. Lesson Objectives  To understand what an array is and it’s function  To know how code and array in VB.
Arrays and Strings. Why? Consider a class of 30 students, each has a score for hw1  Do we want to have 30 variables with different names?  Would it.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
VCE IT Theory Slideshows By Mark Kelly Vceit.com Arrays.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
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.
Introduction to Arrays. Learning Objectives By the end of this lecture, you should be able to: – Understand what an array is – Know how to create an array.
Arrays and Collections
Unit 2 Technology Systems
Chapter 11 - JavaScript: Arrays
VCE IT Theory Slideshows
Review Array Array Elements Accessing array elements
Two-Dimensional Arrays
Computer Programming BCT 1113
Microsoft Visual Basic 2005: Reloaded Second Edition
Array, Strings and Vectors
Data Types and Structures
Data Structures [1] CP1 Computing CP1 Data Structures 1.
Computer Graphics Index Buffers
Foundations of Programming: Arrays
Introduction to Programming Lecture 5
A simple way to organize data
Student Book An Introduction
Arrays in C.
While Loops BIS1523 – Lecture 12.
Arrays, For loop While loop Do while loop
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
File Handling Programming Guides.
Week 9 – Lesson 1 Arrays – Character Strings
Chapter 8 Arrays Objectives
Coding Concepts (Data Structures)
Lecture 12 Oct 16, 02.
Introduction To Programming Information Technology , 1’st Semester
ARRAYS 1 GCSE COMPUTER SCIENCE.
Arrays
Data Structures – 2D Lists
Starting Out with Programming Logic & Design
Data Types and Data Structures
Arrays ICS2O.
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Data Structures (CS212D) Week # 2: Arrays.
Multidimensional array
Arrays Week 2.
Random Access Files / Direct Access Files
ARRAYS 2 GCSE COMPUTER SCIENCE.
CIS16 Application Development and Programming using Visual Basic.net
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Abstract Data Types, Elementary Data Structures and Arrays
Chapter 8 Arrays Objectives
Programming Logic and Design Fifth Edition, Comprehensive
Learning Intention I will learn how to use an array to store data in a program.
BO65: PROGRAMMING WRITING TO TEXT FILES.
Multi-Dimensional Arrays
To understand what arrays are and how to use them
CS149D Elements of Computer Science
C++ Array 1.
Text / Serial / Sequential Files
Introduction to Computer Programming IT-104
Lecture-Hashing.
Introduction to Computer Science
Presentation transcript:

PROGRAMMING ARRAYS

Objectives Understand different ways of organising data within programming. Know what is meant by an array. Begin using arrays in your programming.

The Problem So far we have seen one way of storing data within our programs by separate variables of different types. if we had 100 customers, we would still need 100 variables (customer1, customer2, customer3, customer4…customer100). What if customer 101 comes along? Your client would not be able to add more variables! To overcome this and aid organisation, we use ARRAYS.

One-dimensional Arrays Imagine then if we could take a variable split it into a number of boxes. If we needed 100 customers, we can simply create 100 little boxes within a box that is, an array. We would have 100 boxes, all with the same name and a different index value. E.g. customer(0), customer(1), customer(2), customer(3)…customer(100).

An Example The array has the name arrCustomers . . . . . . . arrCustomers(100) arrCustomers John Jean Kim The array has the name arrCustomers It was declared in a similar way to a normal variable: Dim arrCustomers(100) as string It has 100 slots in memory. Each slot has it’s own INDEX value. IMPORTANT: Note how VB starts from 0 (not 1), for the first item in the list. Items are referenced in a similar way: arrCustomers(1) = “Jean” console.writeline(arrCustomers(0))

Using Arrays in Parallel arrCustomers(0) … arrCustomers(100)are the elements of arrCustomers. arrBalance(0) … arrBalance(100) are the elements of the array arrBalance. (0)…(1)…(100) this is the INDEX value, i.e. the unique reference to that slot in the array. console.writeline(arrCustomers(0)) would display “John” on the screen. console.writeline(arrCustomers(100)) would display “Kim” on the screen. console.writeline(arrCustomers(0) & “ “ & formatCurrency(arrBalance(0)) would display “John £12.54” arrBalance(100) = 625.25 would assign the value 625.25 to arrBalance, item 100.

Declaring ONE Dimensional Array Dim arrName(size) As elementType Examples: Dim weeklyRent(52) As Single Dim mySalary(2000)As Integer

Why bother using arrays? Are all of the data to be stored related? The data in the array must need to be stored You intend to do something with the data. It is more efficient to than use a lot of variables.

Two Dimensional Arrays So far we have seen that arrays are like a column of data which can store a set of values within one variable. If you wanted to store related data then you could have separate arrays. For example you could have an array for: Football Team Names STRINGS Matches Played INTEGER Matches Won INTEGER Matches Drawn INTEGER Matches Lost INTEGER Points INTEGER

Thinking more into it Having an array for each of these would be rather large and would take us back a step in efficiency and structured programming. If you stored it on paper, you would store it like this: Well, so would a computer, with the added INDEXing system, starting from ZERO. This is called a TWO DIMENSIONAL ARRAY.

Declaring a 2D Array Dim ArrayName(Rows, Columns) AS type For example: Dim football(3,5) as string would create the table above (remember we start from zero).

Using a 2D Array Example: Football(0,1) = “Middlesbrough” Football(0,2) = “Aresenal” Football(0,3) = “Manchester United”) Football(1,1) = “20” note we put it in quotes as it is a STRING array. Football(2,1) = “15”