Skip to content

9618 · 13.1

User-defined data types — practice questions

Practice and worked examples for 9618 User-defined data types. Short previews only — attempt the full question in MarkScheme against the official scheme.

Worked example 1

A bookshop needs to store information about each book: its ISBN (13-digit string), title, author, and price. Define a suitable user-defined data type called TBook.

Show solution outline

Here is the pseudocode definition for the TBook type:

TYPE TBook
    DECLARE ISBN : STRING
    DECLARE Title : STRING
    DECLARE Author : STRING
    DECLARE Price : REAL
ENDTYPE

Marking points:

  • TYPE TBook and ENDTYPE present. (1 mark)
  • At least two correct fields with data types declared. (1 mark)
  • All four fields correctly declared with appropriate data types (STRING for ISBN/Title/Author, REAL for Price). (1 mark)

Worked example 2

Using the TBook type defined previously:

  1. Declare a variable newBook of type TBook.
  2. Write pseudocode to assign the value "978-0-241-98276-1" to its ISBN field and 9.99 to its Price field.
  3. Write a statement to output the price of newBook.
Show solution outline
  1. Declaration:
DECLARE newBook : TBook
  1. Assignment:
newBook.ISBN <- "978-0-241-98276-1"
newBook.Price <- 9.99
  1. Output:
OUTPUT newBook.Price

Marking points:

  • Correct declaration of newBook with type TBook. (1 mark)
  • Correct use of dot notation and assignment operator (<<- or ==) for both fields. (1 mark for each correct assignment, total 2 marks)
  • Correct use of dot notation in the OUTPUT statement. (1 mark)