Teachers' Portal  /  A-Level Computer Science 9618  /  Data types and structures  /  Data types and records
Lesson pack · A-Level Computer Science 9618 · 10.1 · AS Level

Data types and records

The right type for the job. Every item of data in a program has a data type that fixes what values it can hold and what you can do with it.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Data types and structures
Syllabus reference
Cambridge International AS and A Level Computer Science 9618, 10.1
Level
AS Level
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 1 of 5 in Data types and structures; leads into 1D and 2D arrays
Central model
Fig. 1: a record variable groups fields of different data types under one identifier
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • Choosing a data type: Pick the type from what the data is and what the program must do with it.
  • Defining a record: A record type is a template.
  • Reading and writing records: Use dot notation to reach a field: the variable name, a full stop, then the field name.
Key points to leave on the board
  • Six types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE; justify each from the data and its use.
  • Digits that are not quantities (phone numbers, IDs) are STRING.
  • Record: TYPE Name, a DECLARE line per field, ENDTYPE; then DECLARE a variable of that type.
  • Access: Variable.Field; in an array of records, Array[Index].Field.
The core visual model

One picture every idea returns to

A data type decides which values a variable can store and which operations are allowed on it. 9618 pseudocode uses INTEGER, REAL, CHAR, STRING, BOOLEAN and DATE. A record is a composite (user-defined) data type that holds a set of related data items, called fields, which can be of different data types, all under one identifier. It is defined with TYPE ... ENDTYPE and each field is accessed with dot notation, such as Pupil1.YearGroup.

