9618/32

Computer Science 9618/32May/June 2022

Cambridge A-Level · Advanced Theory · worked solutions for every part, with the mark scheme

9
questions
75
marks
90
minutes

Topics Further Programming · Hardware and Virtual Machines · Data Representation · Communication and Internet Technologies · System Software · Security · +1 more

Q1Data RepresentationFurther ProgrammingFree sample

Data types can be defined using pseudocode.

The data type, BuildingRecord, is defined in pseudocode as:

TYPE BuildingRecord
 DECLARE BuildingID : INTEGER
 DECLARE BuildingGroup : STRING
 DECLARE OwnerName : STRING
 DECLARE BuildingAddress : STRING
 DECLARE DateLastSold : DATE
 DECLARE PriceLastSold : REAL
ENDTYPE

A variable, BuildingRegister, is declared in pseudocode as:

DECLARE BuildingRegister : BuildingRecord
(a)

Write pseudocode statements to assign:

• 1067 to the BuildingID of BuildingRegister
• house to the BuildingGroup of BuildingRegister

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................

2M
DifficultyEasy
Worked solution

Answer

BuildingRegister.BuildingID ← 1067
BuildingRegister.BuildingGroup ← "house"
Final answer

See completed pseudocode

Detailed explanation

Background Concept

A record is a composite user-defined data type. That means one variable can contain several named fields, and each field can have its own data type. In this question, BuildingRecord contains fields such as BuildingID, BuildingGroup, OwnerName and others.

When a variable is declared using a record type, individual fields are accessed using dot notation:

  • RecordVariable.FieldName

So if BuildingRegister is a variable of type BuildingRecord, then:

  • BuildingRegister.BuildingID refers to the integer field
  • BuildingRegister.BuildingGroup refers to the string field

In CIE pseudocode, assignment is written with the arrow , not with =.

Understanding the Question

You are given the type definition for BuildingRecord and told that BuildingRegister is a variable of that type. The question asks you to write the pseudocode statements that put two values into two specific fields:

  • 1067 into BuildingID
  • house into BuildingGroup

The important clue is the original declaration of BuildingGroup:

DECLARE BuildingGroup : STRING

Because it is a string at this stage, the value house should be written as a string literal.

Approach

Use one assignment statement for each field.

  1. Write the variable name BuildingRegister
  2. Add the field name after a dot
  3. Use
  4. Put the required value on the right-hand side
  5. Make sure the string value is written as a string

Step-by-Step Reasoning

For the first statement:

  • The field is BuildingID
  • Its declared type is INTEGER
  • The value 1067 is an integer
  • So the correct assignment is:
BuildingRegister.BuildingID ← 1067

For the second statement:

  • The field is BuildingGroup
  • Its declared type is STRING
  • Therefore the word house must be assigned as a string value
  • So the correct assignment is:
BuildingRegister.BuildingGroup ← "house"

The two statements are separate because each one sets a different field in the record.

Key Takeaways

  • A record stores several named fields in one variable.
  • Dot notation is used to access a field inside a record.
  • The assigned value must match the field's declared type.
  • CIE pseudocode uses for assignment.

Common Mistakes

  • Writing BuildingID ← 1067 without BuildingRegister. first. That ignores the fact that BuildingID is a field, not a standalone variable.
  • Using = instead of . In pseudocode, = is for comparison, not assignment.
  • Forgetting that BuildingGroup is still a STRING here and not an enumerated value yet.
  • Misspelling a field name such as Buildinggroup or buildingGroup. Field names should match the question exactly.

Things to Be Careful About

  • At this point in the question, BuildingGroup has not yet been changed to an enumerated type, so treating it as a string is important.
  • Use exact identifier names: BuildingRegister, BuildingID, and BuildingGroup.
  • Keep one assignment per line so each marking point is clear.
Techniques used
access record fields using dot notationassign values with the pseudocode assignment arrowmatch each value to the declared field type
(b)

The type definition for BuildingRecord is changed. The data type for BuildingGroup is changed to an enumerated type, BuildingType, with values of house, bungalow, apartment and farm.

(i)

Write the type declaration for BuildingType in pseudocode.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.....................................................................................................................................

2M
DifficultyMedium-Easy
Worked solution

Answer

TYPE BuildingType = (house, bungalow, apartment, farm)
Final answer

See completed pseudocode

Detailed explanation

Background Concept

An enumerated type is a user-defined type that can hold one value from a fixed list of named values. It is useful when only a small number of valid options are allowed.

For example, if a building can only be one of these categories:

  • house
  • bungalow
  • apartment
  • farm

then using an enumerated type is better than using a string, because it restricts the value to one of the valid choices.

This helps with validation, consistency and avoiding typing mistakes.

Understanding the Question

The question says that BuildingGroup is no longer going to be a STRING. Instead, it is being changed to an enumerated type called BuildingType with the four given values.

So before the field can use BuildingType, you must first declare what BuildingType is.

Approach

To declare an enumerated type in pseudocode:

  1. Write TYPE
  2. Give the new type name
  3. Use =
  4. Put the allowed values in brackets, separated by commas

