2D arrays – OCR GCSE Computer Science lesson (J277)
Pupils learn to declare a 2D array, read and change an element using its row and column indexes, and use nested FOR loops to process every element.
Lesson 8 of 11 in unit 10.4 Characters, Images, Sound, Strings and Arrays, taught in Year 10, Spring 2. It answers one big question: How can a program store a table of data?
By the end, pupils can declare a 2D array, read and change an element using its row and column indexes, and use nested FOR loops to process every element.
- The Build (the main task)
- Write a program that stores the campsite map as a 2D array of 3 rows × 4 pitches ("F" = free, "T" = taken), using the map shown. It should input a row index and a pitch index, book that pitch by changing it to "T", then use nested FOR loops to count and print how many pitches are still free.
- Support version
- Part-filled code: the 2D array and both loops are given with gaps for the two indexes and the counting line.
- Challenge
- Refuse a booking if the pitch is already taken, and print the map row by row with its row number.
- Real-world link
- The campsite map is a grid of pitches, each free or taken.
- Key words
- 2D array, Index and Grid, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “camp[2][1] means column 2, row 1”; “camp[1] gives one pitch”.
- OCR J277 specification
- 2.2.3 (additional programming techniques: string manipulation (length, case, substrings, concatenation, ASCII conversion) and 1D and 2D arrays).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Pupils need computers for the main task.
Also sold in the Characters, Images, Sound, Strings and Arrays unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for GCSE Computer Science (OCR)
See allPupils learn to explain how a character set gives each character a binary code, encode and decode text with ASCII, and compare ASCII and Unicode by bits per character and range.
Free sample lessonPupils learn to use concatenation, length, slicing, upper and lower case and ASCII conversion in Python and OCR Exam Reference Language to build and extract parts of strings.
Pupils learn to explain how a bitmap image is stored as pixels with binary colour codes, and describe how colour depth and resolution affect quality and file size.
Written for the specifications named. Not endorsed by or affiliated with any exam board.