Revise360The course

Paper 2 · Topic 2.2

2.2 Programming fundamentals

Variables, constants, the three basic constructs, data types and operators, string handling, arrays and sub-programs, file handling, records and SQL and random numbers. Taught in 7 lessons, each with its own 360° room, alongside the unit's PowerPoints, worksheets and lesson plans, and assessed on paper at the end.

The Type foundry lesson room.
2.2 · Lesson 2 Type foundry

What this topic covers

7 lessons, in teaching order.

Each lesson opens with retrieval from earlier lessons, is taught from its PowerPoint, and is explored in its room, where every station has a short explainer and questions. The topic follows the OCR J277 specification, section 2.2.

  1. Lesson 1: Variable store

    How does a program store data, and how does it decide which line to run next?

    Pupils learn to

    • know what variables and constants are, and how a value is assigned to each
    • understand how input and output move data in and out of a program
    • know what sequence, selection and iteration each do to the order a program runs in

    In the room Variables and assignment · Constants · Input and output · Sequence · Selection · Iteration · Final challenge: three constructs

  2. Lesson 2: Type foundry

    Why does a program need to know what type of data it is working with?

    Pupils learn to

    • know the data types integer, real, Boolean, character and string
    • understand why casting is needed and how a value is cast from one type to another
    • know how the arithmetic, comparison and Boolean operators are used

    In the room Data types · Casting · Arithmetic operators · MOD and DIV · Comparison and Boolean operators · String manipulation · Final challenge: work it out

  3. Lesson 3: Array yard

    How does one name hold many values, and how is code broken into reusable pieces?

    Pupils learn to

    • know how one- and two-dimensional arrays are declared, read and changed
    • understand why arrays are zero-indexed and how a loop iterates over one
    • know the difference between a procedure and a function, and between local and global variables

    In the room One-dimensional arrays · Index positions · Two-dimensional arrays · Procedures and functions · Parameters and returns · Local and global · Final challenge: total the crates

  4. Lesson 4: Filing room

    How does a program keep hold of data after it has stopped running?

    Pupils learn to

    • know why a program needs to store data in a file
    • understand how a file is opened, read from, written to and closed
    • know the difference between writing to a file and appending to it

    In the room Why files · Opening a file · Reading a file · Writing to a file · Appending · Closing the file · Final challenge: read the file

  5. Lesson 5: Record vault

    How does a program store a set of related data, and how does it search it?

    Pupils learn to

    • know what is meant by a record, a field and a table of records
    • understand how SELECT, FROM and WHERE are used to search for data
    • know how AND, OR, NOT and LIKE narrow a search down

    In the room What is a record · Fields and data types · SELECT and FROM · WHERE · Boolean operators · LIKE and wildcards · Final challenge: run the query

  6. Lesson 6: Chance machine

    How does a program produce a number that nobody can predict?

    Pupils learn to

    • know what random numbers are used for in a program
    • understand how a random whole number is generated within a given range
    • know that a computer produces pseudo-random numbers from an algorithm and a seed

    In the room Why random numbers · Generating a random number · Choosing the range · Pseudo-random · Random in a loop · Using randomness well · Final challenge: how many rolls

  7. Lesson 7: Revision HQ 2.2

    Which parts of 2.2 am I secure on, and which do I need to revise before the test?

    Pupils learn to

    • know the whole of topic 2.2 well enough to answer without notes
    • understand the mistakes that most often lose marks in programming questions
    • know which lessons are secure and which still need revision before the test

    In the room Constructs recap · Types and operators recap · File handling recap · Records and SQL recap · Arrays recap · Randomness recap · Final challenge: the lane draw · Functions and procedures recap · Local and global variables recap

  8. End-of-topic test

    An assessment sat on paper, with a mark scheme for the teacher.

Key words

The words to use in an answer.

Algorithm
A precise sequence of steps that solves a problem or completes a task, which a person can follow or a computer can carry out as a program.
Append
Adding new data to the end of an existing file while keeping all the data that was already stored in it.
Array
A data structure that stores a fixed number of values of the same data type under one identifier, with each value reached by its index.
Assignment
Storing a value in a variable, written with a single equals sign so the value on the right is placed in the variable on the left.
Boolean
A data type that can hold only one of two values, True or False, often the result of a comparison or condition.
Casting
Converting a value from one data type to another, such as turning the string "42" into the integer 42 with int().
Close
Ending a program's link to a file so that any data still in the buffer is saved to storage and the file is released.
Constant
A named value that is set when the program is written and cannot be changed while the program is running.
Constructs
The three building blocks that control the order in which lines of code run: sequence, selection and iteration.
Data type
The kind of data a value is, such as integer, real, Boolean, character or string, which decides how it is stored and what can be done with it.
DIV
An operator that gives the whole number part of a division and discards any remainder, so 17 DIV 5 gives 3.
Element
A single value stored in an array, found by giving its index position.
Field
One named item of data within a record, such as a name or a price, with its own data type.
File handling
Using a program to open, read from, write to and close files, so that data can be kept on secondary storage.
FROM
The SQL keyword that names the table a query takes its records from.
Function
A sub-program that carries out a task and returns a value to the part of the program that called it.
Global variable
A variable declared in the main program, with the keyword global in the OCR Exam Reference Language, that can be used and changed anywhere in the program.
Index
The number that gives the position of an element in an array, or a character in a string, counting from 0.
Integer
A data type for whole numbers, positive, negative or zero, with no decimal or fractional part.
Iteration
Repeating a set of instructions, either a set number of times (count-controlled) or while a condition stays True (condition-controlled).
Local variable
A variable declared inside a sub-program that exists only while that sub-program runs and cannot be accessed from outside it.
MOD
An operator that gives the remainder left over after whole number division, so 17 MOD 5 gives 2.
Open
Making a link between a program and a file so the file can be read from or written to; it gives back a handle for the file.
Parameter
A variable named in a sub-program's definition that receives a value passed in when the sub-program is called.

And 21 more in the topic glossary, at the back of the pupil workbook.

Common mistakes

Where pupils go wrong.

Ideas that cost marks in this topic, each with the idea that replaces it.

  • = and == mean the same.= assigns a value to a variable; == compares two values and gives True or False.
  • Typing digits into input() gives a number.input() always returns a string. It has to be cast, for example with int(), before doing arithmetic.
  • The first item in an array is at index 1.In Python and most languages the first item is at index 0.
  • A constant is a variable you choose not to change.A constant is declared so that its value cannot be changed while the program runs.

Using it

In the lesson, at home and in intervention.

For teachers

  • The unit's lesson PowerPoints, worksheets and lesson plans, and the end-of-topic assessment with its mark scheme, in the Teacher Portal.
  • Set any lesson for a class with a due date, and see who has finished.
  • Reports show each station as Secure, Revise or Focus from pupils' first attempts, so a small group can go straight back to the right one.
  • Ask for a teacher key

For pupils

  • Sign in with the card your teacher gives you and open any lesson in this topic.
  • Write each key fact in your own words on the worksheet before you check it.
  • In Quiz Mode, pick this topic: every lost mark names the station that teaches it.
  • Pupil sign in