The order should match the values given in the question.

Step-by-Step Reasoning

The new type name must be BuildingType because that is stated in the question.

The allowed values are exactly:

  • house
  • bungalow
  • apartment
  • farm

So the declaration is:

TYPE BuildingType = (house, bungalow, apartment, farm)

Notice that this is a type declaration, not a field declaration and not an assignment statement.

Key Takeaways

  • An enumerated type defines a fixed set of named values.
  • It is used when only certain values are valid.
  • The type must be declared before it is used in a variable or field declaration.

Common Mistakes

  • Writing a field declaration instead of a type declaration.
  • Leaving out one of the permitted values.
  • Changing the type name from BuildingType to something else.
  • Treating the values as strings rather than enumeration items.

Things to Be Careful About

  • Use the exact type name given: BuildingType.
  • Include all four values and no extra ones.
  • This part only asks for the type declaration, not the record field declaration.
  • Keep the syntax as a single enumerated list in brackets after =.
Techniques used
define an enumerated typelist all allowed values in the declarationreplace a general string category with fixed valid options
(ii)

Write the new declaration for BuildingGroup in pseudocode.

...........................................................................................................................................

.....................................................................................................................................

1M
DifficultyEasy
Worked solution

Answer

DECLARE BuildingGroup : BuildingType
Final answer

See completed pseudocode

Detailed explanation

Background Concept

Once a user-defined type has been declared, it can be used just like a built-in type in later declarations. For example:

  • INTEGER
  • STRING
  • REAL
  • BuildingType

In a record or class, each field is declared by giving the field name followed by its type.

Understanding the Question

This part asks for the new declaration of the BuildingGroup field after BuildingType has been introduced.

Originally, the field was:

DECLARE BuildingGroup : STRING

Now that BuildingGroup must use the new enumerated type, only the type part changes.

Approach

Keep the field name exactly the same and replace STRING with BuildingType.

Step-by-Step Reasoning

The field name is still BuildingGroup.

The new type is BuildingType.

So the declaration becomes:

DECLARE BuildingGroup : BuildingType

This means the field can now hold only one of the allowed enumeration values defined earlier.

Key Takeaways

  • A field declaration names the field and gives its type.
  • User-defined types can be used in exactly the same place as built-in types.
  • Changing a field from STRING to an enumeration restricts it to valid values.

Common Mistakes

  • Writing DECLARE BuildingType : BuildingGroup, which reverses the field name and type.
  • Leaving the type as STRING.
  • Writing the full enumeration list again instead of using the type name.

Things to Be Careful About

  • The field name is BuildingGroup, not BuildingType.
  • The type name must match the earlier declaration exactly.
  • This is still a field declaration, so it begins with DECLARE.
Techniques used
update a record field declarationuse a user-defined type as a field typereplace the original primitive type with an enumerated type
(iii)

Write the new pseudocode statement to assign house to BuildingGroup of BuildingRegister.

...........................................................................................................................................

.....................................................................................................................................

1M
DifficultyEasy
Worked solution

Answer

BuildingRegister.BuildingGroup ← house
Final answer

See completed pseudocode

Detailed explanation

Background Concept

After a field is changed from STRING to an enumerated type, values assigned to it are no longer ordinary text strings. Instead, they are enumeration values from the predefined list.

That changes how the assignment looks:

  • string value: "house"
  • enumerated value: house

The field is still accessed using dot notation because it is still inside the BuildingRegister record.

Understanding the Question

This part asks for the new assignment statement after the type of BuildingGroup has changed.

That means you must not simply repeat the answer from part (a). The key change is that house is now one of the values of BuildingType, not a string.

Approach

  1. Access the same field using BuildingRegister.BuildingGroup
  2. Use the assignment arrow
  3. Assign the enumerated value house
  4. Do not write it as a string literal

Step-by-Step Reasoning

The left-hand side stays the same because the record variable and field name have not changed:

BuildingRegister.BuildingGroup

The right-hand side changes because the field type is now BuildingType, an enumeration. So the value should be one of the named enumeration items.

Therefore the assignment is:

BuildingRegister.BuildingGroup ← house

There are no quotation marks because house is no longer a string.

Key Takeaways

  • Changing a field's type can change how values are written in assignments.
  • Enumeration values are written as named items, not string literals.
  • Dot notation is still used to access the field inside the record.

Common Mistakes

  • Writing BuildingRegister.BuildingGroup ← "house", which treats the value as a string instead of an enumeration value.
  • Forgetting BuildingRegister. and writing only BuildingGroup ← house.
  • Using = instead of .

Things to Be Careful About

  • This answer is different from part (a) for an important reason: the type has changed.
  • Use the exact enumerated value name given in the question.
  • Do not invent capitals or quotes unless the pseudocode definition used them.
Techniques used
assign an enumerated value to a record fielduse dot notation for field accessdistinguish enumeration items from string literals
(c)

The program is to be rewritten using Object-Oriented Programming (OOP). The data type BuildingRecord is to be changed to a class, BuildingClass.

