Learning Intention I will learn how to use an array to store data in a program.
Analysis Design Implementation Testing Documentation Evaluation
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). 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 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 A3? What is the value in B5?
Excel (modified) What is the value in names(7)? What is the value in ages(10)? names ages
SQA Reference Language for Array With data (so can work out the data type): e.g. DECLARE someVals INITIALLY [4, 6, 1] Without data (so must state data type): DECLARE newVals AS ARRAY OF STRING INITIALLY []
SQA Reference Language for Array 1. DECLARE allCosts INITIALLY [ 7, 3, 5, 7, 9 ] 2. SET total TO 0 3. FOR index FROM 1 TO 4 DO 4. SET total TO total + allCosts(index) 5. END FOR 6. SEND total TO DISPLAY
SQA Reference Language for Array 1. DECLARE allCosts INITIALLY [3, 5, 2] 2. SET total TO 0 3. FOR EACH cost FROM allCosts DO 4. SET total TO total + cost 5. END FOR EACH 6. SEND total TO DISPLAY
Array in VB
Programming Tasks Complete the programming tasks on pages 76-79 Extension Task Set 7
Success Criteria I can use arrays to store data.