iGCSE Computer Science - Distance Learning

Tutor Marked Assignment 6
Tutor Marked Assignment 8 (Programming)

Using Arrays in Programming

Arrays are a large feature of the Computer Science iGCSE and feature in most of the programming tasks that you will be asked to complete for paper 2. This is mainly because after the basic data types, they are the fundamental building blocks of any programming language.

programming with arrays - Computer science revision

In their most basic form they are variables that can hold more than one value. You’ll probably see lots of long and complicated words used when people talk about arrays, but hopefully I can dispel a few myths here.

If you’ve ever written a shopping list, then you’ve written an array and they don’t get much more difficult.

When we start our shopping list, we start with a blank list. Each item on the list is written as a word, so we know in Computer Science terms that this is an array of strings. In pseudocode, this might look like:

myShopping = [ ]

Notice how I’ve used square brackets to tell the computer that this variable is going to hold more than one piece of data. Square brackets is the same across almost every programming language.

Now if I wanted to add an item to my shopping list, I would want to add it to the end. In Computer Science, we call this appending (if it was just writing, then we would be writing over the top of data that is already there). In pseudocode, this looks like:

myShopping.Append(“Apple”)

If I had a list of fruit I would write each item on a new line. In code, instead of a new line, we separate each item with a comma. So after adding my apple, a banana, and a strawberry to my list it would look like this:

[“Apple”,”Banana”,”Strawberry”]

But what if I want to tell someone what the 2nd item on my list is without showing the others?

Well this is where lists really make a big difference to your programs. If you want to find out where something is in a book, you look at the index and you’ll find a page number that you can go to. In an array, an index is a number that tells you where to go in the array to find the item of data that you are looking for. So to tell someone what the 2nd item in the array is we use:

OUTPUT myShopping[1]

Now, hang on just a minute! Was that a typo??? Actually no. Unlike us who count from 1, computers start at 0 which means that the 1st item is item 0, the 2nd is item 1… and so on. For those of you looking for higher grades, it’s worth knowing some technical maths terms at this point:

Ordinal Number: 1st 2nd 3rd…

Cardinal Number: 0, 1, 2, 3…

Practice Task

The code below uses an array to save data. Complete the code to read each item of data from the list to the user.
This is a practice task & is not part of your assignment.

Assignment Task

Designing programs that use arrays is an important part of the iGCSE Computer Science course and these tasks have changed in the new specification. If you are sitting your exam in January 2023 or before, stop here and complete this as your final programming assignment task.

If you are sitting the new specification with exams in May/June 2023 or beyond, use this as a practice task.

The task below is the practice version, please submit your final coded solution using the Tutor Marked Assignment Trinket pages.