0% found this document useful (0 votes)
42 views10 pages

1D Arrays

Uploaded by

jokante1151
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views10 pages

1D Arrays

Uploaded by

jokante1151
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

AS & A LEVEL COMPUTER SCIENCE 9618

1 DIMENSIONAL ARRAYS
Store a list of variables of the same data type.
Conceptual Explanations
1. Stores multiple values
2. Data stored is of the same type
3. Data is stored in array positions known as Index

Array Name
Upper Bound Index

Lower Bound Index

1 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

Array Operations

1. Array Declaration/Creation
DECLARE <Array-Name> : ARRAY[Lower Bound Index : Upper Bound Index] OF <DataType>

Example;
DECLARE StudentNames : ARRAY[1:10] OF STRING

Array Size

Visual representation of declaration statement above

2 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

Array Operations
2. Storing and Display/Access values from an array
Example;
Create an array of size 3 called StudentNames and use it to store the names in brackets respectively (“Bill”,
”Greta”, ”Daniella”)
Soln:
1.Creating an array
DECLARE StudentNames : ARRAY[1:3] OF STRING

2.Storing values into an array


StudentNames[1] ”Bill”
StudentNames[2] ”Greta”
StudentNames[3] ”Daniella”

NOTE: When storing and retrieving array elements we shall always use a
for loop
3. Accessing array elements
Qtn: Retrieve array value in position or array index 2
OUTPUT StudentNames[2]

3 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

Array Pseudocodes
Qtn 1: Write a pseudocode program which inputs a number and store it in array position 2.
(Array name is Numbers and size is 5)

DECLARE Numbers : ARRAY[1:5] OF INTEGER


DECLARE ValueToInput : INTEGER
INPUT ValueToInput
Numbers[2] ValueToInput
Qtn 2: Construct an array of 100 elements and store “No Data” in all elements. Name of array is ResultArray
DECLARE ResultArray : ARRAY[1:100] OF STRING
DECLARE Index : INTEGER
FOR Index 1 TO 100
INPUT ResultArray[Index]
NEXT Index

Qtn 3: Use a for loop to retrieve all stored array elements in question2
FOR Index 1 TO 100
OUTPUT ResultArray[Index]
NEXT Index

4 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

Searching In An Array
NOTE: For searching we shall use a condition.
Qtn 1: There is an array which contains names of 500 students, search at which position is “Lucy” stored.(Array Name =
“StudentNames”)
DECLARE Index : INTEGER
FOR Index 1 TO 500
IF StudentNames[Index] = “Lucy”
THEN
OUTPUT Index
ENDIF
NEXT Index

Qtn 2: Already there is an array named “SearchBox” with 500 elements of data type String. Search through the array and
find out how many times “Empty” was repeated
DECLARE Index : INTEGER
DECLARE EmptyCount : INTEGER
EmptyCount 0
FOR Index 1 TO 500
IF SearchBox[Index] = ”Empty”
THEN
EmptyCount EmptyCount+1
OUTPUT EmptyCount
ENDIF
NEXT Index

5 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

EXAM STYLE QUESTIONS

6 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

EXAM STYLE QUESTIONS

7 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

EXAM STYLE QUESTIONS

8 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

EXAM STYLE QUESTIONS

9 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

EXAM STYLE QUESTIONS

10 Davis_Kazibwe@2023KIS

You might also like