A2 · Practice questions · User-defined data types

Define it to fit.

Six original Cambridge-style questions on non-composite and composite user-defined data types, with mark points.

Original questions All questions on this page are original work, written in the Cambridge AS & A Level style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Shape, then syntax.

01
Explain
[2 marks]

Explain why user-defined data types are necessary.

  • Built-in (primitive) types cannot represent every kind of data a problem needs. ✓
  • The programmer can define a type, derived from the built-in types, that matches the problem / makes the code clearer and lets invalid values be rejected. ✓
02
Recall
[2 marks]

State the difference between a composite and a non-composite data type, giving one example of each.

  • Composite: built from / refers to other data types, grouped under one identifier, e.g. record, set, class. ✓
  • Non-composite: defined without reference to other data types, e.g. enumerated, pointer. ✓
03
Write
[3 marks]

Write pseudocode to define an enumerated type Light with values Red, Amber and Green, declare a variable Signal of this type, and set it to Green.

  • TYPE Light = (Red, Amber, Green). ✓
  • DECLARE Signal : Light. ✓
  • Signal ← Green (no quotation marks). ✓
04
Trace
[3 marks]

TYPE TIntPointer = ^INTEGER. Count and Total are INTEGER variables; P is a TIntPointer.

Count ← 5
Total ← 9
P ← ^Count
P^ ← P^ * 3
P ← ^Total
P^ ← P^ - Count

State the final values of Count and Total, and what P holds.

  • Count = 15 (P points to Count, so P^ * 3 = 15 is stored in Count). ✓
  • Total = 9 - 15 = -6. ✓
  • P holds the memory address of Total. ✓
05
Write
[4 marks]

A school records, for each club: its name, the day it meets (one of Monday to Friday), the maximum number of members and the fee per term. Design user-defined data types for this data in pseudocode.

  • Enumerated type for the day: TYPE WeekDay = (Monday, Tuesday, Wednesday, Thursday, Friday). ✓
  • TYPE ClubRecord ... ENDTYPE. ✓
  • DECLARE ClubName : STRING, DECLARE MeetDay : WeekDay. ✓
  • DECLARE MaxMembers : INTEGER, DECLARE Fee : REAL. ✓
06
Analysis
[3 marks]

A game stores the power-ups a player has collected. Each power-up is identified by one letter, a player cannot hold the same power-up twice, and the order of collection does not matter. Justify the choice of a set and write a suitable type definition.

  • Only membership matters (does the player have it?), so no order or index is needed. ✓
  • A set holds no duplicates, matching the rule that a power-up cannot be held twice. ✓
  • TYPE PowerUpSet = SET OF CHAR (and a DEFINE line for any fixed set of values). ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.