Download presentation
Presentation is loading. Please wait.
Published byMadlyn Davis Modified over 9 years ago
1
Introduction to Arrays Presenter: Mrs. McCallum-Rodney
2
Introduction Variables hold ONE value at a given time Arrays hold MULTIPLE values of the same type under one name.
3
WHAT ARE ARRAYS? An array is a set of data of the same type grouped together and referred to by one name. Any collection of homogeneous data (data of the same type) is well-suited for storage in arrays.
4
WHY USE ARRAYS? Arrays provide a mechanism for declaring and accessing several data items with only one identifier, thereby simplifying the task of data management. As programs become larger and more complicated, it becomes increasingly difficult to manage the data. Variable names typically become longer to ensure their uniqueness. And, the number of variable names makes it difficult for the programmer to concentrate on the more important task of correct coding.
5
Real life example of an array A motel with rooms. It has a collection of rooms, each with its unique number.
6
Let’s play CHARADEs Rules: 1.Go into your major groups create a list of 10 real life arrays. 2.Each group will choose a representative to act out (no talking or writing) their real life array. The first group to get it correct in one minute will get a point ; the presenting group will also receive a point if they could guide a group to the right answer. 3.No group can present on array already guessed correctly. 4.If the answer is not an array, the presenting group will lose a point.
7
END OF LESSON ONE
8
LESSON TWO Structure of Arrays
9
STRUCTURE OF ONE – DIMENSIONAL ARRAYS? If you will need to store 10 integer numbers and still have access to all numbers entered, then entering the numbers into an array will be appropriate. Consider the following array: Number 1125111971-11874316
10
STRUCTURE OF ONE – DIMENSIONAL ARRAYS? Number Values1125111971-11874316 How many elements are in the array?10 Each element has a number assigned to it – this is known as the SUBSCRIPT. The subscript identifies each item in the array. If you need to access values from the array, you will need to state the name of the array and the index (subscript) number. The same goes for putting data into the array. Subscript12345678910
11
UNDERSTANDING ARRAYS? Number Values11285111971-11874316 Subscript12345678910 What is the value in the 4 th element of the array? What is in Number[8]? What is in Number[2]? Where is the value -11 stored? Where is the value 16 stored? 1 87 28 Number[7] Number[10]
12
UNDERSTANDING ARRAYS? STUDENT_NAME ValuesALTEVETAJEWEL-ANNALECIAROXANNERENEESUZAN Subscript123456 What is the name of the array? How many elements are in the array? What is the data type for STUDENT_NAME What is the value in the 5 th element of the array? What is in STUDENT_NAME[2]? Where is the value SUZAN stored? STUDENT_NAME 6 string RENEE JEWEL-ANN STUDENT_NAME[6]
13
DO THE CROSSWORD PUZZLE ACTIVITY
14
DECLARING ARRAYS In every algorithm and program you will need to state each variable that you will be using and its data type. This is known as “DECLARING” variables. To declare an integer array called “Number”, to hold 10 values, you will do the following: PSEUDOCODE DECLARE Number AS integer array of size 10
15
DECLARING ARRAYS Question 1 Declare an array called ‘teachaddr’, to hold addresses of 50 teachers. PSEUDOCODE DECLARE teachaddr AS string array of size 50
16
DECLARING ARRAYS Question 2 Declare an array called ‘costprice’, to hold the price of 1000 items in store PSEUDOCODE DECLARE costprice AS real array of size 1000
17
DECLARING ARRAYS Question 3 Declare an array called ‘answer’, to hold the answer of ‘Y’ or ‘N’ for 25 questions in a questionnaire. PSEUDOCODE DECLARE answer AS character array of size 25
18
ASSIGNING VALUES TO ARRAY ELEMENTS STUDENT_NAME ValuesKerri- Ann Allyandra Subscript123456 Place the value Kerri-Ann into third element of STUDENT_NAME. PSEUDOCODE STUDENT_NAME[3] ← “Kerri-Ann” Place the value Allyandra into last element of STUDENT_NAME. PSEUDOCODE STUDENT_NAME[6] ← “Allyandra”
19
END OF LESSON TWO
20
FILLING AN ARRAY using a FOR LOOP Grades Values76891006790 Subscript12345 Pseudocode segment. FOR count ← 1 TO 5 PRINT “Enter grade for student” READ Grades[count] ENDFOR.
21
Question: Write an algorithm pseudocode to accept the names and ages of 100 students. FILLING AN ARRAY using a FOR LOOP START DECLARE count AS integer DECLARE sname AS string array of size 100 DECLARE sage AS integer array of size 100 FOR count ← 1 TO 100 PRINT “Enter name of student” READ sname[count] PRINT “Enter the age of student” READ sage[count] ENDFOR STOP
22
PRINTING VALUES from ARRAY ELEMENTS STUDENT_NAME ValuesKRYSSALSHANICEJODY-GAYEMARSHASARANAMELIA Subscript123456 PRINT the value in first element of STUDENT_NAME. PSEUDOCODE PRINT STUDENT_NAME[1] Print the value in the fourth element of STUDENT_NAME. PSEUDOCODE PRINT STUDENT_NAME[4] KRYSSAL MARSHA
23
PRINTING ALL VALUES in an ARRAY STUDENT_NAME ValuesKRYSSALSHANICEJODY-GAYEMARSHASARANAMELIA Subscript123456 KRYSSAL SHANICE Pseudocode segment. FOR count ← 1 TO 6 PRINT STUDENT_NAME[count] ENDFOR. JODY-GAYE MARSHA SARAN AMELIA
24
The End of Lesson on Arrays Hope you have learnt a lot.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.