The properties for BuildingClass are BuildingID, BuildingGroup, OwnerName, BuildingAddress, DateLastSold and PriceLastSold.

All the properties are set to PRIVATE, for example:

PRIVATE PriceLastSold : REAL
(i)

Write the declaration in pseudocode for OwnerName as PRIVATE.

...........................................................................................................................................

.....................................................................................................................................

1M
DifficultyEasy
Worked solution

Answer

PRIVATE OwnerName : STRING
Final answer

See completed pseudocode

Detailed explanation

Background Concept

In object-oriented programming, a class contains properties and methods.

  • Properties store the data for each object.
  • Methods perform operations on that data.

An access modifier controls where a property can be accessed from.

  • PRIVATE means the property can only be accessed from within the class itself.
  • PUBLIC means it can be accessed from outside the class.

Using PRIVATE is part of encapsulation, where data is kept inside the class and controlled through methods.

Understanding the Question

The question says that the record is being rewritten as a class called BuildingClass, and that all the properties are set to PRIVATE. It then asks specifically for the declaration of OwnerName as PRIVATE.

So this is not asking for a method or a full class definition. It only wants the single property declaration line.

Approach

Take the property name OwnerName, keep its data type STRING, and place PRIVATE before it in the same style as the example shown for PriceLastSold.

Step-by-Step Reasoning

The property name is OwnerName.

From the original record definition, OwnerName has type STRING.

The question says it must be private.

So the declaration is:

PRIVATE OwnerName : STRING

This follows the exact same format as the example:

PRIVATE PriceLastSold : REAL

Key Takeaways

  • A class property declaration includes an access modifier, a name and a type.
  • PRIVATE limits direct access to the property.
  • The data type of a property should match the original design unless the question changes it.

Common Mistakes

  • Writing DECLARE OwnerName : STRING instead of using PRIVATE.
  • Writing a method declaration instead of a property declaration.
  • Changing the type from STRING to something else.

Things to Be Careful About

  • The question asks for one line only, not the whole class.
  • Keep the identifier exactly as OwnerName.
  • Use the same declaration style as the example provided.
Techniques used
declare a class propertyapply an access modifiermatch the property to its stated data type
(ii)

Explain why the properties have been set to PRIVATE.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.....................................................................................................................................

2M
DifficultyMedium-Easy
Worked solution

Answer

  • The properties are PRIVATE so they cannot be accessed or changed directly from outside the class.
  • This provides encapsulation/data hiding, so the class can control access through its methods and help protect the data from invalid changes.
Final answer

See explanation

Detailed explanation

Background Concept

A major idea in object-oriented programming is encapsulation. Encapsulation means combining data and the operations on that data inside a class, while controlling outside access.

This is often described as data hiding.

If properties are PRIVATE:

  • code outside the class cannot read or change them directly
  • the class decides how they are accessed, usually through public methods such as setters and getters
  • the class can validate values before storing them

This helps keep objects in a valid state.

Understanding the Question

The question asks why the properties have been set to PRIVATE in BuildingClass.

It is not enough just to say "because of OOP". You need to explain the benefit:

  • preventing direct access from outside the class
  • protecting the data by controlling how it is changed

These are the ideas the mark scheme is looking for.

Approach

Give two linked points:

  1. PRIVATE blocks direct external access
  2. this supports encapsulation/data hiding and allows controlled access through methods

That covers both the mechanism and the reason.

Step-by-Step Reasoning

When a property is declared PRIVATE, only code inside that class can access it directly. That means another part of the program cannot simply change a value whenever it wants.

For example, if PriceLastSold or BuildingID were public, external code could assign unsuitable or invalid values directly. With PRIVATE properties, the class can require outside code to use methods instead.

Those methods can:

  • check whether the new value is valid
  • reject incorrect values
  • keep the internal structure hidden

So the explanation is:

  • the properties cannot be accessed or altered directly from outside the class
  • this gives encapsulation/data hiding and protects the data by forcing controlled access through methods

Key Takeaways

  • PRIVATE is used to restrict access to class data.
  • Encapsulation means keeping data and the methods that manage it together.
  • Data hiding helps protect objects from invalid or uncontrolled changes.

Common Mistakes

  • Saying only "for security" without explaining what kind of protection is meant.
  • Naming "encapsulation" but not explaining that outside code cannot directly access the data.
  • Confusing PRIVATE with encryption or password protection. This is about program design, not cryptography.

Things to Be Careful About

  • The question asks why the properties are private, so focus on access control and protection of the object's data.
  • Mentioning methods is helpful because it shows how access is controlled.
  • Do not drift into unrelated OOP ideas like inheritance or polymorphism unless they directly support the point.
Techniques used
explain encapsulationrelate private access to data hidingjustify controlled access through class methods

The rest of this paper

8 more questions
  • Q2Further Programming7M
  • Q3Communication and Internet Technologies8M
  • Q4System Software13M
  • Q5Hardware and Virtual Machines6M
  • Q6Hardware and Virtual Machines5M
  • Q7Security10M
  • Q8Computational Thinking and Problem-solving13M
  • Q9Further Programming4M
Loading the full paper…