Computer-science_A-level_Cie
-
computers-and-components6 主题
-
logic-gates-and-logic-circuits2 主题
-
central-processing-unit-cpu-architecture6 主题
-
assembly-language-4 主题
-
bit-manipulation1 主题
-
operating-systems3 主题
-
language-translators2 主题
-
data-security3 主题
-
data-integrity1 主题
-
ethics-and-ownership3 主题
-
database-concepts3 主题
-
database-management-systems-dbms-1 主题
-
data-definition-language-ddl-and-data-manipulation-language-dml1 主题
-
computational-thinking-skills1 主题
-
algorithms14 主题
-
data-types-and-records2 主题
-
arrays2 主题
-
files1 主题
-
introduction-to-abstract-data-types-adt1 主题
-
programming-basics1 主题
-
constructs2 主题
-
structured-programming1 主题
-
program-development-life-cycle2 主题
-
program-design-2 主题
-
program-testing-and-maintenance3 主题
-
user-defined-data-types1 主题
-
file-organisation-and-access-3 主题
-
floating-point-numbers-representation-and-manipulation3 主题
-
protocols2 主题
-
circuit-switching-packet-switching1 主题
-
processors-parallel-processing-and-virtual-machines5 主题
-
boolean-algebra-and-logic-circuits4 主题
-
purposes-of-an-operating-system-os3 主题
-
translation-software3 主题
-
encryption-encryption-protocols-and-digital-certificates3 主题
-
artificial-intelligence-ai4 主题
-
recursion1 主题
-
programming-paradigms4 主题
-
object-oriented-programming7 主题
-
file-processing-and-exception-handling2 主题
-
data-representation5 主题
-
multimedia3 主题
-
compression2 主题
-
networks-and-the-internet11 主题
user-defined-types
What are user-defined data types?
-
A user-defined data type is a custom data structure created by the programmer to match the specific needs of a program
-
It is built using primitive data types such as
INTEGER,STRING,BOOLEAN, etc -
It helps represent real-world entities more accurately than built-in types alone
-
|
Type |
Description |
|---|---|
|
Non-composite |
Made up of a single data item (e.g. enumerated types like |
|
Composite |
Made up of multiple data items, often of different types (e.g. records/structures) |
Non-composite
What is an enumerated data type?
-
An enumerated data type is a type of non-composite, user-defined data type that consists of a list of named, fixed values
-
It allows the programmer to define a variable that can only take one of a limited set of values
-
Making code clearer, more readable, and easier to validate
-
An enumerated data type should be used:
-
When a variable should only hold predefined values
-
To improve code readability and reduce errors
-
To restrict input to a known, fixed list
-
|
Pseudocode |
|
|---|---|
|
|
Example code
TYPE DayType = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) DECLARE Today : DayType Today ← Monday IF Today = Saturday OR Today = Sunday THEN OUTPUT "It's the weekend!"
ELSE OUTPUT "It's a weekday."
ENDIF
-
DayTypeis the enumerated type -
Todaycan only be one of the seven values listed inDayType -
This makes it easy to check against valid options and avoids invalid assignments
What is a pointer data type?
-
A pointer is a special type of variable that stores the memory address of another variable or data item, rather than the data itself
-
Pointers are used to demonstrate dynamic data structures, such as linked lists
|
Pseudocode |
|
|---|---|
|
|
-
The
^indicates the data type is a pointer -
<data type>indicates the type of data stored in the memory location
Example code
TYPE Node DECLARE Data : INTEGER DECLARE Next : ^Node
ENDTYPE DECLARE StartPtr : ^Node
DECLARE NewNode : ^Node // Create a new node
NEW(NewNode)
NewNode^.Data ← 10
NewNode^.Next ← NULL // Initialise the list
StartPtr ← NewNode
|
Line |
What It Does |
|---|---|
|
|
Defines a new record type called |
|
|
Declares a pointer to another |
|
|
Allocates memory for a new node and assigns the pointer to |
|
|
Accesses the contents of the memory the pointer is pointing to |
|
|
A special value used to indicate the end of a linked list (no further nodes) |
Use of pointers in dynamic structures
-
Linked lists: Each node uses a pointer to link to the next
-
Stacks and queues: Implemented using pointers to track top/front positions
-
Memory efficiency: Allows storage to be reused and allocated at runtime
Composite
What are records?
-
A record is a composite user-defined data type that allows you to group together multiple related fields, each of which can have different data types
-
Records are used to represent real-world entities, such as a student, product, or customer, in a single structure
|
Feature |
Explanation |
|---|---|
|
Composite type |
Stores multiple values of different types in one structure |
|
Custom fields |
Each field has a name and a specific data type |
|
Access via dot notation |
Use the format |
|
Reusable |
Once defined, the record type can be used to declare multiple variables of that type |
|
Pseudocode |
|
|---|---|
|
|
Example code
TYPE Student DECLARE Name : STRING DECLARE Age : INTEGER DECLARE Enrolled : BOOLEAN
ENDTYPE DECLARE S1 : Student S1.Name ← "Ali"
S1.Age ← 17
S1.Enrolled ← TRUE OUTPUT S1.Name, " is ", S1.Age, " years old."
-
Groups related data together for easy access
-
Makes programs easier to manage and read
-
Ideal for arrays of records (e.g. a list of students)
What are sets?
-
A set is an unordered collection of unique elements
-
Sets are useful for situations where duplication is not allowed, and where membership testing is common
-
Features of a set include:
-
No duplicate values
-
Order is not important
-
Can perform operations like union, intersection, and difference
-
|
Pseudocode |
|
|---|---|
|
|
Example code
TYPE ColourSet = SET OF STRING
DEFINE Colours ("Red", "Green", "Blue") : ColourSet IF "Green" ISIN Colours THEN OUTPUT "Green is in the set"
ENDIF
-
This creates a set named
Colourscontaining"Red","Green", and"Blue"using the user-defined set typeColourSet
Responses