Computer Science 9618/33 — May/June 2022
Cambridge A-Level · Advanced Theory · worked solutions for every part, with the mark scheme
Topics Further Programming · Hardware and Virtual Machines · Data Representation · Communication and Internet Technologies · System Software · Computational Thinking and Problem-solving · +1 more
Data types can be defined using pseudocode.
The data type, LibraryRecord, is defined in pseudocode as:
TYPE LibraryRecord
DECLARE Title : STRING
DECLARE Fiction : BOOLEAN
DECLARE Author : STRING
DECLARE NumberOfCopies : INTEGER
ENDTYPE
A variable, LibraryBook, is declared in pseudocode as:
DECLARE LibraryBook : LibraryRecord
Write pseudocode statements to assign:
- A Level Computer Science to
TitleofLibraryBook FALSEtoFictionofLibraryBook.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
Answer
LibraryBook.Title ← "A Level Computer Science"
LibraryBook.Fiction ← FALSE
LibraryBook.Title ← "A Level Computer Science"; LibraryBook.Fiction ← FALSE
Background Concept
A record is a composite data type made up of several named fields. Each field stores one value, and each field has its own data type. In the given definition, LibraryRecord has four fields:
Title : STRINGFiction : BOOLEANAuthor : STRINGNumberOfCopies : INTEGER
When a variable is declared as that record type, each field is accessed using dot notation:
RecordVariable.FieldName
So if LibraryBook is a LibraryRecord, then LibraryBook.Title means the Title field inside that specific record.
Understanding the Question
The question gives the record type and then says that LibraryBook has already been declared as one variable of that type:
DECLARE LibraryBook : LibraryRecord
You are asked to write pseudocode statements that assign:
- the string
A Level Computer Scienceto theTitlefield - the Boolean value
FALSEto theFictionfield
So this is not asking you to redefine the type or redeclare the variable. It is only asking for assignment statements to two fields inside the record.
Approach
Use one assignment statement per field. For each one:
- Write the record variable name:
LibraryBook - Add a dot and the field name
- Use the assignment arrow
← - Put the correct value on the right-hand side
Because Title is a STRING, the text must be in double quotes. Because Fiction is a BOOLEAN, use the keyword FALSE without quotes.
Step-by-Step Reasoning
The first field is Title.
- The variable is
LibraryBook - The field is
Title - The value to store is the text
A Level Computer Science
So the statement is:
LibraryBook.Title ← "A Level Computer Science"
The second field is Fiction.
- The variable is still
LibraryBook - The field is
Fiction - The value to store is the Boolean value
FALSE
So the statement is:
LibraryBook.Fiction ← FALSE
These are the only two lines needed.
Key Takeaways
- A record field is accessed with dot notation.
- Assign values to record fields using the assignment arrow
←. - Strings need quotes; Boolean values such as
TRUEandFALSEdo not.
Common Mistakes
- Writing
LibraryRecord.Titleinstead ofLibraryBook.Title.LibraryRecordis the type name;LibraryBookis the variable. - Using
=instead of←in pseudocode. - Writing
"FALSE"in quotes. That would make it a string, not a Boolean. - Omitting the field name and trying to assign directly to
LibraryBook.
Things to Be Careful About
- Use the exact field names given:
TitleandFiction. - Keep the identifier casing exactly as shown in the question.
- In Cambridge pseudocode, assignment uses
←, not=. - Only write the assignment statements asked for; do not repeat the type definition or declaration.
The type definition for LibraryRecord is changed.
The value for NumberOfCopies must be between 1 and 10 inclusive.
Write the updated line of pseudocode from the type definition of LibraryRecord to implement the change.
...........................................................................................................................................
.....................................................................................................................................
Answer
DECLARE NumberOfCopies : 1..10
DECLARE NumberOfCopies : 1..10
Background Concept
A user-defined type can be refined so that a field is not just a broad built-in type such as INTEGER, but a more restricted set of allowed values. This is useful because it builds the rule into the data definition itself.
A subrange type means that only values within a specified range are valid. Here, instead of allowing any integer, the field should only allow integers from 1 to 10 inclusive.
Understanding the Question
Originally, the field was:
DECLARE NumberOfCopies : INTEGER
The question says the value must be between 1 and 10 inclusive, and asks for the updated line from the type definition. So you are not writing validation code such as an IF statement or loop. You are changing the declaration itself to show the restricted range.
Approach
Replace the broad type INTEGER with a bounded range that shows the smallest and largest allowed values.
Because the question says inclusive, both 1 and 10 must be allowed.
Step-by-Step Reasoning
The old declaration allows any integer:
DECLARE NumberOfCopies : INTEGER
But the new rule is:
- minimum value = 1
- maximum value = 10
- both ends included
So the declaration becomes:
DECLARE NumberOfCopies : 1..10
This directly expresses the constraint in the type definition.
Key Takeaways
- A subrange type is used when only a limited set of numeric values is valid.
- If a question asks for an updated type-definition line, change the declaration rather than writing separate checking code.
- Inclusive bounds mean both end values are part of the valid range.
Common Mistakes
- Leaving the field as
INTEGERand describing the range in words. - Writing validation pseudocode instead of updating the type definition.
- Using an exclusive range accidentally, so that
1or10would not be allowed. - Rewriting the whole record instead of giving the one updated line requested.
Things to Be Careful About
- The answer needs the exact field name
NumberOfCopies. - The question asks for one updated line, so keep the response concise.
- Make sure the notation shows a range, not two separate values.
- Do not add quotes; this is numeric data, not a string.
Every copy of every book is now uniquely identified by an accession number, AccessionNumber, as it is added to the library. Each library record will include one or more accession numbers. Each accession number is an integer.
Write the extra line of pseudocode needed in the type definition of LibraryRecord.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.....................................................................................................................................
Answer
DECLARE AccessionNumber : ARRAY[1:10] OF INTEGER
DECLARE AccessionNumber : ARRAY[1:10] OF INTEGER
Background Concept
If one field needs to store more than one value, a single simple type such as INTEGER is not enough. A composite structure is needed. An array is a suitable choice when:
- there are multiple items of the same type
- each item is stored separately
- they can be indexed by position
In this question, each accession number is an integer, and each library record can contain several accession numbers, one for each copy of the book.
Understanding the Question
The record is being extended. Each book can now have one or more accession numbers, and every accession number is unique. The important clue is "one or more accession numbers". That means this is no longer a single integer field.
The previous part limited NumberOfCopies to between 1 and 10, so a record needs enough space to store up to 10 accession numbers.
The question asks for the extra line needed in the type definition, so it wants the declaration of the new field only.
Approach
Choose a data structure that can hold several integers inside the record. The natural choice is a one-dimensional array of integers.
Because there can be at most 10 copies, an array with 10 positions is sufficient.
Step-by-Step Reasoning
A declaration such as:
DECLARE AccessionNumber : INTEGER
would be wrong, because that stores only one accession number.
We need a field that stores several integers. An array does that.
The field name given is AccessionNumber, and the elements are integers. Since the record may need up to 10 of them, the declaration is:
DECLARE AccessionNumber : ARRAY[1:10] OF INTEGER
This means:
AccessionNumberis the field name- it contains positions 1 to 10
- each position stores one integer accession number
In practice, only as many positions as the book has copies would be used.
Key Takeaways
- If a field must store several values, use a composite structure, not a single simple type.
- An array is appropriate when all stored items are the same data type.
- Type definitions can include array fields inside a record.
Common Mistakes
- Declaring
AccessionNumberas justINTEGER, which only stores one value. - Choosing the wrong data type for the array elements, such as
STRING. - Forgetting that the field is inside the record definition and therefore needs a
DECLAREline. - Using a size that does not match the allowed maximum number of copies.
Things to Be Careful About
- Use the exact identifier
AccessionNumberfrom the question. - The elements are integers, so the declaration must end with
OF INTEGER. - The array bounds should allow enough entries for the possible copies.
- The question asks for one extra line, not a full rewritten type definition.
A record is a user-defined composite data type.
Explain what is meant by a user-defined composite data type.
Include an example of another user-defined composite data type in your answer.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Answer
- A user-defined data type is a data type created by the programmer rather than a built-in type.
- A composite data type is made up of more than one data item or field, possibly of different data types.
- Example:
TYPE StudentRecord
DECLARE Name : STRING
DECLARE CandidateNumber : INTEGER
DECLARE DateOfBirth : STRING
ENDTYPE
A user-defined composite data type is created by the programmer and contains more than one field; for example, a StudentRecord with fields such as Name, CandidateNumber and DateOfBirth.
Background Concept
Data types describe what kind of values can be stored and how those values are organised. Some data types are built in, such as INTEGER, REAL, STRING, CHAR and BOOLEAN. Others are created by the programmer to match the problem being solved.
A user-defined data type is one designed by the programmer. This is useful when built-in types alone do not represent the structure of the data clearly.
A composite data type is one that contains multiple components. Those components may all be the same type, or they may be different types. A record is a common composite type because it groups several related fields together under one name.
Understanding the Question
The question states that a record is a user-defined composite data type and then asks you to explain what that means. So there are really two ideas to explain:
- what "user-defined" means
- what "composite" means
It also asks for another example. That means you should not stop after a definition; you should include a valid example of a programmer-created type made from multiple fields.
Approach
A full-mark answer should contain three parts:
- say that the type is created by the programmer
- say that it consists of several related items/fields
- give an example of another such type
A short record definition is the clearest example because it directly shows multiple named fields.
Step-by-Step Reasoning
First, explain "user-defined".
This means the programmer defines the type themselves. It is not one of the standard built-in types already provided by the language.
Second, explain "composite".
Composite means the type is made from more than one component. In a record, these components are fields. Each field stores related information, and the fields can have different data types.
For example, a student record might need a name, candidate number and date of birth. These are related items about one student, so grouping them into one type makes sense.
That leads to a suitable example:
TYPE StudentRecord
DECLARE Name : STRING
DECLARE CandidateNumber : INTEGER
DECLARE DateOfBirth : STRING
ENDTYPE
This example is:
- user-defined, because the programmer created
StudentRecord - composite, because it contains several fields
Key Takeaways
- "User-defined" means created by the programmer for a specific problem.
- "Composite" means made up of multiple data items or fields.
- Records are a standard way to build a user-defined composite type.
- Good examples show both the type name and its component fields.
Common Mistakes
- Defining only "record" without explaining "user-defined" and "composite" separately.
- Saying only that it stores "lots of data" without stating that it contains multiple fields.
- Giving a built-in type like
INTEGERas the example. That is not user-defined. - Giving a one-field example, which does not clearly show a composite type.
Things to Be Careful About
- The question asks for another example, so do not just repeat
LibraryRecordwithout adding anything new. - Make it clear that the fields are related and grouped into one structure.
- If you give an example in pseudocode, keep the format correct with
TYPE ... ENDTYPEandDECLARElines. - A concise explanation is enough, but it must include both parts of the term and an example.
The rest of this paper
8 more questions- Q2Further Programming6M
- Q3Communication and Internet Technologies8M
- Q4Hardware and Virtual Machines6M
- Q5System Software · Computational Thinking and Problem-solving12M
- Q6Hardware and Virtual Machines6M
- Q7Further Programming11M
- Q8Security8M
- Q9Further Programming10M