one identifier, five fields, four different data types Pupil1 : StudentRecord .LastName.YearGroup.FormGroup .DateOfBirth.Boarder "Khan"12'B' 14/03/2009FALSE STRINGINTEGERCHAR DATEBOOLEAN
Fig. 1: a record variable groups fields of different data types under one identifier
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen with the question in the title, The right type for the job.. Every item of data in a program has a data type that fixes what values it can hold and what you can do with it. Put the figure on the board: it is the one picture every idea in the lesson returns to.Whole class, then pairs
5 to 13 minTeach and check: Choosing a data typePick the type from what the data is and what the program must do with it. Model the worked example Justify each choice on the board, one line at a time. Your turn: A telephone number such as 07700900123 is to be stored. Should it be INTEGER or STRING? Give a reason.Whole class, then pairs
13 to 21 minTeach and check: Defining a recordA record type is a template.Pairs
21 to 30 minTeach and check: Reading and writing recordsUse dot notation to reach a field: the variable name, a full stop, then the field name. Model the worked example Process an array of records on the board, one line at a time. Your turn: Write one statement that adds 1 to the number of copies of the book stored in element 12 of Library.Jigsaw
30 to 36 minCheckThe four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong.Individual, then whole class
36 to 43 minPlenaryThe exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording.Individual, random call
43 to 45 minExit and homeworkSet the worksheet below (6 questions, 21 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

Protect the parts that carry the learning

The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.

Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.

Cut first if the build overruns: the last check in Reading and writing records, never the check or the plenary.

In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.

Running the cooperative task

Jigsaw

Split the content into expert pieces. Expert groups master one piece each, then regroup so every home team has one expert per piece, and each expert teaches their piece to the team.

The full structure, with its variations and the other twelve, is on the cooperative-learning page.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching move that pre-empts it
"Phone number: INTEGER because it is a number" loses the mark.Digits that are an identifier, not a quantity, belong in a STRING.
TYPE...ENDTYPE only defines the type. You still need DECLARE ThisBook: BookRecord before any data can be stored. Writing BookRecord.Title ← "Dune" uses the type name, not a variable, and earns no mark.
The index belongs to the array, not the field: Library[12].Copies, never Library.Copies[12].Return to Reading and writing records: ask a pair to state the correct version and show it on the lab before moving on.
Worksheet

Data types and records: worksheet

6 questions, 21 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · recall[2 marks]

Explain what is meant by a record structure.

Q2 · apply[4 marks]

A cinema stores, for each film showing: the film title, the screen number (1 to 12), the ticket price, the date of the showing, whether it is 3D, and an age rating of one character. State the most appropriate data type for four of these items.

Q3 · write[4 marks]

Write pseudocode to define a record type CarRecord with fields for a registration number, the make, the year of manufacture, the price and whether the car has been sold. Then declare a variable NewCar of this type.

Q4 · write[3 marks]

Using CarRecord and NewCar, write pseudocode statements to store a car with registration AB12 CDE, make Toyota, year 2021, price 15995.00, not yet sold, and then output its make and price.

Q5 · write[5 marks]

Stock is an ARRAY[1:200] OF CarRecord. Write pseudocode to output the registration of every car that is not sold and was made before 2015, and then the total price of those cars.

Q6 · analysis[3 marks]

A programmer stores the cars in five separate 1D arrays (one per field) instead of one array of records. Give two advantages of using an array of records.

Answer key and marking notes
Q1 · 2 marks
  • A (composite / user-defined) data type that holds a set of related data items (fields).
  • The fields can be of different data types and are referred to by one identifier.
Q2 · 4 marks
  • Title: STRING.
  • Screen number: INTEGER.
  • Ticket price: REAL.
  • Date: DATE; Is 3D: BOOLEAN; Age rating: CHAR (any four correct, 1 mark each).
Q3 · 4 marks
  • TYPE CarRecord ... ENDTYPE enclosing the fields.
  • DECLARE Registration : STRING and DECLARE Make : STRING.
  • DECLARE Year : INTEGER, DECLARE Price : REAL, DECLARE Sold : BOOLEAN.
  • DECLARE NewCar : CarRecord after the type definition.
Q4 · 3 marks
  • NewCar.Registration ← "AB12 CDE" and NewCar.Make ← "Toyota".
  • NewCar.Year ← 2021, NewCar.Price ← 15995.00, NewCar.Sold ← FALSE.
  • OUTPUT NewCar.Make, " ", NewCar.Price.
Q5 · 5 marks
  • Initialise Total ← 0 before the loop.
  • FOR Index ← 1 TO 200 ... NEXT Index.
  • IF Stock[Index].Sold = FALSE AND Stock[Index].Year < 2015 THEN.
  • Inside: OUTPUT Stock[Index].Registration and Total ← Total + Stock[Index].Price.
  • OUTPUT Total after the loop.
Q6 · 3 marks
  • All the data about one car is kept together under one identifier and one index.
  • A whole car can be moved, copied or swapped (for example when sorting) in one assignment, so the fields cannot get out of step.
  • Only one array needs to be declared and passed to subroutines (any two, with explanation for the third mark).
Quiz

6 multiple-choice questions on this lesson

From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.

Q11 mark

A program stores a customer's mobile number, such as 07700900461. Which data type is most appropriate?

  • ASTRING
  • BINTEGER
  • CREAL
  • DCHAR
Q21 mark

A school stores, for each student: the initial letter of their house, the number of merits they have earned and whether they have paid for a trip. Which data types are most appropriate, in that order?

  • ACHAR, INTEGER, BOOLEAN
  • BSTRING, REAL, BOOLEAN
  • CCHAR, INTEGER, STRING
  • DCHAR, REAL, CHAR
Q31 mark

What is the main purpose of a record structure?

  • ATo hold related data items, which may be of different data types, under one identifier
  • BTo hold a fixed number of values that all have the same data type
  • CTo keep data on secondary storage after the program has ended
  • DTo store items so that the last one added is the first one removed
Q41 mark

Team is declared as ARRAY[1:20] OF PlayerRecord, and PlayerRecord has an INTEGER field Goals. Which statement adds 1 to the goals of the player in element 3?

  • ATeam[3].Goals ← Team[3].Goals + 1
  • BTeam.Goals[3] ← Team.Goals[3] + 1
  • CPlayerRecord[3].Goals ← PlayerRecord[3].Goals + 1
  • DGoals[3].Team ← Goals[3].Team + 1
Q51 mark

This pseudocode contains one error. Which line is it on, and why?

1  TYPE PetRecord
2      DECLARE Name : STRING
3      DECLARE Age : INTEGER
4  ENDTYPE
5  DECLARE MyPet : PetRecord
6  PetRecord.Name ← "Bo"
7  MyPet.Age ← 3

  • ALine 6: it assigns to the type name PetRecord instead of the variable MyPet
  • BLine 5: a variable of a record type cannot be declared with DECLARE
  • CLine 7: a field of a record cannot be given a value by assignment
  • DLine 1: TYPE must be followed by a colon and a built-in data type
Q61 mark

Stock is an ARRAY[1:4] OF ItemRecord with a REAL field Price and an INTEGER field InStock. The four records hold (Price, InStock): (2.50, 4), (1.20, 0), (3.00, 2), (0.80, 10). What is output?

Total ← 0.0
FOR i ← 1 TO 4
    IF Stock[i].InStock > 0 THEN
        Total ← Total + Stock[i].Price * Stock[i].InStock
    ENDIF
NEXT i
OUTPUT Total

  • A24.0
  • B6.3
  • C7.5
  • D16
Quiz key
Q1: A

A phone number is an identifier made of digits, not a quantity: it is never added or multiplied, and as an INTEGER the leading zero would be lost. REAL has the same problem and adds a fractional part that makes no sense, and CHAR holds only one character.

Q2: A

One letter is a CHAR, a count of merits is always a whole number so INTEGER, and paid or not paid has two values so BOOLEAN. STRING works for one letter but is not the most appropriate, and merits never have a fractional part, so REAL is wrong. Storing a yes or no answer as a STRING or CHAR invites invalid values such as "maybe".

Q3: A

A record is a composite type whose fields can have different data types, all reached through one identifier. Same-type values in a fixed number of elements describe an array, permanent storage needs a file, and last in, first out describes a stack.

Q4: A

Team[3] is one PlayerRecord, and .Goals selects its field. The index belongs to the array, not to the field, so Team.Goals[3] is wrong. PlayerRecord is the type name and holds no data, and Goals[3].Team reverses array and field.

Q5: A

PetRecord is only the definition of the type; data is stored in a variable of that type, so line 6 should be MyPet.Name ← "Bo". Line 5 is exactly how a record variable is declared, line 7 is a valid field assignment using dot notation, and a record type is written TYPE followed by its name, with its fields declared inside.

Q6: A

Records 1, 3 and 4 have stock: 2.50 × 4 + 3.00 × 2 + 0.80 × 10 = 10.0 + 6.0 + 8.0 = 24.0. 6.3 adds only the prices of the items in stock, 7.5 adds every price, and 16 is the total number of items, not their value.

Slides

Slides for this lesson

A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.