A2 CS Notes Paper 3 + 4 R.Fok L.Lai E.Min
A2 CS Notes Paper 3 + 4
PRODUCED BY OIC COMPUTER SCIENCE CLASS OF 2023
13 Data Representation 2
13.1 User-defined data types 2
13.2 File organization and access 4
13.3 Floating-point numbers, representation, and manipulation 5
14 Communication and internet technologies 8
14.1 Protocols 8
Definitions: 11
14.2 Circuit switching, packet switching 12
15 Hardware and Virtual Machines 16
15.1 Processors, Parallel Processing and Virtual Machines 16
15.2 Boolean Algebra and Logic Circuits 21
16 System Software 25
16.1 Purposes of an Operating System (OS) 25
16.2 Translation Software 31
17 Security 36
18 Artificial Intelligence (AI) 42
18.1 Artificial Intelligence (AI) 42
19 Computational thinking and problem solving 45
19.2 Recursion Error! Bookmark not defined.
20 Further programming 63
Appendix: Python 80
1
,A2 CS Notes Paper 3 + 4 R.Fok L.Lai E.Min
13 Data Representation
13.1 User-defined data types
Show understanding of why user-defined types are necessary
**User defined data types – a data type based on existing data type or other data
types that have been defined by a programmer in a program
User-defined data types are useful for programmers where the nature of the
problem has data which is more complex than those represented by the simple data
types, integer, string, etc.
It can be divided into 1. Non-composite data type 2. Composite data type
Define and use non-composite types, including enumerated, pointer
**Non-composite data type: defined without referencing another data type
Enumerated type
• An enumeration is an ordered listing of all the items in a collection
TYPE
DECLARE DaysOfTheWeek = (Sunday, Monday, Tuesday,
Wednesday, Thursday, Friday, Saturday)
ENDTYPE
Example: (from 9618/31 May / June 2021 Q1(d)(i))
TYPE SchoolDay = (Monday, Tuesday, Wednesday, Thursday,
Friday)
You can then declare a variable of this type
DECLARE Thisday : DaysOfTheWeek
You can use the variable just like any other
ThisDay ⟵ Thursday
ThisDay ⟵ ThisDay + 1 #now change to Friday
Pointers
• An array is declared to reserve memory for the storage of the data
• Pointers are designed to overcome the need to reserve memory in advance
• Dynamic memory allocation
o Memory will be allocated as and when required
• Pointers are used to access data which is dynamically created at run-time
2
,A2 CS Notes Paper 3 + 4 R.Fok L.Lai E.Min
• A pointer is variable which stores the address of a variable
You can declare a pointer as follows:
DECLARE OrderPointer : ^Order
#^Order is a pointer data type, pointing to data of type
OrderPointer
Define and use composite data types, including set, record, and class/object
**Composite data type: a data type that refers to any other data types in its
type definition
Sets
• Can be used to check the validity of a user’s input
• Replaces standard IF statement for many conditions
• So instead of IF Choice=1 OR Choice=2 OR Choice=3 OR Choice=4
THEN…
• We can say DECLARE MenuChoice : SET OF (1,2,3,4,5)
o IF Choice IN MenuChoice
Records
TYPE Transaction
Bank_ID : STRING
AccountNumber : INTEGER
TransactionDate : DATE
TransactionTime : INTEGER
TransactionType : CHAR
Amount : REAL
ATM_ID : INTEGER
ENDTYPE
DECLARE Food: Transaction
Food.Amount ⟵ 200
A combination of different data types and group them under 1 identifier
Classes
• Blueprints from which actual objects (called instances) will be created
Objects
• Instances that are created from Classes
3
, A2 CS Notes Paper 3 + 4 R.Fok L.Lai E.Min
**Choose and design an appropriate user-defined data type for a given problem
Usually in the form of a record
13.2 File organization and access
Show understanding of the methods of file organization and select an appropriate
method of file organization and file access for a given problem
Including serial, sequential (using a key field), random (using a record key)
Serial file organization
• Records are written to the file in chronological order, new records are
appended to the end of the file
• Useful for bank transaction logs / telephone logs
• Only appear in the order in which they were created in the file
Bank Transaction 1 Customer 1 Date 1
Bank Transaction 2 Customer 2 Date 2
Bank Transaction 3 Customer 3 Date 3
Sequential file organization (key field)
• Stored in an order based on the key field of the records as it is the unique
identifier
• Example could be gas bill, as customer number probably is the key field
which uniquely defines each record
• Note: record must be added in correct space
Random file organization (record key)
• Stores records of data in a file in any available position
• Allows direct access to a particular record in the file
• For records to be written and read to / from the file in the same file session
• File opened in RANDOM mode
• The user will allocate each record a record key number
• Takes a record key number à hashing function à calculated address
Comparing the different file organization methods
Method Write Read
Serial ✅✅ ❌❌❌
Sequential ❌❌❌ (New records ✅✅
need to be added to
correct place)
4