Data types and structures
Cambridge AS & A Level Computer Science 9618 · Paper 2 · Unit 10
Paper 2 · Unit 10. Data types, records, arrays, text files and abstract data types.
Original exam-style questions (14 marks) with a full mark scheme. Use it for homework, revision or a quick test.
1. Data types and records
| Type | Use |
|---|---|
| INTEGER | Whole numbers |
| REAL | Numbers with a fractional part |
| CHAR | A single character |
| STRING | A sequence of characters |
| BOOLEAN | TRUE or FALSE |
| DATE | A calendar date |
A record is a user-defined composite type that groups related items of different types:
TYPE StudentRecord DECLARE Name : STRING DECLARE Age : INTEGER DECLARE Passed : BOOLEAN ENDTYPE DECLARE Pupil : StudentRecord Pupil.Name ← "Aylin"
2. Arrays
An array is a fixed-size, indexed collection of elements of the same type. You need: index, lower and upper bound, 1D and 2D arrays.
DECLARE Scores : ARRAY[1:30] OF INTEGER
DECLARE Grid : ARRAY[1:3, 1:4] OF CHAR
// linear search
Found ← FALSE
Index ← 1
WHILE Found = FALSE AND Index <= 30
IF Scores[Index] = Target THEN Found ← TRUE ENDIF
Index ← Index + 1
ENDWHILE
// bubble sort
FOR Pass ← 1 TO 29
FOR J ← 1 TO 30 - Pass
IF Scores[J] > Scores[J + 1] THEN
Temp ← Scores[J]
Scores[J] ← Scores[J + 1]
Scores[J + 1] ← Temp
ENDIF
NEXT J
NEXT Pass
3. Files
Files store data permanently so it is kept after the program ends. Text files are opened in a mode:
OPENFILE "scores.txt" FOR WRITE // also READ, APPEND
WRITEFILE "scores.txt", Line
CLOSEFILE "scores.txt"
OPENFILE "scores.txt" FOR READ
WHILE NOT EOF("scores.txt")
READFILE "scores.txt", Line
OUTPUT Line
ENDWHILE
CLOSEFILE "scores.txt"
4. Abstract data types
| ADT | Description | Pointers |
|---|---|---|
| Stack | Last In First Out (LIFO); items are pushed and popped at the top | Top of stack (base pointer fixed) |
| Queue | First In First Out (FIFO); enqueue at the rear, dequeue at the front; often circular | Front and rear pointers |
| Linked list | Each node holds data and a pointer to the next node; order is kept without moving data | Start pointer; null pointer ends the list; free list for unused nodes |
All three can be implemented using arrays and pointer variables. Check for overflow (full) and underflow (empty).
Try it: stack vs queue
5. Examiner tips
- Arrays hold one data type; records hold different types.
- Always check bounds and use the bounds given in the question.
- Close files after use, and use EOF when reading.
- Stack = LIFO, queue = FIFO. Say which pointer changes.
- Linked list insertion changes pointers, not data positions.
6. Practice questions
Practice: answer and check instantly
Type a short answer, then press Check or Enter.
Show answer
BOOLEAN.
Show answer
REAL.
Show answer
First In First Out.
Show answer
Underflow.
Show answer
APPEND.
Show answer
EOF.
Show answer
A null pointer.
Show answer
3 × 4 = 12.
Exam-style questions
Not sure what a question wants? Read Command words: what the question is really asking.
9. Describe how an item is added to a queue implemented with an array. [3]
Show mark guide
Check whether the queue is full (overflow) [1] · increment the rear pointer, wrapping round if circular [1] · store the item at the position of the rear pointer [1].
10. Explain why a record data type is useful. [2]
Show mark guide
It groups related data items of different data types [1] under one identifier, so data for one entity (e.g. a student) is kept together and easier to process [1].
7. Topic test: predict your grade
Topic test: predict your grade
15 questions, about 10 minutes. Answer them all, then press Mark my test.
Frequently asked questions
What is the difference between a stack and a queue?
A stack is Last In First Out, so items are added and removed at the top. A queue is First In First Out, so items are added at the rear and removed from the front.
What is a record data type?
A record is a user-defined data type that groups related fields of different data types under one identifier.
How do you read a text file in pseudocode?
Use OPENFILE for READ, then a WHILE NOT EOF loop with READFILE, and finally CLOSEFILE.
What is an abstract data type?
An abstract data type is a collection of data and the operations on that data, defined by what it does rather than how it is stored. In 9618 these are the stack, queue and linked list.
What is a circular queue?
A circular queue uses a fixed-size array where the front and rear pointers wrap around to the start of the array, so space freed at the front can be reused.
What is a linked list?
A linked list is a set of nodes, each holding data and a pointer to the next node. A start pointer shows the first node and a null pointer marks the end.
What is the difference between WRITE and APPEND in pseudocode?
Opening a file FOR WRITE creates a new file or overwrites existing contents. Opening a file FOR APPEND adds new data to the end of the existing file.