Learning Intention I will learn how to use

  • Slides: 13
Download presentation
Learning Intention • I will learn how to use an array to store data

Learning Intention • I will learn how to use an array to store data in a program.

1. 2. 3. 4. 5. 6. Analysis Design Implementation Testing Documentation Evaluation

1. 2. 3. 4. 5. 6. Analysis Design Implementation Testing Documentation Evaluation

How would you store the names of all pupils in the class in a

How would you store the names of all pupils in the class in a program? …

Array • An array is a data structure (a list of data items). •

Array • An array is a data structure (a list of data items). • All the items have the same data type. e. g. in VB to store 20 names in an array: Dim names(20) As String

Array • Each item in an array is called an element. • Each element

Array • Each item in an array is called an element. • Each element is identified by the variable name and an index (number) which identifies the position of the element in the array.

Think of Excel What is the value in A 3? What is the value

Think of Excel What is the value in A 3? What is the value in B 5?

Excel (modified) names ages What is the value in names(7)? What is the value

Excel (modified) names ages What is the value in names(7)? What is the value in ages(10)?

SQA Reference Language for Array • With data (so can work out the data

SQA Reference Language for Array • With data (so can work out the data type): e. g. DECLARE some. Vals INITIALLY [4, 6, 1] • Without data (so must state data type): e. g. DECLARE new. Vals AS ARRAY OF STRING INITIALLY []

SQA Reference Language for Array 1. 2. 3. 4. 5. 6. DECLARE all. Costs

SQA Reference Language for Array 1. 2. 3. 4. 5. 6. DECLARE all. Costs INITIALLY [ 7, 3, 5, 7, 9 ] SET total TO 0 FOR index FROM 1 TO 4 DO SET total TO total + all. Costs(index) END FOR SEND total TO DISPLAY

SQA Reference Language for Array 1. 2. 3. 4. 5. 6. DECLARE all. Costs

SQA Reference Language for Array 1. 2. 3. 4. 5. 6. DECLARE all. Costs INITIALLY [3, 5, 2] SET total TO 0 FOR EACH cost FROM all. Costs DO SET total TO total + cost END FOR EACH SEND total TO DISPLAY

Array in VB

Array in VB

Programming Tasks • Complete the programming tasks on pages 76 -79 • Extension Task

Programming Tasks • Complete the programming tasks on pages 76 -79 • Extension Task Set 7

Success Criteria • I can use arrays to store data.

Success Criteria • I can use arrays to store data.