AS Computer Science 9618
Complete Notes
Compiled by: Nadia Arif
For Details:
Sharjeel Arif: 0333 – 5752253
Office 22- 23, First Floor Al-babar Center, F-8 markaz, Islamabad
Table of Contents
No. Chapter Name Page Number
1 Data Representation 1
2 Communication 30
3 Hardware 59
4 Processor Fundamentals 83
5 System Software 109
6 Security, Privacy & Data Integrity 126
7 Ethics & Ownership 137
8 Databases 146
9 Algorithm Design & Problem solving 162
10 & 11 Data Types & Structures 182
12 Software Development 209
13 Pseudocode Guide 221
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 1
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
1.1 Number systems
1.1.1 Binary represents data:
The binary number system is a base 2 number system. It is based on
the number 2. Thus, only the two ‘values’ 0 and 1 can be used in this
system to represent all values.
Binary to Denary (Decimal)
(1100110)2 ----> (? )10
26 25 24 23 22 21 20
64 32 16 8 4 2 1
1 1 0 0 1 1 0
Only add the 1's
64 + 32 + 4 + 2 = 102
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 2
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Denary to Binary:
(131)10 ----> (?)2
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
1 0 0 0 0 0 1 1
Guide:
Step 1:
Turn the 128 bit on as it is the immediate number that's less than 131
Now subtract 128 from 131
131 - 128 = 3
Step 2:
Now turn the 2 bit on as it is the immediate number that's less than 3
Subtract 2 from 3
3-2=1
Step 3:
Now turn the 1 bit on
Subtract 1-1 = 0
Step 4:
Write down the binary
131 = 10000011
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 3
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Binary to Hexadecimal (16)
(100111011)2 ----> (?)16
Guide:
Make a group of four bits starting from the right hand side
0001 0011 1011
Write down the decimal of each group
0001 = 1
0011 = 3
1011 = 11 --> B (In hexa decimal any number greater than 9 and less
than 15 is written in alphabets)
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15
So,
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 4
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
100111011 = 13B
Hexa to Binary
(9DC)16 ----> ( ? )2
9 D C
9 13 12
1001 1101 1100
9DC = 100111011100
Decimal to Hexa:
(119)10 ----> (?)16
Step 1: Convert to binary
26 25 24 23 22 21 20
64 32 16 8 4 2 1
1 1 1 0 1 1 1
Step 2: Convert binary to hexadecimal
1110111
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 5
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
0111 = 7
0111 = 7
Step 3:
1110111 = 77
Hexadecimal to Decimal:
(BD5)16 ---> ( ? )10
Method 1:
Step 1:
Write down the binary of each bit separately
B = 11 = 1001
D = 13 = 1101
5 = 0101
Step 2:
convert the binary to decimal
BD5 = 1010 1100 0101
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 6
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
211 210 29 28 27 26 25 24 23 22 21 20
2048 1024 512 256 128 64 32 16 8 4 2 1
1 0 1 0 1 1 0 0 0 1 0 1
2048 + 512 + 128 + 64 + 4 + 1 = 2757
BD5 = 2757
Method 2:
162 161 160
256 16 1
B = 11 D = 13 5
256 x 11 = 2,816
13 x 16 = 208
5x1=5
BD5 = 2816 + 208 + 5 = 3029
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 7
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
1.1.3 Use of the hexadecimal system
error codes
MAC addresses
IPv6 addresses
HTML colour codes
Error codes:
Error codes are often shown as hexadecimal values. These numbers refer
to the memory location of the error and are usually automatically
generated by the computer.
Media Access Control (MAC) addresses:
Media Access Control (MAC) address refers to a number which uniquely
identifies a device on a network. The MAC address refers to the
network interface card (NIC) which is part of the device. The MAC
address is rarely changed so that a particular device can always be
identified no matter where it is.
A MAC address is usually made up of 48 bits which are shown as 6
groups of two hexadecimal digits (although 64-bit addresses also exist):
NN – NN – NN – DD – DD – DD
or
NN:NN:NN:DD:DD:DD
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 8
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
where the first half (NN – NN – NN) is the identity number of the
manufacturer of the device and the second half (DD – DD – DD) is
the serial number of the device.
Internet Protocol (IP) addresses Each device connected to a network is
given an address known as the Internet Protocol (IP) address.
HyperText Mark-up Language (HTML) colour codes:
HyperText Mark-up Language (HTML) is used when writing and
developing web pages. A mark-up language is used in the processing,
definition and presentation of text
1.1.4 Addition of binary numbers
A B Sum (A+B) Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 9
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
A B C Sum (A+B+C) Carry
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
1.1.5 Logical binary shifts
Logical Left Shift:
logical shift means moving the binary number to the left
Each shift left is equivalent to multiplying the binary number by 2
Logical Right Shift:
logical shift means moving the binary number to the right
each shift right is equivalent to dividing the binary number by 2
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 10
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Example 1:
The denary number 21 is 00010101 in binary.
If we put this into an 8-bit register:
128 64 32 16 8 4 2 1
0 0 0 1 0 1 0 1
If we now shift the bits in this register one place to the left, we obtain:
128 64 32 16 8 4 2 1
0 0 1 0 1 0 1 0
The value of the binary bits is now
32 + 8 + 2 = 42
The original number was 21
21 x 2 = 42
Example 2:
The denary number 200 is 11001000 in binary.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 11
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
If we put this into an 8-bit register:
128 64 32 16 8 4 2 1
1 1 0 0 1 0 0 0
If we now shift the bits in this register one place to the right, we
obtain:
128 64 32 16 8 4 2 1
0 1 1 0 0 1 0 0
The value of the binary bits is now
64+32+4 = 100
The original number was 200
200/2 = 100
1.1.6 Two’s complement (binary numbers)
Convert -113 to binary
Note that the most significant bit of a negative number is always
1
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 12
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Step 1: write the binary of 113
128 64 32 16 8 4 2 1
0 1 1 1 0 0 0 1
Step 2: take 1's compliment (reverse all the bits)
01110001 = 10001110
Step 3: take 2's compliment (add 1 to the least significant bit)
10001110
+ 1
10001111
-113 = 10001111
Proof:
To check if the answer is correct
-128 64 32 16 8 4 2 1
1 0 0 0 1 1 1 1
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 13
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
-128 + 8 + 4 +2 +1 = -113
1.1.5 Binary coded decimal (BCD) system :
The binary-coded decimal (BCD) system uses a 4-bit code to represent each
denary digit:
0000=0 0101=5
0001=1 0110=6
0010=2 0111=7
0011=3 1000=8
0100=4 1001=9
Therefore, the denary number 3 1 6 5 would be 0 0 1 1 0 0 0 1 0 1 1 0 0 1 0 1
in BCD format
Uses of BCD:
The most obvious use of BCD is in the representation of digits on a calculator
or clock display.
1.2 Text, sound and images
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 14
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
1.2.1 Character sets – ASCII code and Unicode
The standard ASCII code character set consists of 7-bit codes
that represent the letters, numbers and characters found on a
standard keyboard, together with 32 control codes
The main disadvantage is that it does not represent characters in
non-Western languages, for example Chinese characters.
For this reason, different methods of coding have been developed
over the years. One coding system is called Unicode. Unicode can
represent all languages of the world, thus supporting many
operating systems, search engines and internet browsers used
globally.
The Unicode consortium was set up in 1991. Version 1.0 was published with
five goals; these were to:
create a universal standard that covered all languages and all
writing systems
produce a more efficient coding system than ASCII » adopt
uniform encoding where each character is encoded as 16-bit or 32-
bit code
create unambiguous encoding where each 16-bit and 32-bit value
always represents the same character
reserve part of the code for private use to enable a user to assign
codes for their own characters and symbols
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 15
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
1.2.2 Representation of sound :
Sound waves vary continuously.
This means that sound is analogue.
Computers cannot work with analogue data, so sound waves need
to be sampled in order to be stored in a computer.
Sampling means measuring the amplitude of the sound wave.
This is done using an analogue to digital converter (ADC).
To convert the analogue data to digital, the sound waves are
sampled at regular time intervals.
The amplitude of the sound cannot be measured precisely, so
approximate values are stored.
The number of bits per sample is known as the sampling resolution (also
known as the bit depth).
Sampling rate is the number of sound samples taken per second. This is
measured in hertz (Hz), where 1Hz means ‘one sample per second’.
So how is sampling used to record a sound clip?
the amplitude of the sound wave is first determined at set time
intervals (the sampling rate)
this gives an approximate representation of the sound wave
each sample of the sound wave is then encoded as a series of
binary digits.
Using a higher sampling rate or larger resolution will result in a more
faithful representation of the original sound source. However, the higher
the sampling rate and/or sampling resolution, the greater the file size.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 16
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Benefits Drawbacks
larger dynamic range produces larger file size
better sound quality takes longer to transmit/download
music files
less sound distortion requires greater processing power
Frame rate: When recording a video the frame rate refers to the
number of frames recorded per second.
1.2.3 Representation of (bitmap) images
Bitmap images are made up of pixels (picture elements); an image is
made up of a two-dimensional matrix of pixels.
Each pixel can be represented as a binary number, and so a bitmap
image is stored in a computer as a series of binary numbers, so that:
a black and white image only requires 1 bit per pixel – this means
that each pixel can be one of two colours, corresponding to either 1
or 0
if each pixel is represented by 2 bits, then each pixel can be one
of four colours (22 = 4), corresponding to 00, 01, 10, or 11
if each pixel is represented by 3 bits then each pixel can be one of
eight colours (23 = 8), corresponding to 000, 001, 010, 011, 100, 101,
110, 111.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 17
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
The number of bits used to represent each colour is called the colour
depth. An 8 bit colour depth means that each pixel can be one of 256
colours
Image resolution refers to the number of pixels that make up an image;
for example, an image could contain 4096 × 3072 pixels (12 582 912
pixels in total).
Drawback:
The main drawback of using high resolution images is the increase
in file size.
As the number of pixels used to represent the image is increased,
the size of the file will also increase.
This impacts on how many images can be stored on, for example, a
hard drive.
It also impacts on the time to download an image from the
internet or the time to transfer images from device to device.
A certain amount of reduction in resolution of an image is possible
before the loss of quality becomes noticeable.
Image resolution: refers to the number of pixels that make up an
image; for example, an image could contain 4096 × 3192 pixels (12738
656 pixels in total).
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 18
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
1.2.4 Vector graphics
Vector graphics are images that use 2D points to describe lines and
curves and their properties that are grouped to form geometric shapes.
A vector graphic will contain a drawing list (included in a file header)
that is made up of
the command used for each object that makes up the graphic
image
the attributes that define the properties that make up each
object (for example consider the ellipse of the robot’s mouth
the relative position of each object will also need to be included
the dimensions of each object are not defined, but the relative
positions of objects to each other in the final graphic need to be
defined; this means that scaling up the vector graphic image will
result in no loss of quality.
Comparison between vector graphics and bit-map images
Vector graphic images Bit-map images
made up of geometric shapes which made up of tiny pixels of
require definition/attributes different colours
to alter/edit the design, it is necessary possible to alter/edit each of
to change each of the geometric shapes the pixels to change the
design of the image
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 19
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
they do not require large file size since because of the use of pixels
it is made up of simple geometric shapes (which give very accurate
designs), the file size is very
large
because the number of geometric since images are built up pixel
shapes is limited, vector graphics are not by pixel, the final image is
usually very realistic usually very realistic
file formats are usually .svg, .cgm, .odg file formats are usually .jpeg,
.bmp, .png
1.3 Data storage and file compression
1.3.1 Measurement of data storage
A bit is the basic unit of all computing memory storage terms and
is either 1 or 0.
The word comes from binary digit. The byte is the smallest unit of
memory in a computer. 1 byte is 8 bits.
A 4-bit number is called a nibble – half a byte.
Name of memory size Equivalent denary value
1 kilobyte (1KB) 1000 bytes 1000 bytes
1 megabyte (1MB) 1000000 bytes 1000 KB
1 gigabyte (1GB) 1000000000 bytes 1000 MB
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 20
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
1 terabyte (1TB) 1000000000000 bytes 1000 GB
1 petabyte (1PB) 1000000000000000 bytes 1000 TB
1 exabyte (1EB) 1000000000000000000 bytes 1000 PB
Name of memory Number of Equivalent denary value
size bytes
1 Kibibyte (1KiB) 210 1024 bytes 1024
bytes
1mebibyte (1MiB) 220 1048576 bytes 1024
KiB
1gibibyte (1GiB) 230 1073741824 bytes 1024
MiB
1tebibyte (1TiB) 240 1099511627776 bytes 1024
GiB
1pebibyte (1PiB) 250 1125899906842624 bytes 1024
TiB
1exbibyte (1EiB) 260 1152921504606846976 1024
bytes PiB
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 21
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
1.3.2 Calculation of file size:
The file size of an image is calculated as:
image resolution (in pixels) × colour depth (in bits)
The size of a mono sound file is calculated as:
sample rate (in Hz) × sample resolution (in bits) × length of sample (in
seconds)
Example 1:
A photograph is 1024 × 1080 pixels and uses a colour depth of 32 bits.
How many photographs of this size would fit onto a memory stick of
64GiB?
Multiply number of pixels in vertical and horizontal directions to
find
total number of pixels = (1024 × 1080) = 1105920 pixels
Now multiply number of pixels by colour depth then divide by 8 to
give the
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 22
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
number of bytes = 1105920 × 32 = 35389440/8 bytes = 4423680
bytes
64 GiB = 64 × 1024 × 1024 × 1024 = 68719476736 bytes
Finally divide the memory stick size by the files size =
68719476736/4423680 = 15534 photos
Example 2:
A camera detector has an array of 2048 by 2048 pixels and uses a
colour depth of 16. Find the size of an image taken by this camera in
MiB.
Multiply number of pixels in vertical and horizontal directions to
find
total number of pixels = (2048 × 2048) = 4194304pixels
Now multiply number of pixels by colour depth = 4194304 × 16 =
67108864bits
Now divide number of bits by 8 to find the number of bytes in
the file = (67108864)/8 = 8388608bytes
Now divide by 1024 × 1024 to convert to MiB =
(8388608)/(1048576) = 8MiB.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 23
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Example 3:
An audio CD has a sample rate of 44100 and a sample resolution of
16bits. The music being sampled uses two channels to allow for stereo
recording. Calculate the file size for a 60-minute recording.
Size of file = sample rate (in Hz) × sample resolution (in bits) ×
length of sample (in seconds)
Size of sample = (44100 × 16 × (60 × 60)) = 2540160000bits
Multiply by 2 since there are two channels being used =
5080320000bits
Divide by 8 to find number of bytes = (5080320000)/8 =
635040000
Divide by 1024 × 1024 to convert to MiB = 635 040 000 / 1 048
576 = 605MiB.
1.3.3 Data compression
The size of a file can be quite large.It is therefore necessary to reduce
(or compress) the size of a file for the following reasons:
to save storage space on devices such as the hard disk drive/solid
state drive
to reduce the time taken to stream a music or video file
to reduce the time taken to upload, download or transfer a file
across a network
the download/upload process uses up network bandwidth – this is
the maximum rate of transfer of data across a network, measured
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 24
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
in bits per second. This occurs whenever a file is downloaded, for
example, from a server. Compressed files contain fewer bits of data
than uncompressed files and therefore use less bandwidth, which
results in a faster data transfer rate.
reduced file size also reduces costs. For example, when using cloud
storage, the cost is based on the size of the files stored. Also an
internet service provider (ISP) may charge a user based on the
amount of data downloaded.
1.3.4 Lossy and lossless file compression
File compression can either be lossless or lossy.
Lossy file compression:
With this technique, the file compression algorithm eliminates
unnecessary data from the file. This means the original file cannot be
reconstructed once it has been compressed. Lossy file compression
results in some loss of detail when compared to the original file. The
algorithms used in the lossy technique have to decide which parts of the
file need to be retained and which parts can be discarded. For example,
when applying a lossy file compression algorithm to:
an image, it may reduce the resolution and/or the bit/colour depth
a sound file, it may reduce the sampling rate and/or the resolution
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 25
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Lossy files are smaller than lossless files which is of great benefit when
considering storage and data transfer rate requirements. Common lossy
file compression algorithms are:
MPEG-3 (MP3) and MPEG-4 (MP4)
JPEG.
MPEG-3 (MP3) and MPEG-4 (MP4):
MP3 files are used for playing music on computers or mobile phones.
This compression technology will reduce the size of a normal music file
by about 90%.
This is done using file compression algorithms that use perceptual music
shaping.
For example:
removal of sounds outside the human ear range
if two sounds are played at the same time, only the louder one can
be heard by the ear, so the softer sound is eliminated. This is
called perceptual music shaping.
MP4 files are slightly different to MP3 files. This format allows the
storage of multimedia files rather than just sound – music, videos,
photos and animation can all be stored in the MP4 format. As with
MP3, this is a lossy file compression format, but it still retains an
acceptable quality of sound and video.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 26
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
Movies, for example, could be streamed over the internet using the MP4
format without losing any real discernible quality.
JPEG:
When a camera takes a photograph, it produces a raw bitmap file which
can be very large in size. These files are temporary in nature. JPEG is a
lossy file compression algorithm used for bitmap images.
The JPEG file reduction process is based on two key concepts:
human eyes don’t detect differences in colour shades quite as well
as they detect differences in image brightness
by separating pixel colour from brightness, images can be split into
8 × 8 pixel blocks
Lossless file compression
Lossless file compression is designed so that none of the original detail
from the file is lost.
Run-length encoding (RLE) can be used for lossless compression of a
number of different file formats:
it is a form of lossless/reversible file compression
it reduces the size of a string of adjacent, identical data (e.g.
repeated colours in an image)
a repeating string is encoded into two values:
– the first value represents the number of identical data items
in the run
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 27
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
– the second value represents the code of the data item
RLE is only effective where there is a long run of repeated
units/bits.
Using RLE on text data
Consider the text string ‘aaaaabbbbccddddd’. Assuming each character
requires 1byte, then this string needs 16 bytes. If we assume ASCII code
is being used, then the string can be coded as follows:
a a a a a b b b b c c d d d d d
05 97 04 98 02 99 05 100
Using RLE with images
Black and white images
Coloured images
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 28
AS Computer Science - 9618 Chapter 1 : Data Representation Instructor: Nadia Arif
This produces the following data:
2 0 0 0 4 0 255 0 3 0 0 0 6 255 255 255 1 0 0 0 2 0 255 0 4 255
0 0 4 0 255 0 1 255 255 255 2 255 0 0 1 255 255 255 4 0 255 0
4 255 0 0 4 0 255 0 4 255 255 255 2 0 255 0 1 0 0 0 2 255 255
255 2 255 0 0 2 255 255 255 3 0 0 0 4 0 255 0 2 0 0 0
1.3.5 General methods of compressing files
Movie Files reduce the sampling rate used
reduce the sampling resolution
reduce the frame rate
Image Files crop the image
decrease the colour/bit depth
reduce the image resolution
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 29
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 30
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
2.1 - Networking:
Networks can be categorised as private or public
Private networks are owned by a Public networks are owned by a
single company or organisation communications carrier company
(they are often LANs or intranets (such as a telecoms company);
with restricted user access, many organisations will use the
For example, passwords and user network and there are usually no
ids are required to join the specific password requirements to
enter the network
network) but sub networks may be under
security management.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 31
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
WANs & LANs
LAN WLAN WAN
LANs are usually Wireless LANs (WLANs) Wide area networks
contained within are similar to LANs but (WANs) are used
one building, or there are no wires or when computers or
within a small cables. networks are
geographical area. In other words, they situated a long
A typical LAN provide wireless distance from each
consists of a network other
number of communications over If a number of LANs
computers and fairly short distances are joined together
devices (such as (up to 100 metres) using a router or
printers) connected using radio or infrared modem, they can
to hubs or switches. signals instead of using form a WAN.
One of the hubs or cables The network of
switches is usually automated teller
connected to a machines (ATMs)
router and/or used by banks is one
modem to allow the of the most common
LAN to connect to examples of the use
the internet or of a WAN.
become part of a
wide area network
(WAN )
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 32
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Client - server and peer-to-peer networking models
Client - server model:
The client-server model uses separate dedicated servers and specific client
workstations; client computers will be connected to the server computer(s).
Users are able to access most of the files, which are stored on dedicated
servers.
The server dictates which users are able to access which files.
The client-server model allows the installation of software onto a client’s
computer.
The model uses central security databases which control access to the shared
resources.
Once a user is logged into the system, they will have access to only those
resources (such as a printer) and files assigned to them by the network
administrator, so offers greater security than peer-to-peer networks.
Client-server networks can be as large as you want them to be and they are
much easier to scale up than peer-to-peer networks.
A central server looks after the storing, delivery and sending of emails.
This model offers the most stable system, for example, if someone deletes a
shared resource from the server, the nightly back-up would restore the
deleted resource
Client-server networks can become bottlenecked if there are several client
requests at the same time.
Advantages:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 33
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Central storage and management of data files, thus enabling other network
users to access files
allowing users to share information without the need for offline devices (such
as a memory stick)
allowing any computer to be configured as the host machine and act as the
file server (note that the server could be a storage device (such as SSD or
HDD) that could also serve as a remote storage device for other computers,
thus allowing them to access this device as if it were a local storage device
attached to their computer).
Examples of use of client-server network model:
A company/user would choose a client-server network model for the
following reasons.
The company/user has a large user-base
Access to network resources needs to be properly controlled.
There is a need for good network security.
The company requires its data to be free from accidental loss (in other
words, data needs to be backed up at a central location).
Peer-to-peer model:
On a peer-to-peer network, each node joins the network to allow
the provision of services to all other network users; the services available are
listed on a nominated ‘look up’ computer – when a node requests a service,
the ‘look up’ computer is contacted to find out which of the other network
nodes can provide the required service
other users on the network to simply access data from another node
communication with other peers connected to the network
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 34
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
peers to be both suppliers and consumers
peers to participate as equals on the network
The peer-to-peer model does not have a central server.
Each of the nodes (workstations) on the network can share its files with all
the other nodes, and each of the nodes will have its own data.
Because there is no central storage, there is no requirement to authenticate
users.
This model is used in scenarios where no more than 10 nodes are required
(such as a small business)
where it is relatively easy for users to be in contact with each other on a
regular basis. More than 10 nodes leads to performance and management
issues.
Disadvantages:
Peer-to-peer offers little data security since there is no central security
system. This means it is impossible to know who is authorised to share
certain data.
Users can create their own network node share point which is the only real
security aspect since this gives them some kind of control. However, there
are no real authentication procedures.
Examples of peer-to-peer network model:
A user would choose the peer-to-peer network model for one or more of
following reasons:
The network of users is fairly small.
There is no need for robust security.
They require workstation-based applications rather than being server-based.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 35
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Thick and Thin Clients:
Thick Client Thin Client
always relies on a connection to a can run some of the features of the
remote server or computer for it to software even when not connected
work to a server
requires very few local resources (such relies heavily on local resources
as SSD, RAM memory or computer
processing time)
relies on a good, stable and fast more tolerant of a slow network
network connection for it to work connection
data is stored on a remote server or can store data on local resources
computer such as HDD or SSD
Thick Client Thin Client
Pros more robust (device can less expensive to expand (low-
carry out processing powered and cheap devices can be
even when not used)
connected to server) all devices are linked to a server
clients have more (data updates and new software
control (they can store installation done centrally)
their own programs and server can offer protection against
data/ files hacking and malware
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 36
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Cons less secure (relies on high reliance on the server; if the
clients to keep their server goes down or there is a
own data secure) break in the communication link
each client needs to then the devices cannot work
update data and despite cheaper hardware, the
software individually start-up costs are generally higher
data integrity issues, than for thick clients
since many clients
access the same data
which can lead to
inconsistencies
Network Topologies:
bus networks
star networks
mesh networks
hybrid networks
Bus networks
A bus network topology uses a single central cable to which all computers
and devices are connected.
It is easy to expand and requires little cabling.
Data can only travel in one direction; if data is being sent between devices
then other devices cannot transmit.
Bus networks are typically peer-to-peer
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 37
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Advantages Disadvantages
Even if one node fails, the If the main cable fails, the whole
remainder of the network network goes down.
continues to function. The performance of the network
It is easy to increase the size deteriorates under heavy loading.
of the network by adding The network is not secure since
additional nodes. each packet passes through every
node.
Packet transfer over bus topology:
In bus network topology, each node looks at each packet and
determines whether or not the address of the recipient in the package
matches the node address.
If so, the node accepts the packet; if not, the packet is ignored.
These are most suitable for situations with a small number of devices
with light traffic occurring. For example, a small company or an office
environment.
Star networks:
A star network topology uses a central hub/switch and each
computer/device is connected to the hub/switch.
Data going from host to host is directed through the central
hub/switch.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 38
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Each computer/device has its own dedicated connection to the central
node (hub/switch) – any type of network cable can be used for the
connections
Advantages: Disadvantages:
Data collisions are greatly reduced due The initial installation costs are
to the topology. high.
It is a more secure network since If the central hub/switch fails,
security methods can be applied to the then the whole network goes down.
central node and packets only travel to
nodes with the correct address.
It is easy to improve by simply
installing an upgraded hub.
If one of the connections is broken it
only affects one of the nodes.
Packet transfer over star topology:
How packets are handled depends on whether the central node is a
switch or a hub.
If it is a hub, all the packets will be sent to every device/node on the
star network
if the address in the packet matches that of the node, it will be
accepted; otherwise, it is ignored
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 39
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
If the central node is a switch, packets will only be sent to nodes
where the address matches the recipient address in the packet.
The latter is clearly more secure, since only nodes intended to see the
packet will receive it.
Mesh networks:
There are two types of mesh network topologies: routing and flooding.
Routing works by giving the nodes routing logic (in other words, they
act like a router) so that data is directed to its destination by the
shortest route and can be re-routed if one of the nodes in the route
has failed.
Flooding simply sends the data via all the nodes and uses no routing
logic, which can lead to unnecessary loading on the network.
Advantages: Disadvantages:
It is easy to identify where faults on the A large amount of cabling is
network have occurred. needed, which is expensive
and time consuming.
Any broken links in the network do not Set-up and maintenance is
affect the other nodes. difficult and complex.
Good privacy and security, since packets
travel along dedicated routes.
The network is relatively easy to expand.
Hybrid networks:
A hybrid network is a mixture of two or more different topologies
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 40
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
The main advantages and disadvantages depend on which types of network
are used to make up the hybrid network,
but an additional disadvantage is that they can be very complex to install,
configure and maintain.
Additional advantages include:
They can handle large volumes of traffic.
It is easy to identify where a network fault has occurred.
They are very well suited to the creation of larger networks.
Public and Private Cloud Computing:
Public cloud is a storage environment where the customer/client and cloud
storage provider are different companies.
Private cloud is storage provided by a dedicated environment behind a
company firewall. Customer/client and cloud storage provider are integrated
and operate as a single entity.
Hybrid cloud is a combination of private and public clouds. Some data resides
in the private cloud and less sensitive/less commercial data can be accessed
from a public cloud storage provider.
Pros of using cloud storage Cons of using cloud storage
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 41
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
customer/client files stored on if the customer/client has a slow
the cloud can be accessed at or unstable internet connection,
any time from any device they would have problems
anywhere in the world provided accessing or downloading their
internet access is available data/files
no need for a customer/client to costs can be high if large
carry an external storage device storage capacity is required
with them, or use the same expensive to pay for high
computer to store and retrieve download/upload data transfer
information limits with the customer/client
provides the user with remote internet service provider (ISP)
back-up of data to aid data loss potential failure of the cloud
and disaster recovery storage company is possible –
recovers data if a this poses a risk of loss of all
customer/client has a hard disk back-up data
or back-up device failure
offers almost unlimited
storage capacity
Wired and wireless networking
Wireless networking
It is easier to expand networks and is not necessary to connect devices
using cables.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 42
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Devices have increased mobility, provided they are within range of the
WAPs.
Increased chance of interference from external sources.
Data is less secure than with wired systems; it is easier to intercept
radio waves and microwaves than cables so it is essential to protect
data transmissions using encryption.
Data transmission rate is slower than wired networks (although it is
improving).
Signals can be stopped by thick walls (in old houses, for example) and
signal strength can vary, or ‘drop out’.
Wired networking
More reliable and stable network (wireless connectivity is often
subjected to interference).
Data transfer rates tend to be faster with no ‘dead spots’.
Tends to be cheaper overall, in spite of the need to buy and install
cable.
Devices are not mobile; they must be close enough to allow for cable
connections.
Lots of wires can lead to tripping hazards, overheating of connections
(potential fire risk) and disconnection of cables during routine office
cleaning.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 43
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Hardware requirements of networks
Hub :
Hubs are hardware devices that can have a number of devices or
computers connected to them.
They are often used to connect a number of devices to form a local
area network (LAN), for example a star network .
A hub’s main task is to take any data packet (a group of data being
transmitted) received at one of its ports and then send the data to
every computer in the network.
Using hubs is not a very secure method of data distribution and is also
wasteful of bandwidth.
Switch :
Switches are similar to hubs, but are more efficient in the way they
distribute the data packet.
As with hubs, they connect a number of devices or computers
together to form a LAN (for example, a star network).
However, unlike a hub, the switch checks the data packet received
and works out its destination address (or addresses) and sends the data
to the appropriate computer(s) only.
This makes using a switch a more secure and efficient way of
distributing data.
Each device or computer on a network has a media access control
(MAC) address which identifies it uniquely.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 44
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Data packets sent to switches will have a MAC address identifying the
source of the data and additional addresses identifying each device
which should receive the data. Note that switches can be wired or
wireless devices.
Repeater:
When signals are sent over long distances, they suffer attenuation or
signal loss.
Repeaters are devices which are added to transmission systems to boost
the signal so it can travel greater distances.
They amplify signals on both analogue (copper cable) and digital (fibre
optic cable) communication links
Bridge:
Bridges are devices that connect one LAN to another LAN that uses
the same protocol (communication rules).
They are often used to connect together different parts of a LAN so
that they can function as a single LAN.
Router:
Routers enable data packets to be routed between the different
networks for example, to join a LAN to a WAN.
The router takes data transmitted in one format from a network
(which is using a particular protocol) and converts the data to a
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 45
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
protocol and format understood by another network, thereby allowing
them to communicate via the router.
We can, therefore, summarise the role of routers as follows.
restrict broadcasts to a LAN
act as a default gateway
can perform protocol translation; for example, allowing a wired network
to communicate with a wireless (Wi-Fi) network
the router can take an Ethernet data packet, remove the Ethernet
part and put the IP address into a frame recognised by the wireless
protocol (in other words, it is performing a protocol conversion)
can move data between networks
can calculate the best route to a network destination address
Gateway:
A gateway is a network point (or node) that acts as an entrance to
another network.
It is a key point for data on its way to or from other networks.
It can be used to connect two or more dissimilar LANs (LANs using
different protocols).
The gateway converts data packets from one protocol to another.
Modems:
Modern computers work with digital data, whereas many of the public
communication channels still only allow analogue data transmission.
To allow the transmission of digital data over analogue communication
channels we need to use a modem (modulator demodulator).
This device converts digital data to analogue data.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 46
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
It also does the reverse and converts data received over the analogue
network into digital data which can be understood by the computer
Routers Gateways
forward packets of data from convert one protocol (or data format)
one network to another; routers to another protocol (format) used in
read each incoming packet of a different network
data and decide where to forward
the packet
can route traffic from one convert data packets from one
network to another network protocol to another; they act as an
entry and exit point to networks
can be used to join LANs translate from one protocol to
together to form a WAN another
(sometimes called brouters) and
also to connect a number of
LANs to the internet
offer additional features such as do not support dynamic routing
dynamic routing (ability to
forward data by different routes)
Network interface card (NIC):
A network interface card (NIC) is needed to allow a device to connect
to a network (such as the internet).
It is usually part of the device hardware and frequently contains the
MAC address generated at the manufacturing stage.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 47
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Wireless network interface card/controller (WNIC):
Wireless network interface cards/controllers (WNICs) are the same as
the more ordinary NICs, in that they are used to connect devices to
the internet or other networks.
They use an antenna to communicate with networks via microwaves
and normally simply plug into a USB port or can be internal integrated
circuit plug in.
Ethernet:
Ethernet is a protocol used by many wired LANs.A network using Ethernet
is made up of:
a node (any device on the LAN)
medium (path used by the LAN devices, such as an Ethernet cable)
frame (data is transmitted in frames which are made up of source
address and destination address – the addresses are often the MAC
address).
Collisions:
Ethernet supports broadcast transmission (communications where pieces
of data are sent from sender to receiver) and are used to send
messages to all devices connected to a LAN.
The risk is that two messages using the same data channel could be
sent at the same time, leading to a collision.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 48
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Carrier sense multiple access with collision detection (CSMA/CD) was
developed to try and resolve this issue.
Collison detection depends on simple physics: when a frame is sent it
causes a voltage change on the Ethernet cable.
When a collision is detected, a node stops transmitting a frame and
transmits a ‘jam’ signal and then waits for a random time interval
before trying to resend the frame.
CSMA/CD protocol will define the random time period for a device to
wait before trying again.
Bit streaming:
Bit streaming is a contiguous sequence of digital bits sent over the
internet or a network that requires a high speed data communication
link (such as fast broadband).
Since bit streaming often involves very large files (such as video) it is
necessary for the files to undergo some data compression before
transmission.
It is also necessary to have some form of buffering to ensure smooth
playback of the media files.
The data transmission rate from the file server (containing the video,
for example) to the buffer must be greater than the rate at which
data is transmitted from buffer to media player.
The larger the buffer, the better the control over the bit rate being
sent to the media player
2.2 - The Internet
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 49
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Internet
The internet is a massive network of networks which are made up of
various computers and other electronic devices.
It stands for interconnected network.
The internet makes use of transmission control protocol
(TCP)/internet protocol (IP)
World Wide Web (WWW)
This is a collection of multimedia web pages and other documents
which are stored on websites.
http(s) protocols are written using HyperText Mark-up Language
(HTML).
Uniform resource locators (URLs) specify the location of all web pages.
Web resources are accessed by web browsers.
The world wide web uses the internet to access information from
servers and other computers.
Hardware and software needed to support the internet
The fundamental requirements for connecting to the internet are
a device (such as a computer, tablet or mobile phone)
a telephone line connection or a mobile phone network connection
(however, it is possible that a tablet or mobile phone may connect to
the internet using a wireless router)
a router (which can be wired or wireless) or router and modem
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 50
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
an internet service provider (ISP) (combination of hardware and
software)
a web browser.
Comparison between PSTN and internet when making a phone call
PSTN Phone calls using the internet
Public switched telephone Phone calls using the internet use
network (PSTN) PSTN uses a either an internet phone or
standard telephone connected microphone and speakers (video calls
to a telephone line. also require a webcam).
The telephone line connection The internet connection is only ‘live’
is always open whether or not while data (sound/video image) is
anybody is talking being transmitted.
the link is not terminated until Voice over Internet Protocol (VoIP)
the receivers are replaced by converts sound to digital packages
both parties. (encoding) which can be sent over
Telephone lines remain active the internet.
even during a power cut; they VoIP uses packet switching; the
have their own power source. networks simply send and retrieve
data as it is needed so there is no
dedicated line, unlike PSTN.
Data is routed through thousands of
possible pathways, allowing the
fastest route to be determined.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 51
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Cellular networks and satellites
Other devices, such as mobile phones, use the cellular network.
Here, the mobile phone providers act as the ISPs and the phones
contain communication software which allows them to access the
telephone network and also permits them to make an internet
connection.
Satellites are an important part of all network communications that
cover vast distances
IP addresses
The internet is based on TCP/IP protocols.
Protocols define the rules that must be agreed by senders and receivers
on the internet
Internet protocols (IP):
IPv4 addressing
The most common type of addressing on the internet is IP version 4 (IPv4).
This is based on 32bits giving 232 (4294 967296) possible addresses. The
32bits are split into four groups of 8bits (thus giving a range of 0 to 255).
For example, 254.0.128.77.
Network IPv4 range Number of Number of Types of
class netID bits hostID bits network
A 0.0.0.0 to 8 24 very large
127.255.255.255
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 52
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
B 128.0.0.0 to 16 16 medium size
191.255.255.255
C 192.0.0.0 to 24 8 small
223.255.255.255 networks
D 224.0.0.0 to – – multi-cast
239.255.255.255
E 240.0.0.0 to – – experimental
255.255.255.255
Drawback:
IPv4 system provides insufficient address range.
For example, a user with a medium sized network (class B) might have
284 host machines and their class B licence allows them 216.
This means several of the allocated host IDs will not be used, which is
wasteful.
Solution:
Classless inter-domain routing (CIDR) reduces this problem by
increasing the flexibility of the IPv4 system.
A suffix is used, such as 192.30.250.00/18, which means 18 bits will be
used for the net ID and the last 14 bits will be used for the host ID
IPv6 addressing:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 53
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
IPv6 addressing has been developed to overcome some of the
problems associated with IPv4.
This system uses 128-bit addressing, which allows for much more
complex addressing structures.
An IPv6 address is broken into 16-bit chunks and because of
this, it adopts the hexadecimal notation.
For example:
A8FB:7A88:FFF0:0FFF:3D21:2085:66FB:F0FA
Note how a colon (:) rather than a decimal point (.) is used here. It has been
designed to allow the internet to grow in terms of number of hosts and the
potential amount of data traffic.
IPv6 has benefits over IPv4
has no need for NATs (network address translation)
removes risk of private IP address collisions
has built in authentication
allows for more efficient routing.
Sub-netting
CIDR is actually based on sub-netting and the two are similar in many
ways.
Sub-netting divides a LAN into two or more smaller networks.
This helps reduce network traffic and can also hide the complexity of
the overall network.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 54
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Private IP addresses and public:
IP addresses Private IP addresses are reserved for internal use behind a
router or other NAT device. The following blocks are reserved for private IP
addresses.
Class A 10.0.0.0 to 10.255.255.255 16 million possible addresses
Class B 172.16.0.0 to 172.31.255.255 1 million possible addresses
Class C 192.168.0.0 to 192.168.255.255 65 600 possible addresses
Public IP addresses are the ones allocated by a user’s ISP to identify the
location of their device. Devices using these IP addresses are accessible from
anybody using the internet. Public IP addresses are used by
DNS servers
network routers
directly-controlled computers.
Uniform resource service (URLs):
Protocol is usually http or https Website address is
domain host (www)
domain name (name of website)
domain type (.com, .org, .net, .gov, and so on)
(sometimes) a country code (.uk, .de, .cy, .br, and so on).
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 55
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
Path is the web page (if this is omitted then it is the root directory of the
website)
Filename is the item from the web page
For example: http://www.hoddereducation.co.uk/computerscience
Domain name service (DNS):
The domain name service (DNS) (also known as domain name system) gives
domain names for internet hosts and is a system for finding IP addresses of
a domain name. Domain names eliminate the need for a user to memorise IP
addresses. The DNS process involves converting a host name (such as
www.hoddereducation.co.uk) into an IP address the computer can understand
(such as 107.162.140.19)
Often, DNS servers contain a database of URLs with the matching IP
addresses.
1. The user opens their web browser and types in the URL
(www.hoddereducation.co.uk) and the web browser asks the DNS server
(1) for the IP address of the website.
2. The DNS server can’t find www.hoddereducation.co.uk in its database
or its cache and sends out a request to DNS server (2).
3. DNS server (2) finds the URL and can map it to 107.162.140.19; the IP
address is sent back to DNS server (1) which now puts the IP address
and associated URL into its cache/database.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 56
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
4. This IP address is then sent back to the user’s computer.
5. The computer now sets up a communication with the website server
and the required pages are downloaded. The web browser interprets the
HTML and displays the information on the user’s screen.
Scripting in HTML
A user may wish to develop a web application, which is client-server based,
on their own computer. To do this they would need to:
download the necessary server software
install the application on the chosen/allocated server
use the web browser on their computer to access and interpret the
application web pages
JavaScript
JavaScript (unlike HTML) is a programming language which will run on the
client-side.
Client-side – the script runs on the computer, which is making the
request, processing the web page data that is being sent to the
computer from the server.
Server-side – the script is run on the web server and the results of
processing are then sent to the computer that made the request.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 57
AS Computer Science - 9618 Chapter 2 : Communication Instructor: Nadia Arif
PHP
PHP is another language which can be embedded within HTML.
However, when PHP is used it is processed on the server-side.
Again, the code will be sandwiched inside HTML and will be stored as a
.php file.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 58
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 59
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 60
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
3.1: Computers and their components
3.1.1 Types of memory and storage:
Primary Memory:
Primary memory is the part of computer memory which can be accessed
directly from the CPU. Primary memory allows the processor to access
applications and services temporarily stored in memory locations.
RAM:
RAM refers to the fact that any memory location can be accessed
independent of which memory location was last used. Access time to locate
data is much faster in RAM than in secondary devices.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 61
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
RAM can also be:
o written to or read from, and the data stored can be changed by the user
or by the computer
o used to store data, files, part of an application or part of the operating
system currently in use
o volatile (memory contents are lost on powering off the computer).
There are currently two types of RAM technology, dynamic RAM (DRAM) and
static RAM (SRAM).
DRAM SRAM
consists of a number of uses flip-flops to hold each bit of
transistors and capacitors memory
needs to be constantly
refreshed does not need to be constantly
less expensive to manufacture refreshed
than SRAM has a faster data access time than
has a higher memory capacity DRAM
than SRAM processor memory cache makes use of
main memory is constructed SRAM
from DRAM if accessed at a high frequency, power
consumes more power than usage can exceed that of DRAM
SRAM under reasonable levels of
access, as it needs to be
constantly refreshed
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 62
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
ROM:
o non-volatile (the contents are not lost after powering off the computer)
o permanent memory devices (the contents cannot be changed)
o often used to store data which the computer needs to access when
powering up for the first time for example, the basic input/output
system (BIOS).
PROM and EPROM
o A programmable read-only memory (PROM) is a type of ROM chip
that can be altered once.
o A PROM is made up of a matrix of fuses. Programming a PROM
requires the use of a PROM writer which uses an electric current to
alter specific cells by ‘burning’ fuses in the matrix.
o Due to the method of programming (writing), a PROM can only be
written to once.
o They are often used in mobile phones and in RFID tags.
o An Erasable Programmable Read-Only Memory (EPROM) is different to a
PROM because they use floating gate transistors and capacitors rather
than fuses.
o Ultra violet (UV) light is used to program an EPROM through a quartz
window.
o They are used in applications which are under development, such as the
programming of new games consoles.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 63
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
RAM ROM
temporary memory device permanent memory device
volatile memory non-volatile memory device
can be written to and read from data stored cannot be altered
used to store data, files, programs, sometimes used to store BIOS and
part of OS currently in use other data needed at start up
can be increased in size to
improve operational speed of a
computer
Embedded systems
Embedded systems involve installing microprocessors into devices to enable
operations to be controlled in a more efficient way. Devices such as cookers,
refrigerators and central heating systems can now all be activated by a web-
enabled device (such as a mobile phone or tablet).
Pros of embedded systems Cons of embedded systems
small in size and therefore easy to difficult to upgrade devices to take
fit into devices advantage of new technology
relatively low cost to make troubleshooting faults in the device
usually dedicated to one task, becomes a specialist task
making for simple interfaces and although the interface can appear to
often no requirement of an be simple, in reality it can be more
operating system confusing (changing the time on a
consume very little power cooker clock can require several
steps, for example)
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 64
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
very fast reaction to changing any device that can be accessed over
input (operate in real time) the internet is also open to hackers,
with mass production comes viruses, and so on
reliability due to the difficulty in upgrading and
fault finding, devices are often just
thrown away rather than being
repaired (wasteful)
Secondary storage devices (SSD):
Secondary storage includes storage devices that are not directly accessible
by the CPU.
They are non-volatile devices which allow data to be stored as long as
required by the user.
This type of storage is much larger than primary memory, but data access
time is considerably slower than RAM and ROM
Hard disk drives (HDD) :
Data is stored in a digital format on the magnetic surfaces of the disks (or
platters, as they are frequently called).
The hard disk drive will have a number of platters which can spin at about
7000 times a second.
A number of read-write heads can access all of the surfaces in the disk
drive.
Data is stored on the surface in sectors and tracks.
A sector on a given track will contain a fixed number of bytes.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 65
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Issue: Latency
Explanation: hard disk drives have very slow data access when compared to, for
example, RAM. Many applications require the read-write heads to constantly seek
for the correct blocks of data; this means a large number of head movements.
The effects of latency then become very significant. Latency is defined as the
time it takes for a specific block of data on a data track to rotate around to
the read-write head.
Solution: When a file or data is stored on an HDD, the required number of
sectors needed to store the data will be allocated. However, the sectors allocated
may not be adjacent to each other. Through time, the HDD will undergo
numerous deletions and editing, which leads to sectors becoming increasingly
fragmented, resulting in a gradual deterioration of the HDD performance (in
other words, it takes longer and longer to access data). Defragmentation software
can improve on this situation by ‘tidying up’ the disk sectors.
Solid state drives (SSD)
Latency is an issue in HDDs, Solid state drives (SSD) reduce this issue
considerably.
They have no moving parts and all data is retrieved at the same rate.
They do not rely on magnetic properties.
The most common type of solid state storage devices store data by
controlling the movement of electrons within NAND chips.
The data is stored as 0s and 1s in millions of tiny transistors within the
chip.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 66
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
This effectively produces a non-volatile rewritable memory. However, a
number of solid state storage devices sometimes use electronically erasable
PROM (EEPROM) technology.
The main difference is the use of NOR chips rather than NAND.
Benefits of SSD:
are more reliable (no moving parts to go wrong)
are considerably lighter (which makes them suitable for laptops)
do not have to ‘get up to speed’ before they work properly
have a lower power consumption
run much cooler than HDDs (both these points again make them very
suitable for laptop computers)
are very thin (because they have no moving parts)
access data considerably faster.
Drawback: unknown longevity of the technology.
Optical media: CDs, DVDs and Blu-ray discs
CDs and DVDS are described as optical storage devices. Laser light is used
to read data from, and write data onto, the surface of a disk.
Both CDs and DVDs use a thin layer of metal alloy or light-sensitive
organic dye to store the data.
When a disk spins, the optical head moves to the point where the laser
beam ‘contacts’ the disk surface and follows the spiral track from the
centre outwards.
As with an HDD, a CD/DVD is divided into sectors allowing direct access of
data. Also, as in the case of an HDD, the outer part of the disk runs
faster than the inner part of the disk.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 67
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
The data is stored in ‘pits’ and ‘bumps’ on the spiral track. A red laser is
used to read and write the data.
disk laser wavelength disk construction track pitch (distance
type colour of laser light between tracks)
CD red 780nm single 1.2mm 1.60µm
polycarbonate layer
DVD red 650nm two 0.6mm 0.74µm
polycarbonate layers
Blu-ray blue 405nm single 1.1mm 0.30µm
polycarbonate layer
3.1.2 Input and output devices
Laser printers:
Stage Description of what happens
1 data from the document is sent to a printer driver
2 printer driver ensures that the data is in a format that the chosen
printer can understand
3 check is made by the printer driver to ensure that the chosen printer
is available to print (is it busy? is it off-line? is it out of ink? and so
on)
4 data is sent to the printer and stored in a temporary memory known as
a printer buffer
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 68
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
5 printing drum given a positive charge. As this drum rotates, a laser
beam scans across it removing the positive charge in certain areas,
leaving negatively charged areas which exactly match the text/images
of the page to be printed
6 drum is coated with positively charged toner (powdered ink). Since the
toner is positively charged, it only sticks to the negatively charged parts
of the drum
7 negatively charged sheet of paper is rolled over the drum
8 toner on the drum sticks to the paper to produce an exact copy of the
page sent to the printer
9 to prevent the paper sticking to the drum, the electric charge on the
paper is removed after one rotation of the drum
10 the paper goes through a fuser (a set of heated rollers), where the heat
melts the ink so that it fixes permanently to the paper
11 a discharge lamp removes all the electric charge from the drum so it is
ready to print the next page
Inkjet printers
Stage Description of what happens
1 data from the document is sent to a printer driver
2 printer driver ensures that the data is in a format that the chosen
printer can understand
3 check is made by the printer driver to ensure that the chosen printer
is available to print
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 69
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
4 data is sent to the printer and stored in a temporary memory known
as a printer buffer
5 a sheet of paper is fed into the main body of the printer. A sensor
detects whether paper is available in the paper feed tray – if it is out
of paper (or the paper is jammed), an error message is sent back to
the computer
6 as the sheet of paper is fed through the printer, the print head moves
from side to side across the paper printing the text or image. The four
ink colours are sprayed in their exact amounts to produce the desired
final colour
7 at the end of each full pass of the print head, the paper is advanced
very slightly to allow the next line to be printed. This continues until
the whole page has been printed
8 if there is more data in the printer buffer, then the whole process
from stage 5 is repeated until the buffer is empty
9 once the printer buffer is empty, the printer sends an interrupt to the
processor in the computer, which is a request for more data to be sent
to the printer. The process continues until the whole of the document
has been printed
3D Printers:
3D printers use additive manufacturing this is in contrast to the more
traditional method of subtractive manufacturing
The subtractive method would involve carving the statue out of solid stone
(removing the stone not required) until the final item was produced.
Similarly, CNC machining removes metal to form an object; 3D printing
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 70
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
would produce the same item by building up the object from layers of
powdered metal.
Speakers:
Digitised sound stored in a file on a computer can be converted into analogue
sound as follows:
The digital data is first passed through a digital to analogue converter
(DAC) where it is converted into an electric current.
This is then passed through an amplifier (since the current generated by
the DAC will be small) to create a current large enough to drive a
loudspeaker.
This electric current is then fed to a loudspeaker where it is converted into
sound.
If the sound is stored in a computer file, it must first pass through a digital
to analogue converter (DAC) to convert the digital data into an electric
current which can be used to drive the loudspeaker.
how a loudspeaker can convert electric signals into sound waves:
When an electric current flows through a coil of wire that is wrapped around
an iron core, the core becomes a temporary electromagnet; a permanent
magnet is also positioned very close to this electromagnet.
As the electric current through the coil of wire varies, the induced
magnetic field in the iron core also varies. This causes the iron core to be
attracted towards the permanent magnet and as the current varies this will
cause the iron core to vibrate.
Since the iron core is attached to a cone (made from paper or thin
synthetic material), this causes the cone to vibrate, producing sound.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 71
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
The rate at which the DAC can translate the digital output into analogue
voltages is known as the sampling rate.
Microphones:
Microphones are either built into the computer or are external devices connected
through the USB port or through wireless connectivity. The current produced can
either be stored as sound amplified and sent to a loudspeaker, or sent to a
computer for storage.
When sound is created, it causes the air to vibrate.
When a diaphragm in the microphone picks up the air vibrations, the
diaphragm also begins to vibrate.
A copper coil is wrapped around a permanent magnet and the coil is
connected to the diaphragm using a cone. As the diaphragm vibrates, the
cone moves in and out causing the copper coil to move backwards and
forwards.
This forwards and backwards motion causes the magnetic field around the
permanent magnet to be disturbed, inducing an electric current.
The electric current is then either amplified or sent to a recording device.
The electric current is analogue in nature. The electric current output from
the microphone can also be sent to a computer where a sound card converts
the current into a digital signal which can then be stored in the computer.
Screens:
screens use an LCD, backlit with LEDs or the newer organic light emitting diode
(OLED) technology.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 72
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
OLED: OLEDs use organic materials (made up of carbon compounds) to create
flexible semiconductors. Organic films are sandwiched between two charged
electrodes (one is a metallic cathode and the other a glass anode). When an
electric field is applied to the electrodes, they give off light. This means that no
form of back lighting is required. This allows for very thin screens
Touch screens
Capacitive:
Made up of many layers of glass that act like a capacitor creating electric
fields between the glass plates in layers.
When the top glass layer is touched, the electric current changes and the
coordinates where the screen was touched are determined by an on board
microprocessor.
Benefits Drawbacks
Medium cost technology. Only allows use of bare fingers as
Screen visibility is good even in the form of input; although the
strong sunlight. latest screens permit the use of a
Permits multi-touch capability. special stylus to be used.
Screen is very durable; it takes a
major impact to break the glass.
Resistive:
Makes use of an upper layer of polyester (a form of plastic) and a bottom
layer of glass.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 73
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
When the top polyester layer is touched, the top layer and bottom layer
complete a circuit.
Signals are then sent out, which are interpreted by a microprocessor and
the calculations determine the coordinates of where the screen was touched.
Benefits Drawbacks
Relatively inexpensive Screen visibility is poor in strong
technology. sunlight.
Possible to use bare fingers, Does not permit multi-touch capability.
gloved fingers or stylus to carry Screen durability is only fair; it is
out an input operation. vulnerable to scratches and the screen
wears out through time
Virtual headsets:
Video is sent from a computer to the headset
Two feeds are sent to an LCD/OLED display ; lenses placed between the
eyes and the screen allow for focusing and reshaping of the image/video for
each eye, thus giving a 3D effect and adding to the realism.
Most headsets use 110° field of view which is enough to give a pseudo 360°
surround image/video.
A frame rate of 60 to 120 images per second is used to give a true/realistic
image.
As the user moves their head, a series of sensors and/or LEDs measure this
movement, which allows the image/video on the screen to react to the
user’s head movements.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 74
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Headsets also use binaural sound so that the speaker output appears to
come from behind, from the side or from a distance, giving very realistic 3D
sound
Some headsets also use infrared sensors to monitor eye movement, which
allows the depth of field on the screen to be more realistic; an example of
this is to make objects in the foreground appear fuzzy when the user’s
eyes indicate they are looking into the distance.
Sensors
Sensors are input devices which read or measure physical properties, such as
temperature, pressure etc
Sensor Example applications
temperature control a central heating system
control/monitor a chemical process
control/monitor temperature in a greenhouse
moisture/humidity control/monitor moisture/humidity levels in soil/air in a
greenhouse
monitor dampness levels in an industrial application
light switch street lighting on at night and off during the day
monitor/control light levels in a greenhouse
switch on car headlights when it gets dark
infrared/motion turn on windscreen wipers on a car when it rains
detect an intruder in a burglar alarm system
count people entering or leaving a building
pressure detect intruders in a burglar alarm system
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 75
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
check weight
monitor/control a process where gas pressure is important
acoustic/sound pick up noise levels in a burglar alarm system
detect noise of liquids dripping from a pipe
gas (such as O2 or monitor pollution levels in a river or air
CO2) measure O2 and CO2 levels in a greenhouse
check for CO2 or NO2 leaks in a power station
pH monitor/control acidity/alkalinity levels in soil
monitor pollution in rivers
magnetic field detect changes in in cell phones, CD players, and so on
used in anti-lock braking systems in motor vehicles
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 76
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 77
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Examples of monitoring Examples of control
monitoring a patient in a checking for intruders in a burglar
hospital for vital signs such as alarm system
heart rate, temperature, and so
on
checking the temperature levels monitoring pollution levels in a river
in a car engine
turning street lights on at night controlling the temperature in a central
and turning them off again heating/air conditioning system
during daylight
controlling the traffic lights at a operating anti-lock brakes on a car
road junction when necessary
controlling the environment in a
greenhouse
3.2 Logic Gates and Logic Circuits
3.1 Truth Tables
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 78
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 79
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Truth Table using a circuit
A B C P = A AND B Q = B NOR R = P OR Q X = R XOR
C C
0 0 0 0 1 1 1
0 0 1 0 0 0 1
0 1 0 0 0 0 0
0 1 1 0 0 0 1
1 0 0 0 1 1 1
1 0 1 0 0 0 1
1 1 0 1 0 1 1
1 1 1 1 0 1 0
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 80
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
Truth table using a statement
X = 1 if (A = 1 AND B = NOT 1 OR B = 1 AND C = NOT 1)
A B C P = (A = 1 AND B = Q =( B = 1 AND C = X = P OR
NOT 1) NOT 1) Q
0 0 0 0 0 0
0 0 1 0 0 0
0 1 0 0 1 1
0 1 1 0 0 0
1 0 0 1 0 1
1 0 1 1 0 1
1 1 0 0 1 1
1 1 1 0 0 0
Statement from a Truth Table
A B C X
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 1
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 81
AS Computer Science - 9618 Chapter 3 : Hardware Instructor: Nadia Arif
1 0 1 0
1 1 0 0
1 1 1 1
Step 1: Write down the statement by looking at the truth table
Write the statement only for the rows where the output is 1
Statement for row 5 will be:
A AND NOT B AND NOT C
Statement for row 8 will be:
A AND B AND C
The complete statement will be:
X = 1 if (A=1 AND B = 0 AND C = 0) OR (A=1 AND B=1 AND C=1)
OR
X = 1 if (A AND NOT B AND NOT C) OR (A AND B AND C)
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 82
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 83
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 84
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 85
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 86
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
4.1 Central Processing Unit (CPU) Architecture:
4.1.1 Von Neumann Model
features of the Von Neumann architecture were
a central processing unit (CPU or processor)
a processor able to access the memory directly
computer memories that could store programs as well as data
stored programs made up of instructions that could be executed in
sequential order.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 87
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
4.1.2 Components of the processor (CPU):
The main components of the processor are the:
arithmetic logic unit (ALU)
the control unit (CU)
the system clock
the immediate access store (IAS).
Arithmetic logic unit (ALU):
The ALU allows the required arithmetic or logic operations to be carried out
while a program is being run.
It is possible for a computer to have more than one ALU – one will
perform fixed point operations and the other floating-point operations
The accumulator (ACC) is a temporary register used when carrying out ALU
calculations.
Control unit (CU):
The CU reads an instruction from memory (the address of the location
where the instruction can be found is stored in the program counter (PC).
This instruction is then interpreted.
System clock:
A system clock is used to produce timing signals on the control bus to
ensure this vital synchronisation takes place – without the clock the
computer would simply crash.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 88
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Immediate access store (IAS) :
The IAS holds all the data and programs that the processor (CPU) needs to
access.
The CPU takes data and programs held in backing store and puts them
into the IAS temporarily.
This is done because read/write operations carried out using the IAS are
considerably faster than read/write operations to backing store.
4.1.3 Registers
Register Abbreviation Function/purpose of register
current CIR stores the current instruction being decoded
instruction and executed index register IX used when
register carrying out index addressing operations
(assembly code)
memory address MAR stores the address of the memory location
register currently being read from or written
to memory MDR/MBR stores data which has just been read from
data/ buffer memory or data which is about to be written to
register memory (sometimes referred to as MBR)
program PC stores the address where the next instruction
counter to be read can be found
status register SR contain bits which can be set or cleared
depending on the operation (for example, to
indicate overflow in a calculation)
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 89
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
A status register is used when an instruction requires some form of arithmetic or
logic processing. Each bit is known as a flag. Most systems have the following
four flags.
Carry flag (C) is set to 1 if there is a CARRY following an addition operation.
Negative flag (N) is set to 1 if the result of a calculation yields a NEGATIVE
value.
Overflow flag (V) is set to 1 if an arithmetic operation results in an
OVERFLOW being produced.
Zero flag (Z) is set to 1 if the result of an arithmetic or logic operation is
ZERO.
4.1.4 System buses
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 90
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
There are three common buses used in the Von Neumann architecture known as
address bus, data bus and control bus.
Address bus:
The address bus carries addresses throughout the computer system. Between
the CPU and memory the address bus is unidirectional (in other words, bits
can travel in one direction only).
This prevents addresses being carried back to the CPU, which would be
undesirable.
The width of a bus is important.
The wider the bus, the more memory locations which can be directly
addressed at any given time; for example, a bus of width 16 bits can address
216 (65 536) memory locations, whereas a bus width of 32 bits allows 4
294 967 296 memory locations to be simultaneously addressed.
Data bus:
The data bus is bidirectional (in other words, it allows data to be sent in
both directions along the bus).
This means data can be carried from CPU to memory (and vice versa) as
well as to and from input/output devices.
It is important to point out that data can be an address, an instruction or a
numerical value.
As with the address bus, the width of the data bus is important: the wider
the bus, the larger the word length that can be transported
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 91
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Control bus:
The control bus is also bidirectional. It carries signals from the CU to all the
other computer components. It is usually 8-bits wide since it only carries
control signals.
The clock defines the clock cycle which synchronises all computer
operations.
.By increasing clock speed, the processing speed of the computer is also
increased
Summary:
Increasing bus width (data and address buses) increases the performance and
speed of a computer system
Increasing clock speed usually increases the speed of a computer
a computer’s performance can be changed by altering bus width, clock
speed and use of multi-core CPUs
use of cache memories can also speed up a processor’s performance.
4.1.5 Computer ports
Input and output devices are connected to a computer via ports. The interaction
of the ports with connected input and output is controlled by the control unit.
USB ports
The Universal Serial Bus (USB) is an asynchronous serial data transmission
method.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 92
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
the computer automatically detects that a device is present (this is due to
a small change in the voltage level on the data signal wires in the cable)
the device is automatically recognised, and the appropriate device driver is
loaded up so that computer and device can communicate effectively
if a new device is detected, the computer will look for the device driver
which matches the device. If this is not available, the user is prompted to
download the appropriate software.
Pros of USB system Cons of USB system
devices plugged into the computer the present transmission rate is
are automatically detected and limited to less than 500 megabits
device drivers are automatically per second
loaded up the maximum cable length is
the connectors can only fit one presently about five metres
way, which prevents incorrect the older USB standard may not
connections being made be supported in the near future
this has become the industry
standard, which means that
considerable support is available to
users
several different data transmission
rates are supported
newer USB standards are backward
compatible with older USB standards
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 93
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
High-definition multimedia interface (HDMI):
High-definition multimedia interface (HDMI) ports allow output (both audio and
visual) from a computer to an HDMI-enabled device.
They support high definition signals (enhanced or standard). HDMI was introduced
as a digital replacement for the older Video Graphics Array (VGA) analogue
system.
They use a widescreen format (16:9 aspect ratio).
The screens use a greater number of pixels (typically 1920 × 1080).
The screens have a faster refresh rate (such as 120Hz or 120 frames a
second).
The range of colours is extremely large.
Video Graphics Array (VGA):
VGA supports 640 × 480 pixel resolution on a television or monitor screen. It can
also handle a refresh rate of up to 60Hz (60 frames a second) provided there are
only 16 different colours being used. If the pixel density is reduced to 200 × 320,
then it can support up to 256 colours.
Pros of HDMI Cons of HDMI
the current standard for modern not a very robust connection (easy
televisions and monitors to break connection when simply
allows for a very fast data transfer moving device)
rate limited cable length to retain good
improved security (helps prevent signal
piracy) there are currently five cable/
supports modern digital systems connection standards
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 94
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Pros of VGA Cons of VGA
simpler technology old outdated analogue technology
only one standard available it is easy to bend the pins when
it is easy to split the signal and making connections
connect a number of devices the cables must be of a very high
from one source grade to ensure good undistorted
the connection is very secure signal
4.1.6 Fetch-execute cycle
To execute a set of instructions, the processor first fetches data and instructions
from memory and stores them in suitable registers. Both the address bus and data
bus are used in this process. Once this is done, each instruction needs to be
decoded before being executed.
Fetch:
The next instruction is fetched from the memory address currently stored
in the program counter (PC) and is then stored in the current instruction
register (CIR).
The PC is then incremented (increased by 1) so that the next instruction
can be processed.
This is decoded so that each instruction can be interpreted in the next part
of the cycle.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 95
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Execute :
The processor passes the decoded instruction as a set of control signals to
the appropriate components within the computer system.
This allows each instruction to be carried out in its logical sequence.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 96
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
When registers are involved, it is possible to describe what is happening by using
Register Transfer Notation (RTN). In its simplest form:
MAR ← [PC] contents of PC copied into MAR
PC ← [PC] + 1 PC is incremented by 1
data stored at address shown in MAR is copied into MDR
MDR ← [[MAR]] contents of MDR copied into CIR
CIR ← [MDR]
Double brackets are used in the third line because it is not MAR contents being
copied into MDR but it is the data stored at the address shown in MAR that is
being copied to MDR.
Interrupt Handling:
There are many different reasons for an interrupt to be generated. Some
examples are:
a fatal error in a program
a hardware fault
a need for I/O processing to begin
user interaction
a timer signal.
A special register called the interrupt register is used in the fetch-execute cycle.
While the CPU is in the middle of carrying out this cycle, an interrupt could
occur, which will cause one of the bits in the interrupt register to change its
status.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 97
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
At the next fetch-execute cycle, the interrupt register is checked bit by
bit.
The contents 0000 1000 would indicate an interrupt occurred during a
previous cycle and it still needs servicing. The CPU would now service this
interrupt or ignore it for now, depending on its priority.
Once the interrupt is serviced by the CPU, it stops its current task and
stores the contents of its registers.
Control is now transferred to the interrupt handler (or interrupt service
routine, ISR).
Once the interrupt is fully serviced, the register is reset and the contents
of registers are restored.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 98
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Once the interrupt signal is received, the processor either carries on with what it
was doing or stops to service the device/program that generated the interrupt.
The computer needs to identify the interrupt type and also establish the level of
interrupt priority.
4.2 Assembly Language:
Important Definitions:
Opcode: defines the action associated with the instruction
Operand: defines any data needed by the instruction
Machine code instruction: a binary code with a defined number of bits that
comprises an opcode and, most often, one operand
Assembly language: a low-level language related to machine code where opcodes
are written as mnemonics and there is a character representation for an operand
Assembler: a program used to translate an assembly language program into
machine code
Directive: an instruction to the assembler program
4.2.2 Stages of assembly
Before a program written in assembly language (source code) can be
executed, it needs to be translated into machine code.
The translation is performed by a program called an assembler.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 99
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
An assembler translates each assembly language instruction into a machine
code instruction.
An assembler also checks the syntax of the assembly language program to
ensure that only opcodes from the appropriate machine code instruction set
are used.
This speeds up the development time, as some errors are identified during
translation before the program is executed.
There are two types of assembler: single pass assemblers and two pass assemblers.
Pass 1
Read the assembly language program one line at a time.
Ignore anything not required, such as comments.
Allocate a memory address for the line of code.
Check the opcode is in the instruction set.
Add any new labels to the symbol table with the address, if known.
Place address of labelled instruction in the symbol table.
Pass 2
Read the assembly language program one line at a time.
Generate object code, including opcode and operand, from the symbol table
generated in Pass 1.
Save or execute the program.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 100
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
4.2.3 Assembly language instructions
Data movement instructions:
These instructions allow data stored at one location to be copied into the
accumulator. This data can then be stored at another location, used in a
calculation, used for a comparison or output.
Input and output of data instructions:
These instructions allow data to be read from the keyboard or output to the
screen.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 101
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Arithmetic operation instructions:
These instructions perform simple calculations on data stored in the accumulator
and store the answer in the accumulator, overwriting the original data.
Unconditional and conditional instructions:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 102
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Compare instructions:
4.2.4 Addressing Modes
Addressing mode Use of the operand
Immediate The operand is the value to be used in the instruction;
SUB #48 is an example.
Direct The operand is the address which holds the value to be
used in the instruction; ADD TOTAL is an example.
Indirect The operand is an address that holds the address which has
the value to be used in the instruction.
Indexed The operand is an address to which must be added the
value currently in the index register (IX) to get the address
which holds the value to be used in the instruction.
Relative addressing the memory address used is the current memory address
added to the operand. For example, JMR #5 would transfer
control to the instruction 5 locations after the current
instruction.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 103
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Symbolic addressing only used in assembly language programming. A label is
used instead of a value. For example, if the memory
location with address labelled MyStore contained the value
20, the assembly language instruction LDD MyStore would
store 20 in the accumulator.
4.3 Bit Manipulation:
4.3.1 Binary shifts
A shift involves moving the bits stored in a register a given number of places
within the register.
There are several different types of shift.
Logical shift – bits shifted out of the register are replaced with zeros.
For example, an 8-bit register containing the binary value 10101111 shifted left
logically three places would become 01111000.
Arithmetic shift – the sign of the number is preserved.
For example, an 8-bit register containing the binary value 10101111 shifted right
arithmetically three places would become 11110101. Arithmetic shifts can be used for
multiplication or division by powers of two.
Cyclic shift – no bits are lost during a shift. Bits shifted out of one end of the
register are introduced at the other end of the register.
For example, an 8-bit register containing the binary value 10101111 shifted left
cyclically three places would become 01111101.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 104
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
4.3.2 Bit manipulation used in monitoring and control
AND is used to check if the bit has been set.
OR is used to set the bit.
XOR is used to clear a bit that has been set
Binary numbers can be multiplied or divided by shifting
Left shift (LSL #n)
Bits are shifted to the left to multiply
E.g. to multiply by four, all digits shift two places to left
Right shift (LSR #n)
Bits are shifted to the right to divide
E.g. to divide by four, all digits shift two places to right
Logical shift: zeros replace the vacated bit position
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 105
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Arithmetic shift: Used to carry out multiplication and division of signed
integers represented by bits in the accumulator by ensuring that the sign-
bit (usually the MSB) is the same after the shift.
Cyclic shift: the bit that is removed from one end by the shift is added to
the other end.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 106
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Bit Masking:
Each bit can represent an individual flag.
by altering the bits, flags could be operated upon.
Bit manipulation operations:
Masking: an operation that defines which bits you want to keep
and which bits you want to clear.
Masking to 1: The OR operation is used with a 1.
Masking to 0: The AND operation is used with a 0
Matching: an operation that allows the accumulator to compare
the value it contains to the given value in order to change the
state of the status register.
Practical applications of Bit Masking:
Setting an individual bit position:
Mask the content of the register with a mask pattern
which has 0 in the ‘mask out’ positions and 1 in the
‘retain’ positions.
Set the result with the match pattern by using the AND
command with a direct address.
Testing one or more bits:
Mask the content of the register with a mask pattern
which has 0 in the ‘mask out’ positions and 1 in the
‘retain’ positions.
Compare the result with the match pattern by using the
CMP command or by “Checking the pattern”.
Checking the pattern
Use AND operation to mask bits and obtain resultant.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 107
AS Computer Science - 9618 Chapter 4 : Processor Fundamentals Instructor: Nadia Arif
Now subtract matching bit pattern from resultant.
The final ‘non-zero’ result confirms the patterns are not
the same else vice versa.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 108
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 109
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
5.1 Operating System
5.1.1 The need for an operating system
An operating system provides both the environment in which applications
can be run, and a useable interface between humans and computer
The human–computer interface (HCI) is usually achieved through a
graphical user interface (GUI), although it is possible to use a command line
interface (CLI) if the user wishes to directly communicate with the
computer.
Command Line Interface (CLI)
A CLI requires a user to type instructions to choose options from menus,
open software, and so on. There are often a number of commands that
need to be typed; for example, to save or load a file
Advantages:
direct communication with the computer
not restricted to a number of pre-determined options.
Graphical User Interface (GUI):
A GUI allows the user to interact with a computer (or MP3 player, gaming
device, mobile phone, and so on) using pictures or symbols (icons).
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 110
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
5.1.2 Operating system tasks
Memory management
This can be broken down into three parts: memory optimisation, memory
organisation and memory protection.
Memory optimisation
a. Memory optimisation is used to determine how computer memory
is allocated and deallocated when a number of applications are
running simultaneously.
b. It also determines where they are stored in memory.
c. It must, therefore, keep track of all allocated memory and free
memory available for use by applications.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 111
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
d. To maintain optimisation of memory, it will also swap data to
and from the HDD or SSD.
Memory organisation
Memory organisation determines how much memory is allocated to an
application, and how the memory can be split up in the most
appropriate or efficient manner. This can be done with the use of
a. a single (contiguous) allocation, where all of the memory is made
available to a single application. This is used by MS-DOS and by
embedded systems
b. partitioned allocation, where the memory is split up into contiguous
partitions (or blocks) and memory management then allocates a
partition (which can vary in size) to an application
c. paged memory, which is similar to partitioned allocation, but each
partition is of a fixed size. This is used by virtual memory systems
d. segmented memory, which is different because memory blocks are
not contiguous – each segment of memory will be a logical
grouping of data
Memory protection
Memory protection ensures that two competing applications cannot
use the same memory locations at the same time. If this was not
done, data could be lost, applications could produce incorrect results,
there could be security issues, or the computer may crash.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 112
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
Security management:
Security management is another part of a typical operating system. The
function of security management is to ensure the integrity, confidentiality
and availability of data.
This can be achieved by
carrying out operating system updates as and when they become
available
ensuring that antivirus software (and other security software) is
always upto-date
communicating with, for example, a firewall to check all traffic to and
from the computer
making use of privileges to prevent users entering ‘private areas’ on a
computer which permits multi-user activity (this is done by setting up
user accounts and making use of passwords and user IDs). This helps
to ensure the privacy of data
maintaining access rights for all users
offering the ability for the recovery of data (and system restore)
when it has been lost or corrupted
helping to prevent illegal intrusion to the computer system (also
ensuring the privacy of data)
Process management
A process is a program which is being run on a computer. Process
management involves the allocation of resources and permits the sharing
and exchange of data, thus allowing all processes to be fully synchronised
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 113
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
Hardware management
Hardware management involves all input and output peripheral devices. The
functions of hardware management include
communicating with all input and output devices using device drivers
translating data from a file (defined by the operating system) into a
format that the input/output device can understand using device
drivers
ensuring each hardware resource has a priority so that it can be used
and released as required. The management of input/output devices is
essentially the control and management of queues and buffers. For
example, when printing out a document, the printer management
locates and loads the printer driver into memory
sends data to a printer buffer ready for printing
sends data to a printer queue (if the printer is busy or the print job
has a low priority) before sending to the printer buffer
sends various control commands to the printer throughout the
printing process
receives and handles error messages and interrupts from the printer
File management
The main tasks of file management include
defining the file naming conventions which can be used
(filename.docx, where the extension can be .bat, .htm, .dbf, .txt, .xls,
and so on)
performing specific tasks, such as create, open, close, delete, rename,
copy, move
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 114
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
maintaining the directory structures
ensuring access control mechanisms are maintained, such as access
rights to files, password protection, making files available for editing,
locking files, and so on
specifying the logical file storage format (such as FAT or NTFS if
Windows is being used), depending on which type of disk formatter is
used
ensuring memory allocation for a file by reading it from the
HDD/SSD and loading it into memory
5.1.3 Utility software
Hard disk formatter
A disk formatter will organise storage space by assigning it to
data blocks (partitions).
A disk surface may have a number of partitions
partitions are contiguous blocks of data
When carrying out full formatting using NTFS, all disk sectors are filled
with zeros; these zeros are read back, thus testing the sector, but any
data already stored there will be lost. So, it is important to remember that
reformatting an HDD which has already been used will result in loss of data
during the formatting procedure.
Disk formatters also have checking tools, which are non-destructive tests
that can be carried out on each sector. If any bad sector errors are
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 115
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
discovered, the sectors will be flagged as ‘bad’ and the file tracking records
will be reorganised – this is done by replacing the bad sectors with new
unused sectors, effectively repairing the faulty disk
Hard bad sectors (difficult to repair) Soft bad sectors
caused by manufacturing errors damage to disk surface caused by
allowing the read write head to touch
the disk surface (for example, by
moving HDD without first parking
the read-write head)
system crash which could lead to sudden loss of power leading to data
damage to the disk surface(s) corruption in some of the sectors
effect of static electricity leading to
corruption of data in some of the
sectors on the hard disk surfaces
Virus checkers
Running antivirus software in the background on a computer will constantly
check for virus attacks
Features of anti virus software are:
check software or files before they are run or loaded on a computer
compare possible viruses against a database of known viruses
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 116
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
carry out heuristic checking – this is the checking of software for
types of behaviour that could indicate a possible virus, which is useful
if software is infected by a virus not yet on the database
put files or programs which may be infected into quarantine, to –
automatically delete the virus, or – allow the user to decide whether
to delete the file
Defragmentation software:
Rearranges blocks of individual files (on the HDD) so they are
contiguous // moves the free space together
Accessing each file is faster because there is no need to search for
the next fragment / block of the file so less head movement is
needed
A disk defragmenter will rearrange the blocks of data to store files in
contiguous sectors wherever possible; however, if the disk drive is almost
full, defragmentation may not work.
Back-up software
allow a schedule for backing up files to be made
only carry out a back-up procedure if there have been any changes
made to a file.
Windows environment offers the following facilities using the back-up
utility:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 117
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
The ability to restore data, files or the computer from the back-up
(useful if there has been a problem and files have been lost and need
to be recovered).
The ability to create a restore point (this restores a computer to its
state at some point in the past; this can be very useful if a very
important file has been deleted and cannot be recovered by any of
the other utilities).
Options of where to save back-up files; this can be set up from the
utility to ensure files are automatically backed up to a chosen device.
5.1.4 Program libraries
Program libraries are used
when software is under development and the programmer can utilise
pre-written subroutines in their own programs, thus saving
considerable development time
to help a software developer who wishes to use dynamic link library
(DLL) subroutines in their own program, so these subroutines must be
available at run time.
Dynamic Link Libraries:
In dynamic libraries, software being developed is not linked to the
library routines until actual run time (these are known as dynamic
link library files or DLL).
These library routines would be stand-alone files only being accessed
as required by the new program – the routines will be available to
several applications at the same time.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 118
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
Pros of using DLL files Cons of using DLL files
the executable code of the main the executable code is not self-
program is much smaller since DLL contained, therefore all DLL files need
files are only loaded into memory to be available at run time otherwise
at run time error messages (such as missing .dll
error) will be generated and the
software may even crash
it is possible to make changes to any DLL linking software in the main
DLL files independently of the program needs to be available at run
main program, consequently if any time to allow links with DLL files to
changes are made to the DLL files be made
it will not be necessary to
recompile the main program
DLL files can be made available to if any of the DLL files have been
a number of applications at the changed (either intentionally or
same time through corruption) this could lead to
the main program giving unexpected
results or even crashing
all of the above save memory and malicious changes to DLL files could
also save execution time be due to the result of malware, thus
presenting a risk to the main program
following the linking process
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 119
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
5.2 Language Translators:
5.2.1 Translation and execution of programs
The systems software used to translate a source program written in any
language other than machine code are translators
Assemblers
Programs written in assembly language are translated into machine
code by an assembler program.
Assemblers either store the program directly in main memory,
ready for execution, as it is translated, or they store the translated
program on a storage medium to be used later.
If stored for later use, then a loader program is also needed to load
the stored translated program into main memory before it can be
executed
Compilers and interpreters
Programs written in a high-level language can be either
translated into machine code by a compiler program, or directly
executed line-by-line using an interpreter program.
Compilers usually store the translated program (object program)
on a storage medium ready to be executed later.
A loader program is needed to load the stored translated program
into main memory before it can be executed.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 120
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
With an interpreter, no translated program is generated in main
memory or stored for later use.
Every line in a program is interpreted then executed each time
the program is run.
Assembler Compiler Interpreter
Source program assembly high-level high-level language
written in language language
Machine yes no no
dependent
Object program yes, stored on yes, stored on no, instructions are
generated disk or in main disk or in main executed under the
memory memory control of the
interpreter
Each line of one machine code many machine many machine code
the source instruction, one code instructions, instructions,
program to one translation instruction instruction
generates explosion explosion
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 121
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
5.2.2 Pros and cons of compiling or interpreting a program
Compiler Interpreter
The end user only needs the The end user will need to purchase a
executable code, therefore, the end compiler or an interpreter to translate
user benefits as there is no need to the source code before it is used.
purchase a compiler to translate
the program before it is used.
The developer keeps hold of the The developer relinquishes control of
source code, so it cannot be altered the source code, making it more
or extended by the end user, difficult to charge for upgrades and
therefore, the developer benefits as alterations. Since end users can view
they can charge for upgrades and the source code, they could
alterations. potentially use the developer’s
intellectual property.
Compiled programs take a shorter An interpreted program can take
time to execute as translation has longer to execute than the same
already been completed and the program when compiled, since each
machine code generated may have line of the source code needs to be
been optimised by the compiler. translated before it is executed every
time the program is run.
Compiled programs have no syntax Interpreted programs may still contain
or semantic errors. syntax or semantic errors if any part
of the program has not been fully
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 122
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
tested, these errors will need to be
debugged.
The source program can be Interpreted programs cannot be
translated on one type of computer interpreted on one type of computer
then executed on another type of and run on another type of
computer. computer.
A compiler finds all errors in a It is easier to develop and debug a
program. One error detected can program using an interpreter as errors
mean that the compiler finds other can be corrected on each line and
dependent errors later on in the the program restarted from that
program that will not be errors place, enabling the programmer to
when the first error is corrected. easily learn from any errors.
Therefore, the number of errors
found may be more than the actual
number of errors.
Untested programs with errors may Untested programs should not be able
cause the computer to crash. to cause the computer to crash.
The developer needs to write special Partial results can be viewed during
routines in order to view partial development, enabling the developer
results during development, making to make informed decisions about a
it more difficult to assess the section of code, for example whether
quality of particular sections of to continue, modify, or scrap and
code. start again.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 123
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
End users do not have access to If an interpreted program is
the source code and the run-time purchased, end users have all the
libraries, meaning they are unable source code and the run-time
to make modifications and are libraries, enabling the program to be
reliant on the developer for updates modified as required without further
and alterations. purchase.
5.2.4 Integrated development environment (IDE)
IDEs usually have
a source code editor
a compiler, an interpreter, or both
a run-time environment with a debugger
an auto-documenter.
Source code editor
A source code editor allows a program to be written and edited
without the need to use a separate text editor.
Most source code editors colour code the words in the program
and layout the program in a meaningful way (prettyprinting)
Dynamic syntax checking finds possible syntax errors as the
program code is being typed in to the source code editor and
alerts the programmer at the time, before the source code is
interpreted.
Logic errors can only be found when the program is run.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 124
AS Computer Science - 9618 Chapter 5 : System Software Instructor: Nadia Arif
Compilers and interpreters
Most IDEs usually provide a compiler and/or an interpreter to run the
program. The interpreter is often used for developing the program and the
compiler to produce the final version of the object code.
A run-time environment with a debugger
A debugger is a program that runs the program under
development and aids the process of debugging.
It allows the programmer to single step through the program a
line at a time (single stepping) or to set a breakpoint to stop
the execution of the program at a certain point in the source
code.
A report window then shows the contents of the variables and
expressions evaluated at that point in the program
Auto-documenter
Most IDEs usually provide an auto-documenter to explain the function and
purpose of programming code.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 125
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 126
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
6.1 Data Security:
6.1.1 Data Privacy:
Data privacy is achieved by the following data protection laws:
Data must be fairly and lawfully processed.
Data can only be processed for the stated purpose.
Data must be adequate, relevant and not excessive.
Data must be accurate.
Data must not be kept longer than necessary.
Data must be processed in accordance with the data subject’s
rights.
Data must be kept secure.
Data must not be transferred to another country unless that
country also has adequate protection
6.1.2 Preventing data loss and restricting data access
Data security refers to the methods used to prevent unauthorised access
to data, as well as to the data recovery methods if it is lost.
Create user accounts to control access rights
Use of strong passwords
Use of firewall
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 127
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
Digital signatures
Anti Virus Software
Anti Spyware software
Encryption
Biometrics (Fingerprint scan, Retina Scan)
6.1.3 Risks to the security of stored data
Hacking:
Malicious Hacking: illegal access to a computer system without
the user’s permission or knowledge.
Ethical Hacking: authorised by companies to check their
security measures and how robust their computer systems are
to resist hacking attacks.
Malware:
Viruses: Programs or program code that can replicate and/or
copy themselves with the intention of deleting or corrupting
files or causing the computer to malfunction.
Worms: A type of stand-alone virus that can replicate
themselves with the intention of spreading to other
computers; they often use networks to search out computers
with weak security.
Trojan Horses: Malicious programs often disguised as legitimate
software. They replace all or part of the legitimate software
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 128
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
with the intent of carrying out some harm to the user’s
computer system.
Spyware: Software that gathers information by monitoring, for
example, key presses on the user’s keyboard. The information
is then sent back to the person who sent the software –
sometimes referred to as key logging software.
Bots: Not always harmful and can be used, for example, to
search automatically for an item on the internet. However,
they can cause harm by taking control over a computer
system and launching attacks.
Logic Bombs: Code embedded in a program on a computer.
When certain conditions are met (such as a specific date) they
are activated to carry out tasks such as deleting files or
sending data to a hacker.
Phishing: Phishing is when someone sends legitimate-looking emails
to users. They may contain links or attachments which, when
clicked, take the user to a fake website, or they may trick the
user into responding with personal data such as bank account
details or credit card numbers.
Pharming: Pharming is malicious code installed on a user’s computer
or on a web server. The code re-directs the user to a fake website
without their knowledge (the user does not have to take any
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 129
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
action, unlike phishing). The creator of the malicious code can gain
personal data such as bank details from users
Protection against pharming: It is possible to mitigate the risk
of pharming by
using antivirus software, which can detect unauthorised
alterations to a website address and warn the user
using modern web browsers that alert users to pharming
and phishing attacks
checking the spelling of websites
checking for https and/or the green padlock symbol in
the address bar.
6.1.4 Data Recovery:
accidental loss of data use back-ups in case the data is lost or
(for example, accidentalcorrupted through an accidental operation
deletion of a file) save data on a regular basis
use passwords and user IDs to restrict
access to authorised users only
hardware fault (such as use back-ups in case data is lost or
head crash on the HDD) corrupted through the hardware fault
use uninterruptable power supply (USP) in
case power loss causes hardware malfunction
save data on a regular basis
use parallel systems as back-up hardware
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 130
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
software fault (for use back-ups in case the data is lost or
example, incompatible corrupted through the software fault
software installed on the save data on a regular basis in case the
system) software suddenly ‘freezes’ or ‘crashes’ while
the user is working on it
incorrect computer use back-ups in case data is lost or
operation (for example, corrupted through wrong operation
incorrect shutdown or correct training procedures so users are
procedure for removing aware of the correct operation of hardware
memory stick)
6.2 Data Integrity:
Data stored on a computer should always be accurate, consistent and up to
date. Two of the methods used to ensure data integrity are validation and
verification.
The accuracy (integrity) of data can be compromised
during the data entry and data transmission stages
by malicious attacks on the data, for example caused by malware and
hacking
by accidental data loss caused through hardware issues.
6.2.1 Validation:
Validation is a method of checking if entered data is reasonable , but it cannot
check if data is correct or accurate. For example, if somebody accidentally
enters their age as 62 instead of 26, it is reasonable but not accurate or
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 131
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
correct. Validation is carried out by computer software; the most common types
are shown in the table below:
Validation Description Example of data Example of
test failing validation test data passing
validation test
type checks whether typing sk.34 in a field typing 34.50 in
non-numeric data which should contain a field which
has been input the price of an item should contain
into a numeric- the price of an
only field item
range checks whether typing in somebody’s typing in
data entered is age as −120 somebody’s age
between a lower as 48
and an upper limit
format checks whether typing in the date as typing in the
data has been 12-12-20 where the date as
entered in the format is dd/mm/yyyy 12/12/2020
agreed format where the
format is
dd/mm/yyyy
length checks whether typing in a telephone typing in a
data has the number as 012 345 telephone
required number of 678 when it should number as 012
contain 11 digits 345 678 90
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 132
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
characters or when it should
numbers contain 11 digits
presence checks to make please enter passport please enter
sure a field is not number:………… passport
left empty when it …… number: AB
should contain 1234567 CD
data
existence checks if data in data look up for car data look up
a file or a file registration plate A123 for a file called
name actually BCD which does not books_in_stock
exists exist which exists in
a database
limit Checks only one typing in age as −25 typing in
check of the limits (such where the data entered somebody’s age
as the upper limit should not be negative as 72 where
OR the lower limit) the upper limit
is 140
consistency checks whether typing in Mr in the typing in Ms in
check data in two or title field and then the title field
more fields match choosing female in the and then
up correctly gender field choosing female
in the gender
field
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 133
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
uniqueness checks that each choosing the user name choosing the
check entered value is MAXIMUS222 in a website name
unique social networking site Aristooo.com
but the user name which is not
already exists already used
6.2.2 Verification:
Verification is a way of preventing errors when data is entered manually (using
a keyboard, for example) or when data is transferred from one computer to
another.
Verification during data entry When data is manually entered into a
computer it needs to undergo verification to ensure there are no errors.
There are three ways of doing this:
double entry
Data is entered twice, using two different people, and then
compared
visual check
Entered data is compared with the original document
check digits
The check digit is an additional digit added to a number
They are often used in barcodes, ISBNs and VINs
The check digit can be used to ensure the barcode, for
example, has been correctly inputted.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 134
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
Verification during data transfer When data is transferred electronically
from one device to another, there is always the possibility of data
corruption or even data loss. A number of ways exist to minimise this risk.
Checksums
A checksum is a method to check if data has been changed
or corrupted following data transmission. Data is sent in
blocks and an additional value, the checksum, is sent at the
end of the block of data.
Parity checks
A parity check is another method to check whether data
has been changed or corrupted following transmission from
one device or medium to another.
Automatic Repeat ReQuest(ARQ)
ARQ uses acknowledgement (a message sent to the receiver
indicating that data has been received correctly) and timeout
(the time interval allowed to elapse before an
acknowledgement is received).
When the receiving device detects an error following data
transmission, it asks for the data packet to be re-sent.
If no error is detected, a positive acknowledgement is sent to
the sender.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 135
AS Computer Science - 9618 Chapter 6 : Security, Privacy & Data Integrity Instructor: Nadia Arif
The sending device will re-send the data package if – it
receives a request to re-send the data, or – a timeout has
occurred.
The whole process is continuous until the data packet received
is correct or until the ARQ time limit (timeout) is reached.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 136
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
7.1 - Legal, Moral, Ethical and Cultural Implications
The following definitions are important when considering ethical behaviour:
Legal covers the law, whether or not an action is punishable by law.
Morality concerns questions of right and wrong, and is more often
thought of in relation to personal or individual choices.
Ethics also concerns questions of right and wrong, but is more often
used in a professional context.
Culture refers to the attitudes, values and practices shared by a society
or group of people.
7.1.1 Computer ethics:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 137
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
Computer ethics is a set of principles set out to regulate the use of
computers. Three factors are considered:
Intellectual property rights, for example, copying of software without the
permission of the owner.
Privacy issues, for example, hacking or any illegal access to another
person’s personal data.
Effect of computers on society, for example, job losses, social impacts,
and so on.
Plagiarism Internet use has led to an increase in plagiarism – this is
when a person takes another person’s idea or work and claims it was
their own.
7.1.2: Professional Ethical Bodies:
The British Computer Society (BCS)
The BCS Code of Conduct covers four main areas:
The Public Interest
Professional Competence and Integrity
Duty to Relevant Authority
Duty to the Profession
The Institute of Electrical and Electronics Engineers (IEEE)
raising awareness of ethical issues
promoting ethical behaviour among professionals working in the
electronics industry
ensuring engineers and scientists respect the need for ethical behaviour.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 138
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
IEEE Code of Ethics: (Imp: Memorize at least 3 points)
1. to hold paramount the safety, health, and welfare of the public, to
strive to comply with ethical design and sustainable development
practices, and to disclose promptly factors that might endanger the
public or the environment;
2. to avoid real or perceived conflicts of interest whenever possible, and to
disclose them to affected parties when they do exist;
3. to be honest and realistic in stating claims or estimates based on
available data;
4. to reject bribery in all its forms;
5. to improve the understanding by individuals and society of the
capabilities and societal implications of conventional and emerging
technologies, including intelligent systems;
6. to maintain and improve our technical competence and to undertake
technological tasks for others only if qualified by training or experience,
or after full disclosure of pertinent limitations;
7. to seek, accept, and offer honest criticism of technical work, to
acknowledge and correct errors, and to credit properly the contributions
of others;
8. to treat fairly all persons and to not engage in acts of discrimination
based on race, religion, gender, disability, age, national origin, sexual
orientation, gender identity, or gender expression;
9. to avoid injuring others, their property, reputation, or employment by
false or malicious action;
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 139
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
10. to assist colleagues and co-workers in their professional development
and to support them in following this code of ethics
Software Engineering Code of Ethics:(Imp: Memorize at least 3 points)
1. PUBLIC – Software engineers shall act consistently with the public
interest
2. CLIENT AND EMPLOYER – Software engineers shall act in a manner
that is in the best interests of their client and employer consistent with
the public interest
3. PRODUCT – Software engineers shall ensure that their products and
related modifications meet the highest professional standards possible.
4. JUDGEMENT – Software engineers shall maintain integrity and
independence in their professional judgement.
5. MANAGEMENT – Software engineering managers and leaders shall
subscribe to and promote an ethical approach to the management of
software development and maintenance.
6. PROFESSION – Software engineers shall advance the integrity and
reputation of the profession consistent with the public interest.
7. COLLEAGUES – Software engineers shall be fair to and supportive of
their colleagues.
8. SELF – Software engineers shall participate in life-long learning
regarding the practice of their profession and shall promote an ethical
approach to the practice of the profession.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 140
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
7.2 Copyright Issues:
7.2.1 Software copyright and privacy:
Software is protected by copyright laws in much the same way as music CDs,
videos and articles from magazines and books are protected. When software is
purchased, there are certain rules that must be obeyed:
It is illegal to make a software copy and sell it or give it away.
Software cannot be used on a network or used on multiple computers
without a multi-use licence.
It is illegal to use coding from copyrighted software in your own software
– and then pass this software on or sell it as your own – without the
permission of the copyright holder.
It is illegal to rent out a software package without permission to do so.
It is illegal to use the name of copyrighted software on other software
without agreement to do so.
7.2.2 Software Licensing:
Commercial software
Commercial software is available to customers for a fee, providing a
licence for one genuine copy to be used on a single device, or a multi-
use licence for multiple users.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 141
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
Free software and the Open Source Initiative
The Free Software Foundation and the Open Source Initiative are non-
profit organisations that promote the benefits of giving users the
freedom to run, copy, change and adapt software.
Users are allowed to follow the four freedoms:
Run the software for any legal purpose they wish.
Study the program source code and modify it where necessary to meet
their needs.
Redistribute copies of the software to friends and family.
Distribute code modified by the user to friends and family.
Users cannot
add source code from another piece of software unless this is also
described as free software or open source software
use the source code to produce software which copies existing software
which is subject to copyright laws
adapt the source code in such a way that it infringes copyright laws
protecting other software
use the source code to produce software which is deemed offensive by
third parties.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 142
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
Open Source Initiative focuses on the practical consequences offered by
the four freedoms; the aims are to provide effective collaboration on
software development by the users
a. Free Redistribution
b. Source Code
c. Derived Works
d. No Discrimination Against Fields of Endeavor
e. Distribution of License
f. License Must Not Be Specific to a Product
g. License Must Be Technology-Neutral
Freeware:
Freeware is software a user can download from the internet free of
charge. Once it has been downloaded, there are no fees associated with
using the software (examples include: Adobe Reader, Skype and some
media players). Unlike free software, freeware is subject to copyright
laws and users are often requested to tick a box to say they understand
and agree to the terms and conditions governing the software. This
means that a user is not allowed to study or modify the source code in
any way.
Shareware:
Shareware allows users to try out some software free of charge for a
trial period. At the end of the trial period, the author of the software
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 143
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
will request that you pay a fee if you wish to continue using it. Once
the fee is paid, a user is registered with the originator of the software
and free updates and help are then provided. Often, the trial version of
the software is missing some of the features found in the full version,
and these do not become available until the fee is paid. This type of
software is protected by copyright laws and users must not use the
source code in any of their own software without permission.
7.3 Artificial Intelligence
7.3.1 What is AI?
Artificial intelligence (AI) is a machine or application which carries out a
task that requires some degree of intelligence when carried out by a
human being. These tasks could include
the use of a language
carrying out a mathematical calculation or function
recognising a person’s face
the ability to operate machinery, such as a car, an aeroplane or a train
analysing data to predict the outcome of a future event, such as
weather forecasting
Three laws of robotics:
A robot may not injure a human through action or inaction.
A robot must obey orders given by humans without question.
A robot must protect itself unless it conflicts with the two laws above.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 144
AS Computer Science - 9618 Chapter 7 : Ethics & Ownership Instructor: Nadia Arif
7.3.2 The impacts of AI on society, the economy and the environment
Transport:
Some taxi companies are already looking at the introduction of
autonomous (driverless) cars. A customer can call up the taxi using
an app on their mobile phone, which also automatically handles the
payment. Information about the taxi (such as its location and
estimated arrival time) would be sent to the mobile phone until the
driverless taxi arrives at the exact pick-up point. There would not be
any people anywhere in the chain, with AI systems taking total
control. Some car manufacturers are on the brink of actually
supplying autonomous vehicles (cars, buses and trucks). This would be
much more efficient but would put many drivers out of a job.
Criminal justice system:
Advances in facial recognition systems is making fingerprinting in
forensic science almost obsolete. AI is also being used to automate
legal work
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 145
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 146
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 147
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
8.1 Database Concepts:
8.1.1 Limitations of File Based Approach
A file-based approach is limited because
storage space is wasted when data items are duplicated by the
separate applications and some data is redundant
data can be altered by one application and not by another; it then
becomes inconsistent
enquiries available can depend on the structure of the data and the
software used so the data is not independent.
8.1.2 The advantages of a relational database over a file-based approach
A database approach is beneficial because
storage space is not wasted as data items are only stored once,
meaning little or no redundant data
data altered in one application is available in another application, so
the data is consistent
enquiries available are not dependent on the structure of the data
and the software used, so the data is independent.
8.1.3 Relational database model terminology
A table is a group of similar data, in a database, with rows for each
instance of an entity and columns for each attribute.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 148
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
A record is a row in a table in a database.
A field is a column in a table in a database.
Tuple – one instance of an entity, which is represented by a row in a
table
Entity – anything that can have data stored about it, for example, a
person, place, event, thing.
Indexing: creating a secondary key on an attribute to provide fast access
when searching on that attribute; indexing data must be updated when
table data changes
There are different types of keys.
A candidate key is an attribute or smallest set of attributes in a
table where no tuple has the same value.
A primary key is a unique identifier for a table, it is a special case
of a candidate key.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 149
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
A secondary key is a candidate key that is an alternative to the
primary key.
A foreign key is a set of attributes in one table that refer to the
primary key in another table.
Relationships: A relationship is formed when one table in a database has a
foreign key that refers to a primary key in another table in the database.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 150
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
Relationships can take several forms
one-to-one, 1:1
one-to-many, 1:m
many-to-one, m:1
many-to-many, m:m
8.1.4 The normalisation process:
First normal form (1NF) – entities do not contain repeated groups of
attributes.
Second normal form (2NF) – entities are in 1NF and any non-key
attributes depend upon the primary key. There are no partial
dependencies.
Third normal form (3NF) – entities are in 2NF and all non-key attributes
are independent. The table contains no non-key dependencies.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 151
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
First Normal Form (1NF)
Second Normal Form (2NF)
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 152
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
Third Normal Form (3NF):
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 153
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 154
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
8.2 Database Management System (DBMS)
8.2.1 How a DBMS addresses the limitations of a file-based approach
Data redundancy issue:
This is solved by storing data in separate linked tables, which reduces the
duplication of data as most items of data are only stored once.
Data inconsistency issue:
This is also solved by storing most items of data only once, allowing
updated items to be seen by all applications. As data is not inconsistent,
the integrity of the data stored is improved.
Data dependency issue:
Data is independent of the applications using the database, so changes
made to the structure of the data will be managed by the DBMS and
have little or no effect on the applications using the database. Any fields
or tables added to or removed from the database will not affect the
applications that do not use those fields/tables, as each application only
has access to the fields/tables it requires.
The DBMS approach:
Security measures taken by a DBMS can include
using usernames and passwords to prevent unauthorised access to the
database
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 155
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
using access rights to manage the actions authorised users can take,
for example, users could read/write/delete, or read only, or append
only
using access rights to manage the parts of the database they have
access to, for example, the provisions of different views of the data
for different users to allow only certain users access to some tables
automatic creation and scheduling of regular back-ups
encryption of the data stored » automatic creation of an audit trail
or activity log to record the actions taken by users of the database.
8.2.2 The use and purpose of DBMS software tools
Developer interface
The developer interface allows a developer to write queries in
structured query language (SQL) rather than using query-by-
example. These queries are then processed and executed by
the query processor. This allows the construction of more
complex queries to interrogate the database.
Query processor
The query processor takes a query written in SQL and
processes it. The query processor includes a DDL interpreter, a
DML compiler and a query evaluation engine. Any DDL
statements are interpreted and recorded in the database’s
data dictionary. DML statements are compiled into low level
instructions that are executed by the query evaluation engine.
The DML compiler will also optimise the query.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 156
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
8.3.1 SQL (DDL) commands and scripts
SQL (DDL) command Description
CREATE DATABASE Creates a database
CREATE TABLE Creates a table definition
ALTER TABLE Changes the definition of a table
PRIMARY KEY Adds a primary key to a table
FOREIGN KEY … REFERENCES Adds a foreign key to a table
…
Data types for attributes Description
CHARACTER Fixed length text
VARCHAR(n) Variable length text
BOOLEAN True or False; SQL uses the integers 1 and
0
INTEGER Whole number
REAL Number with decimal places
DATE A date usually formatted as YYYY-MM-
DD
TIME A time usually formatted as HH:MM:SS
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 157
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 158
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
8.3.2 SQL (DML) commands and scripts
SQL (DML) Description
query
command
SELECT Fetches data from a database. Queries always begin with
FROM SELECT.
WHERE Includes only rows in a query that match a given
condition
ORDER BY Sorts the results from a query by a given column either
alphabetically or numerically
GROUP BY Arranges data into groups
INNER JOIN Combines rows from different tables if the join condition
is true
SUM Returns the sum of all the values in the column
COUNT Counts the number of rows where the column is not NUL
AVG Returns the average value for a column with a numeric
data type
SQL (DML) maintenance commands Description
INSERT INTO Adds new row(s) to a table
DELETE FROM Removes row(s) from a table
UPDATE Edits row(s) in a table
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 159
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
This query will show, in alphabetical order of second name, the first
and second names of all students in class 7A:
SELECT FirstName, SecondName
FROM Student
WHERE ClassID = '7A'
ORDER BY SecondName
This query will show the teacher’s name and the subject taught:
SELECT Teacher.TeacherName AND Subject.SubjectName
FROM Teacher INNER JOIN Subject ON Teacher. LicenceNumber =
Subject.LicenceNumber
This statement will insert a row into the Student table:
INSERT INTO Student VALUES(S1301, Peter, Probert, 06/06/2011, 7A)
If the values for all the columns are not known, then the table
columns need to be specified before the values are inserted:
INSERT INTO Student(StudentID, FirstName, SecondName)
VALUES(S1301, Peter, Probert)
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 160
AS Computer Science - 9618 Chapter 8 : Databases Instructor: Nadia Arif
These statements will delete the specified row(s) from the Student
table
DELETE FROM Student WHERE StudentID = 'S1301'
The values for any column can be counted, totalled or averaged
SELECT SUM (ExamMark)
FROM STUDENTSUBJECT
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 161
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
P2 Theory with step by step
pseudocode guide
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 162
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 163
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
9.1 Computational Thinking Skills:
9.1.1 Abstraction – the process of extracting information that is
essential, while ignoring what is not relevant, for the provision of a
solution.
The benefits of eliminating any unnecessary characteristics from the
model include
the time required to develop the program is reduced so the program
can be delivered to the customer more quickly
the program is smaller in size so takes up less space in memory and
download times are shortened
customer satisfaction is greater as their requirements are met
without any extraneous features.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 164
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
9.1.2 Decomposition – the process of breaking a complex problem into
smaller parts.
9.1.3 Pattern recognition – the identification of parts of a problem that
are similar and could use the same solution
9.2 Methods of finding the solution to a problem:
Structured English is a method of showing the logical steps in an
algorithm, using an agreed subset of straightforward English words for
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 165
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
commands and mathematical operations to represent the solution.
These steps can be numbered.
A flowchart shows diagrammatically, using a set of symbols linked
together with flow lines, the steps required for a task and the order
in which they are to be performed. These steps, together with the
order, are called an algorithm. Flowcharts are an effective way to show
the structure of an algorithm.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 166
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 167
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Pseudocode is a method of showing the detailed logical steps in an
algorithm, using keywords, identifiers with meaningful names and
mathematical operators to represent a solution.
Total ← 0
OUTPUT "Enter the number of values to average"
INPUT Number
FOR Counter ← 1 TO Number
OUTPUT "Enter value"
INPUT Value
Total ← Total + Value
NEXT Counter
Average ← Total / Number
OUTPUT "The average of ", Number, " values is ", Average
Operators used in Pseudocode:
+ addition
- subtraction
* multiplication
/ divide
& concatenation
<--- assignment
= Equal to
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 168
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
<> Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== To check if two values are equal
OR either
AND both
NOT not
Integer 4
Real 4.3
Character "a"
String "Hamza"
Boolean True OR False
Pseudocode Statements:
To Input a value
INPUT StudentName
To Output a statement or result:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 169
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
OUTPUT "You have made an error"
OUTPUT StudentName
OUTPUT "Student name is ", StudentName
To Assign a value to a variable:
Counter ← 1
Counter ← Counter + 1
MyChar ← "A"
LetterValue ← ASC(MyChar)
StudentMark ← 40
Percentage ← (StudentMark / 80) * 100
Oldstring ← "Your mark is"
NewString ← OldString & " ninety-seven"
Selection Statements:
IF/ELSE
CASE/ENDCASE
IF MyValue > YourValue
THEN
OUTPUT "I win"
ELSE OUTPUT "You win"
ENDIF
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 170
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
CASE OF Direction
"N": Y ← Y + 1
"S": Y ← Y – 1
"E": X ← X + 1
"W": X ← X – 1
OTHERWISE : OUTPUT "Error"
ENDCASE
Iteration:
FOR LOOP (Count Controlled Loop)
WHILE LOOP (Pre Conditioned Loop)
REPEAT LOOP (Post Conditioned loop)
Total ← 0
FOR Counter ← 1 TO 10
OUTPUT "Enter a number "
INPUT Number
Total ← Total + Number
NEXT Counter
OUTPUT "The total is ", Total
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 171
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
REPEAT
OUTPUT "Please enter a positive number "
INPUT Number
UNTIL Number > 0
Number ← 0
WHILE Number >= 0
DO
OUTPUT "Please enter a negative number "
INPUT Number
ENDWHILE
Writing Pseudocode from a flowchart:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 172
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Stepwise refinement:
When an algorithm is written to solve a more complex problem,
decomposition is used to break the problem down into smaller and more
manageable parts. These parts then need to be written as a series of steps
where each step can be written as a statement in a high-level
programming language, this process is called stepwise refinement.
Identifier Table:
keep track of any identifiers used during the program along with its
description and data type
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 173
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Practice Questions with marking scheme
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 174
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 175
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 176
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 177
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 178
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 179
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 180
AS Computer Science - 9618 Chapter 9 : Algorithm design & Problem solving Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 181
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 182
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 183
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 184
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
10.1 Data types & Records
10.1.1 - Data Types:
Data Type Description Declaration
Boolean Logical values, True (1) and False (2) BOOLEAN
char Single alphanumerical character CHAR
date Value to represent a date DATE
integer Whole number, positive or negative INTEGER
real Positive or negative number with a REAL
decimal point
string Sequence of alphanumerical characters STRING
10.1.2 Variable Declaration in Pseudocode:
DECLARE Num : INTEGER
DECLARE myBirthday : DATE
DECLARE Name : STRING
DECLARE Flag : BOOLEAN
DECLARE ThisChar : CHAR
10.1.3 Records:
Records are composite data types formed by the inclusion of several
related items that may be of different data types.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 185
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
TYPE TbookRecord
DECLARE title : STRING
DECLARE author : STRING
DECLARE publisher : STRING
DECLARE noPages : INTEGER
DECLARE fiction : BOOLEAN
ENDTYPE
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 186
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
10.2 ARRAYS
An array is a data structure containing several elements of the same data
type
10.2.1 1D Arrays
DECLARE myList : ARRAY[0:8] OF INTEGER
10.2.2 2D arrays
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 187
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
DECLARE myArray : ARRAY[0:8,0:2] OF INTEGER
10.2.3 Using a linear search
DECLARE myList : ARRAY[0:8] OF INTEGER
DECLARE upperBound : INTEGER
DECLARE lowerBound : INTEGER
DECLARE index : INTEGER
DECLARE item : INTEGER
DECLARE found : BOOLEAN
upperBound ← 8
lowerBound ← 0
OUTPUT "Please enter item to be found"
INPUT item
found ← FALSE
index ← lowerBound
REPEAT
IF item = myList[index]
THEN
found ← TRUE
ENDIF
index ← index + 1
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 188
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
UNTIL (found = TRUE) OR (index > upperBound)
IF found
THEN
OUTPUT "Item found"
ELSE
OUTPUT "Item not found"
ENDIF
10.2.4 Using a bubble sort:
This is a method of sorting data in an array into alphabetical or numerical
order by comparing adjacent items and swapping them if they are in the
wrong order.
Pseudocode:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 189
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
DECLARE myList : ARRAY[0:8] OF
INTEGER
DECLARE upperBound : INTEGER
DECLARE lowerBound : INTEGER
DECLARE index : INTEGER
DECLARE swap : BOOLEAN
DECLARE temp : INTEGER
DECLARE top : INTEGER
upperBound ← 8
lowerBound ← 0
top ← upperBound
REPEAT FOR index = lowerBound TO top - 1
Swap ← FALSE
IF myList[index] > myList[index + 1]
THEN
temp ← myList[index]
myList[index] ← myList[index + 1]
myList[index + 1] ← temp
swap ← TRUE
ENDIF
NEXT
top ← top -1
UNTIL (NOT swap) OR (top = 0)
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 190
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Bubble sort in a 2D Array:
PROCEDURE Sort()
DECLARE Temp : INTEGER
DECLARE NoSwaps : BOOLEAN
DECLARE Boundary, Row, Col : INTEGER
Boundary ← 999
REPEAT
NoSwaps ← TRUE
FOR Row ← 1 TO Boundary
IF Result[Row, 2] > Result[Row + 1, 2]
THEN
FOR Col ← 1 TO 2
Temp ← Result [Row, Col]
Result [Row, Col] ← Result [Row + 1, Col]
Result [Row + 1, Col] ← Temp
NEXT Col
NoSwaps ← FALSE
ENDIF
NEXT Row
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 191
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
ENDPROCEDURE
10.3: Files
To open a file before reading from it or writing to it:
OPEN <file identifier> FOR <file mode>
Files can be opened in one of the following modes:
READ reads data from the file
WRITE writes data to the file, any existing data stored in the file will
be overwritten
APPEND adds data to the end of the file
Once the file is opened in READ mode, it can be read from a line at
a time:
READFILE <file Identifier> , <variable>
Once the file is opened in WRITE or APPEND mode, it can be written to
a line at a time:
WRITEFILE <file Identifier>, <variable>
In both cases, the variable must be of data type STRING.
The function EOF is used to test for the end of a file. It returns a value
TRUE if the end of a file has been reached and FALSE otherwise.
EOF(<file Identifier>)
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 192
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
When a file is no longer being used it should be closed:
CLOSEFILE <file identifier>
This pseudocode shows how the file myText.txt could be written to and
read from:
DECLARE textLn : STRING
DECLARE myFile : STRING
myFile ← "myText.txt"
OPEN myFile FOR WRITE
REPEAT
OUTPUT "Please enter a line of text"
INPUT textLn
IF textLn <> ""
THEN
WRITEFILE, textLn
ELSE
CLOSEFILE(myFile)
ENDIF
UNTIL textLn = ""
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 193
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
OUTPUT "The file contains these lines of text:"
OPEN myFile FOR READ
REPEAT
READFILE, textLn
OUTPUT textLn
UNTIL EOF(myFile)
CLOSEFILE(myFile)
10.4 String Manipulation:
String manipulation is done through the following built-in functions:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 194
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 195
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Question: Write an algorithm using pseudocode to check that the length
of a password and the first and last letter of a password input is correct.
CONSTANT storedPassword ← "Secret"
DECLARE inputPassword : STRING
DECLARE size : INTEGER
OUTPUT "Please enter your password "
INPUT inputPassword
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 196
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
size ← LENGTH(inputPassword)
IF size = LENGTH(storedPassword)
THEN
IF (LEFT(inputPassword, 1) = LEFT(storedPassword, 1)) AND
(RIGHT(inputPassword, 1) = RIGHT(storedPassword, 1))
THEN
OUTPUT "Password entered has correct first and last
letters"
ELSE
OUTPUT "Password entered is incorrect"
ENDIF
ELSE
OUTPUT "Password entered is incorrect"
ENDIF
10.5 Abstract Data Types:
An abstract data type (ADT) is a collection of data and a set of
operations on that data.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 197
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Stacks Queues Linked lists
Memory management Management of files Using arrays to
sent to a printer implement a stack
Expression evaluation Buffers used with Using arrays to
keyboards implement a queue
Backtracking in Scheduling Using arrays to
recursion implement a binary tree
Stack:
a list containing several items operating on the last in, first out
(LIFO) principle.
Items can be added to the stack (push) and removed from the
stack (pop).
The first item added to a stack is the last item to be removed from
the stack.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 198
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Implementing a stack using arrays and variables:
A stack can be implemented using an array and a set of pointers.
As an array has a finite size, the stack may become full and this
condition must be allowed for
Queue:
a list containing several items operating on the first in, first out
(FIFO) principle.
Items can be added to the queue (enqueue) and removed from the
queue (dequeue).
The first item added to a queue is the first item to be removed from
the queue.
The value of the frontPointer changes after dequeue but the value
of the rearPointer changes after enqueuer
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 199
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Implementing a queue using arrays and variables:
A queue can be implemented using an array and a set of
pointers.
As an array has a finite size, the queue may become full and
this condition must be allowed for.
Also, as items are removed from the front and added to the
end of a queue, the position of the queue in the array changes.
Therefore, the queue should be managed as a circular queue to
avoid moving the position of the items in the array every time
an item is removed.
When a queue is implemented using an array with a finite
number of elements, it is managed as a circular queue.
Both pointers, frontPointer and rearPointer, are updated to
point to the first element in the array (lower bound) after an
operation where that pointer was originally pointing to the last
element of the array (upper bound), providing the length of the
queue does not exceed the size of the array.
Linked list :
a list containing several items in which each item in the list points
to the next item in the list.
In a linked list a new item is always added to the start of the list.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 200
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Implementing a Linked List using arrays and variables:
A linked list can be implemented using two 1D arrays, one for the
items in the linked list and another for the pointers to the next
item in the list, and a set of pointers.
As an array has a finite size, the linked list may become full and
this condition must be allowed for.
Also, as items can be removed from any position in the linked list,
the empty positions in the array must be managed as an empty
linked list, usually called the heap.
10.6 Structured Programming:
Important definitions:
Parameter – a variable applied to a procedure or function that allows
one to pass in a value for the procedure to use.
By value – a method of passing a parameter to a procedure in which
the value of the variable cannot be changed by the procedure.
By reference – a method of passing a parameter to a procedure in
which the value of the variable can be changed by the procedure.
Header (procedure or function) – the first statement in the
definition of a procedure or function, which contains its name, any
parameters passed to it, and, for a function, the type of the return
value.
Argument – the value passed to a procedure or function.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 201
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
10.6.1 Procedure:
PROCEDURE stars (Number : INTEGER)
FOR Counter 1 TO Number
OUTPUT "*"
NEXT Counter
ENDPROCEDURE
10.6.2 Functions:
FUNCTION substring (myString : STRING, start : INTEGER, length :
INTEGER) RETURNS STRING
IF LENGTH (myString) >= length + start
THEN
RETURN MID (myString, start, length)
ELSE RETURN ""
ENDIF
ENDFUNCTION
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 202
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Practice Questions with marking scheme
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 203
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 204
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 205
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 206
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 207
AS Computer Science - 9618 Chapter 10 & 11 : Data types & Structures Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 208
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 209
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
12.1 Program development Life Cycle:
Purpose:
A program that has been developed may require alterations at any time in
order to deal with new circumstances or new errors that have been found,
so the stages are referred to as a lifecycle as this continues until the
program is no longer used.
Stages in the program development lifecycle
Analysis:
a process of investigation, leading to the specification of what a
program is required to do
Design:
it uses the program specification from the analysis stage to show
how the program should be developed.
Coding
The program or set of programs is written using a suitable
programming language.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 210
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
Testing
The program is run many times with different sets of test data,
to test that it does everything it is supposed to do in the way set
out in the program design.
Maintenance
The program is maintained throughout its life, to ensure it
continues to work effectively. This involves dealing with any
problems that arise during use, including correcting any errors that
come to light, improving the functionality of the program, or
adapting the program to meet new requirements.
12.2 Different development lifecycles
The waterfall model
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 211
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
The arrows going down represent the fact that the results from one stage
are input into the next stage. The arrows leading back up to an earlier
stage reflect the fact that often more work is required at an earlier stage
to complete the current stage
Principles Benefits Drawbacks
linear, as each stage is easy to manage, difficult to change the
completed before the understand and use requirements at a later
next is begun stage
well documented as full stages do not overlap not suitable for
documentation is and are completed one programs where the
completed at every at a time requirements could be
stage subject to change
low customer each stage has specific working program is
involvement; only deliverables produced late in the
involved at the start lifecycle
and end of the process
works well for smaller not suitable for long,
programs where complex projects
requirements are known
and understood
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 212
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
The iterative model
An iterative life cycle model does not attempt to start with a full
specification of requirements. Instead, development starts with the
implementation of a small subset of the program requirements. Repeated
(iterative) reviews to identify further requirements eventually result in the
complete system
Principles Benefits Drawbacks
incremental some working whole system needs to
development as the programs developed be defined at start, so it
program development quickly at an early can be broken down into
lifecycle is repeated stage in the lifecycle pieces to be developed at
each iteration
working programs are easier to test and needs good planning
produced for part of the debug smaller overall and for every
system at every programs stage
iteration
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 213
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
high customer more flexible as easier not suitable for short
involvement, as part of to alter requirements simple projects
the system can be
shown to the customer
after every iteration
customers involved at
each iteration
therefore no surprises
when final system
delivered
Rapid application development (RAD):
RAD is a software development methodology that uses minimal planning.
Instead it uses prototyping. A prototype is a working model of part of the
solution
In the RAD model, the modules are developed in parallel as prototypes and
are integrated to make the complete product for faster product delivery.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 214
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
There is no detailed preplanning. Changes are made during the
development process. The analysis, design, code and test phases are
incorporated into a series of short, iterative development cycles.
Principles Benefits Drawbacks
minimal planning reduced overall development system under
time development
reuses previously written rapid frequent customer needs to be
code where possible, feedback informs the modular needs
makes use of automated development strong teams of
code generation where skilled developers
possible
high customer very flexible as not suitable for
involvement, as requirements evolve from short simple
customers can use the feedback during projects
prototypes during development
development
as parts of the system are
developed side by side,
modification is easier
because each part must
work independently
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 215
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
12.3 Program Design:
Structure charts:
A structure chart is a modelling tool used in program design to decompose
a problem into a set of sub-tasks. The structure chart shows the
hierarchy or structure of the different modules and how they connect and
interact with each other.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 216
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
12.4 state-transition diagrams:
A finite state machine (FSM) is a mathematical model of a machine
that can be in one of a fixed set of possible states. One state is changed
to another by an external input, this is called a transition. A diagram
showing the behaviour of an FSM is called a state-transition diagram.
State-transition diagrams can be constructed as follows:
States are represented as nodes (circles).
Transitions are represented as interconnecting arrows.
Events are represented as labels on the arrows.
Conditions can be specified in square brackets after the event label.
The initial state is indicated by an arrow with a black dot.
A stopped state is indicated by a double circle.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 217
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
12.5 Program testing:
Several types of test data need to be used during testing:
Normal test data that is to be accepted by a program and is used to
show that the program is working as expected.
Abnormal test data that should be rejected by a program as it is
unsuitable or could cause problems.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 218
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
Extreme test data that is on the limit of that accepted by a
program; for example, when testing a validation rule such as number
>= 12 AND number <= 32 the extreme test data would be 12 at the
lower limit and 32 at the upper limit; both these values should be
accepted.
Boundary test data that is on the limit of that accepted by a
program or data that is just outside the limit of that rejected by a
program; for example, when testing a validation rule such as number
>= 12 AND number <= 32 the boundary test data would be 12 and 11
at the lower limit and 32 and 33 at the upper limit; 12 and 32
should be accepted, 11 and 33 should be rejected
As the program is being developed the following types of testing are used:
White-box testing is the detailed testing of how each procedure
works. This involves testing the structure and logic of every path
through a program module.
Black-box testing tests a module’s inputs and outputs.
Integration testing is the testing of any separately written modules
to ensure that they work together, during the testing phase of the
program development lifecycle. If any of the modules have not been
written yet, this can include stub testing, which makes use of
dummy modules for testing purposes.
When the program has been completed, it is tested as a whole:
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 219
AS Computer Science - 9618 Chapter 12 : Software Development Instructor: Nadia Arif
Alpha testing is used first. The completed, or nearly completed,
program is tested in-house by the development team.
Beta testing is then used. The completed program is tested by a
small group of users before it is generally released.
Acceptance testing is then used for the completed program to prove
to the customer that it works as required in the environment in
which it will be used.
12.6 Program Maintenance:
Program maintenance can usually be divided into three categories:
Corrective maintenance is used to correct any errors that appear
during use, for example trapping a run-time error that had been
missed during testing.
Perfective maintenance is used to improve the performance of a
program during its use, for example improving the speed of response.
Adaptive maintenance is used to alter a program so it can perform
any new tasks required by the customer, for example working with
voice commands as well as keyboard entry.
Sharjeel Arif: 0333 5752253 Copyright ©Learningscapes Academy 220
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
1. Pseudocode in examined components
The following information sets out how pseudocode will appear within the examined components and is
provided to allow you to give learners familiarity before the exam.
1.1 Font style and size
Pseudocode is presented in a monospaced (fixed-width) font such as Courier New. The size of the font will
be consistent throughout.
1.2 Indentation
Lines are indented (usually by three spaces) to indicate that they are contained within a statement in a
previous line. In cases where line numbering is used, this indentation may be omitted. Every effort will be
made to make sure that code statements are not longer than a line of text unless this is absolutely
necessary. Where necessary, continuation lines will be aligned to maximise readability.
1.3 Case
Keywords are in upper-case, e.g. IF, REPEAT, PROCEDURE. (Different keywords are explained in
later sections of this guide.)
Identifiers are in mixed case (sometimes referred to as camelCase or Pascal case) with upper-case letters
indicating the beginning of new words, for example NumberOfPlayers.
Meta-variables – symbols in the pseudocode that should be substituted by other symbols are enclosed in
angled brackets < > (as in Backus-Naur Form). This is also used in this guide.
Example – meta-variables
REPEAT
<statement(s)>
UNTIL <condition>
1.4 Lines and line numbering
Where it is necessary to number the lines of pseudocode so that they can be referred to, line numbers are
presented to the left of the pseudocode with sufficient space to indicate clearly that they are not part of the
pseudocode statements.
Line numbers are consecutive, unless numbers are skipped to indicate that part of the code is missing. This
will also be clearly stated.
Each line representing a statement is numbered. However, when a statement runs over one line of text, the
continuation lines are not numbered.
2
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
1.5 Comments
Comments are preceded by two forward slashes //. The comment continues until the end of the line. For
multi-line comments, each line is preceded by //.
Normally the comment is on a separate line before, and at the same level of indentation as, the code it refers
to. Occasionally, however, a short comment that refers to a single line may be at the end of the line to which
it refers.
Example – comments
// this procedure swaps
// values of X and Y
PROCEDURE SWAP(BYREF X : INTEGER, Y : INTEGER)
Temp ← X // temporarily store X
X ←Y
Y ← Temp
ENDPROCEDURE
3
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
2. Variables, constants and data types
2.1. Data Types
The following keywords are used to designate some basic data types:
• INTEGER a whole number
• REAL a number capable of containing a fractional part
• CHAR a single character
• STRING a sequence of zero or more characters
• BOOLEAN the logical values TRUE and FALSE
• DATE a valid calendar date
2.2. Literals
Literals of the above data types are written as follows:
• Integer Written as normal in the denary system, e.g. 5, -3
Always written with at least one digit on either side of the decimal point, zeros being
• Real
added if necessary, e.g. 4.7, 0.3, -4.0, 0.0
• Char A single character delimited by single quotes e.g. ꞌxꞌ, ꞌCꞌ, ꞌ@ꞌ
Delimited by double quotes. A string may contain no characters (i.e. the empty string)
• String
e.g. "This is a string", ""
• Boolean TRUE, FALSE
This will normally be written in the format dd/mm/yyyy. However, it is good practice to
• Date state explicitly that this value is of data type DATE and to explain the format (as the
convention for representing dates varies across the world).
2.3. Identifiers
Identifiers (the names given to variables, constants, procedures and functions) are in mixed case. They can
only contain letters (A–Z, a–z), digits (0–9) and the underscore character ( _ ). They must start with a letter and
not a digit. Accented letters should not be used.
It is good practice to use identifier names that describe the variable, procedure or function they refer to. Single
letters may be used where these are conventional (such as i and j when dealing with array indices, or X and
Y when dealing with coordinates) as these are made clear by the convention.
Keywords identified elsewhere in this guide should never be used as variables.
Identifiers should be considered case insensitive, for example, Countdown and CountDown should not
be used as separate variables.
4
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
2.4. Variable declarations
It is good practice to declare variables explicitly in pseudocode.
Declarations are made as follows:
DECLARE <identifier> : <data type>
Example – variable declarations
DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
2.5. Constants
It is good practice to use constants if this makes the pseudocode more readable, as an identifier is more
meaningful in many cases than a literal. It also makes the pseudocode easier to update if the value of the
constant changes.
Constants are normally declared at the beginning of a piece of pseudocode (unless it is desirable to restrict
the scope of the constant).
Constants are declared by stating the identifier and the literal value in the following format:
CONSTANT <identifier> = <value>
Example – CONSTANT declarations
CONSTANT HourlyRate = 6.50
CONSTANT DefaultText = "N/A"
Only literals can be used as the value of a constant. A variable, another constant or an expression must
never be used.
2.6. Assignments
The assignment operator is ← .
Assignments should be made in the following format:
<identifier> ← <value>
The identifier must refer to a variable (this can be an individual element in a data structure such as an array or
a user defined data type). The value may be any expression that evaluates to a value of the same data type
as the variable.
Example – assignments
Counter ← 0
Counter ← Counter + 1
TotalToPay ← NumberOfHours * HourlyRate
5
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
3. Arrays
Syllabus requirements
The Cambridge International AS & A Level syllabus (9618) requires candidates to understand and
use both one-dimensional and two-dimensional arrays.
3.1. Declaring arrays
Arrays are considered to be fixed-length structures of elements of identical data type, accessible by
consecutive index (subscript) numbers. It is good practice to explicitly state what the lower bound of the
array (i.e. the index of the first element) is because this defaults to either 0 or 1 in different systems.
Generally, a lower bound of 1 will be used.
Square brackets are used to indicate the array indices.
A One-dimensional array is declared as follows:
DECLARE <identifier>:ARRAY[<lower>:<upper>] OF <data type>
A two-dimensional array is declared as follows:
DECLARE <identifier>:ARRAY[<lower1>:<upper1>,<lower2>:<upper2>] OF <data type>
Example – array declarations
DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE NoughtsAndCrosses : ARRAY[1:3,1:3] OF CHAR
3.2. Using arrays
Array index values may be literal values or expressions that evaluate to a valid integer value.
Example – Accessing individual array elements
StudentNames[1] ← "Ali"
NoughtsAndCrosses[2,3] ← ꞌXꞌ
StudentNames[n+1] ← StudentNames[n]
Arrays can be used in assignment statements (provided they have same size and data type). The following is
therefore allowed:
Example – Accessing a complete array
SavedGame ← NoughtsAndCrosses
A statement should not refer to a group of array elements individually. For example, the following
construction should not be used.
StudentNames [1 TO 30] ← ""
6
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
Instead, an appropriate loop structure is used to assign the elements individually. For example:
Example – assigning a group of array elements
FOR Index ← 1 TO 30
StudentNames[Index] ← ""
NEXT Index
7
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
4. User-defined data types
Syllabus requirements
The AS & A Level (9618) syllabus requires candidates to understand that data structures that are not
available in a particular programming language need to be constructed from the data structures that
are built-in within the language. User-defined data types need to be defined. The syllabus requires
candidates to use and define non-composite data types such as enumerated and pointer and
composite data types such as record, set, class/object. Abstract Data Types (ADTs) stack, queue,
linked list, dictionary and binary tree are also defined as composite data types.
4.1. Defining user-defined data types
Non-composite data type – Enumerated
A user-defined non-composite data type with a list of possible values is called an enumerated data type.
The enumerated type should be declared as follows:
TYPE <identifier> = (value1, value2, value3, ...)
Example – declaration of enumerated type
This enumerated type holds data about seasons of the year.
TYPE Season = (Spring, Summer, Autumn, Winter)
Non-composite data type – Pointer
A user-defined non-composite data type referencing a memory location is called a pointer.
The pointer should be declared as follows:
TYPE <identifier> = ^<data type>
The ^ shows that the variable is a pointer and the data type indicates the type of the data
stored in the memory location.
Example – declarations of pointer type
TYPE TIntPointer = ^INTEGER
TYPE TCharPointer = ^CHAR
Declaration of a variable of pointer type does not require the ^ (caret) symbol to be used.
Example – declaration of a pointer variable
DECLARE MyPointer : TIntPointer
8
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
Composite data type
A composite data type is a collection of data that can consist of different data types, grouped under one
identifier. The composite type should be declared as follows:
TYPE <identifier1>
DECLARE <identifier2> : <data type>
TECLARE <identifier3> : <data type>
...
ENDTYPE
Example – declaration of composite type
This user-defined data type holds data about a student.
TYPE Student
DECLARE LastName : STRING
DECLARE FirstName : STRING
DECLARE DateOfBirth : DATE
DECLARE YearGroup : INTEGER
DECLARE FormGroup : CHAR
ENDTYPE
9
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
4.2. Using user-defined data types
When a user-defined data type has been defined it can be used in the same way as any other data type in
declarations.
Variables of a user-defined data type can be assigned to each other. Individual data items are accessed
using dot notation.
Example – using user-defined data types
This pseudocode uses the user-defined types Student, Season and TIntPointer defined in
the previous section.
DECLARE Pupil1 : Student
DECLARE Pupil2 : Student
DECLARE Form : ARRAY[1:30] OF Student
DECLARE ThisSeason : Season
DECLARE NextSeason : Season
DECLARE MyPointer : TIntPointer
Pupil1.LastName ← "Johnson"
Pupil1.Firstname ← "Leroy"
Pupil1.DateOfBirth ← 02/01/2005
Pupil1.YearGroup ← 6
Pupil1.FormGroup ← ꞌAꞌ
Pupil2 ← Pupil1
FOR Index ← 1 TO 30
Form[Index].YearGroup ← Form[Index].YearGroup + 1
NEXT Index
ThisSeason ← Spring
MyPointer ← ^ThisSeason
NextSeason ← MyPointer^ + 1
// access the value stored at the memory address
10
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
5. Common operations
5.1. Input and output
Values are input using the INPUT command as follows:
INPUT <identifier>
The identifier should be a variable (that may be an individual element of a data structure such as an array, or
a custom data type).
Values are output using the OUTPUT command as follows:
OUTPUT <value(s)>
Several values, separated by commas, can be output using the same command.
Example – INPUT and OUTPUT statements
INPUT Answer
OUTPUT Score
OUTPUT "You have ", Lives, " lives left"
5.2. Arithmetic operations
Standard arithmetic operator symbols are used:
+ Addition
- Subtraction
* Multiplication
/ Division (The resulting value should be of data type REAL, even if the operands are integers.)
DIV Integer division: Used to find the quotient (integer number before the decimal point) after division.
MOD or Modulus: The remainder that is left over when one number is divided by another.
Multiplication and division have higher precedence over addition and subtraction (this is the normal
mathematical convention). However, it is good practice to make the order of operations in complex
expressions explicit by using parentheses.
5.3. Relational operations
The following symbols are used for relational operators (also known as comparison operators):
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
= Equal to
<> Not equal to
The result of these operations is always of data type BOOLEAN.
In complex expressions it is advisable to use parentheses to make the order of operations explicit.
11
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
5.4. Logic operators
The only logic operators (also called relational operators) used are AND, OR and NOT. The operands and
results of these operations are always of data type BOOLEAN.
In complex expressions it is advisable to use parentheses to make the order of operations explicit.
5.5. String functions and operations
Syllabus requirements
The AS & A Level (9618) syllabus specifically requires candidates to know string manipulation
functions in their chosen programming language. Pseudocode string manipulation functions will
always be provided in examinations. Some basic string manipulation functions are given here.
Each function returns an error if the function call is not properly formed.
RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING
returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"
LENGTH(ThisString : STRING) RETURNS INTEGER
returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10
MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING
returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns "BCD"
LCASE(ThisChar : CHAR) RETURNS CHAR
returns the character value representing the lower-case equivalent of ThisChar
If ThisChar is not an upper-case alphabetic character, it is returned unchanged.
Example: LCASE('W') returns 'w'
UCASE(ThisChar : CHAR) RETURNS CHAR
returns the character value representing the upper-case equivalent of ThisChar
If ThisChar is not a lower-case alphabetic character, it is returned unchanged.
Example: UCASE('h') returns 'H'
12
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
In pseudocode, the operator & is used to concatenate (join) two strings.
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Where string operations (such as concatenation, searching and splitting) are used in a programming
language, these should be explained clearly, as they vary considerably between systems.
Where functions in programming languages are used to format numbers as strings for output, their use should
also be explained.
5.6. Numeric functions
INT(x : REAL) RETURNS INTEGER
returns the integer part of x
Example: INT(27.5415) returns 27
RAND(x : INTEGER) RETURNS REAL
returns a random real number in the range 0 to x (not inclusive of x)
Example: RAND(87) may return 35.43
13
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
6. Selection
6.1. IF statements
IF statements may or may not have an ELSE clause.
IF statements without an ELSE clause are written as follows:
IF <condition> THEN
<statement(s)>
ENDIF
IF statements with an ELSE clause are written as follows:
IF <condition> THEN
<statement(s)>
ELSE
<statement(s)>
ENDIF
Note, due to space constraints, the THEN and ELSE clauses may only be indented by two spaces rather than
three. (They are, in a sense, a continuation of the IF statement rather than separate statements).
Example – nested IF statements
IF ChallengerScore > ChampionScore THEN
IF ChallengerScore > HighestScore THEN
OUTPUT ChallengerName, " is champion and highest scorer"
ELSE
OUTPUT ChallengerName, " is the new champion"
ENDIF
ELSE
OUTPUT ChampionName, " is still the champion"
IF ChampionScore > HighestScore THEN
OUTPUT ChampionName, " is also the highest scorer"
ENDIF
ENDIF
14
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
6.2. CASE statements
CASE statements allow one out of several branches of code to be executed, depending on the value of a
variable.
CASE statements are written as follows:
CASE OF <identifier>
<value 1> : <statement1>
<statement2>
...
<value 2> : <statement1>
<statement2>
...
...
ENDCASE
An OTHERWISE clause can be the last case:
CASE OF <identifier>
<value 1> : <statement1>
<statement2>
...
<value 2> : <statement1>
<statement2>
...
OTHERWISE : <statement1>
<statement2>
...
ENDCASE
Each value may be represented by a range, for example:
<value1> TO <value2> : <statement1>
<statement2>
...
Note that the CASE clauses are tested in sequence. When a case that applies is found, its statement is
executed and the CASE statement is complete. Control is passed to the statement after the ENDCASE. Any
remaining cases are not tested.
If present, an OTHERWISE clause must be the last case. Its statement will be executed if none of the
preceding cases apply.
Example – formatted CASE statement
INPUT Move
CASE OF Move
ꞌWꞌ : Position ← Position − 10
ꞌSꞌ : Position ← Position + 10
ꞌAꞌ : Position ← Position − 1
ꞌDꞌ : Position ← Position + 1
OTHERWISE : CALL Beep
ENDCASE
15
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
7. Iteration (repetition)
7.1. Count-controlled (FOR) loops
Count-controlled loops are written as follows:
FOR <identifier> ← <value1> TO <value2>
<statement(s)>
NEXT <identifier>
The identifier must be a variable of data type INTEGER, and the values should be expressions that evaluate
to integers.
The variable is assigned each of the integer values from value1 to value2 inclusive, running the statements
inside the FOR loop after each assignment. If value1 = value2 the statements will be executed once, and if
value1 > value2 the statements will not be executed.
It is good practice to repeat the identifier after NEXT, particularly with nested FOR loops.
An increment can be specified as follows:
FOR <identifier> ← <value1> TO <value2> STEP <increment>
<statement(s)>
NEXT <identifier>
The increment must be an expression that evaluates to an integer. In this case the identifier will be
assigned the values from value1 in successive increments of increment until it reaches value2. If it goes
past value2, the loop terminates. The increment can be negative.
Example – nested FOR loops
Total ← 0
FOR Row ← 1 TO MaxRow
RowTotal ← 0
FOR Column ← 1 TO 10
RowTotal ← RowTotal + Amount[Row, Column]
NEXT Column
OUTPUT "Total for Row ", Row, " is ", RowTotal
Total ← Total + RowTotal
NEXT Row
OUTPUT "The grand total is ", Total
7.2. Post-condition (REPEAT) loops
Post-condition loops are written as follows:
REPEAT
<statement(s)>
UNTIL <condition>
The condition must be an expression that evaluates to a Boolean.
16
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
The statements in the loop will be executed at least once. The condition is tested after the statements are
executed and if it evaluates to TRUE the loop terminates, otherwise the statements are executed again.
Example – REPEAT UNTIL loop
REPEAT
OUTPUT "Please enter the password"
INPUT Password
UNTIL Password = "Secret"
7.3. Pre-condition (WHILE) loops
Pre-condition loops are written as follows:
WHILE <condition>
<statement(s)>
ENDWHILE
The condition must be an expression that evaluates to a Boolean.
The condition is tested before the statements, and the statements will only be executed if the condition
evaluates to TRUE. After the statements have been executed the condition is tested again. The loop
terminates when the condition evaluates to FALSE.
The statements will not be executed if, on the first test, the condition evaluates to FALSE.
Example – WHILE loop
WHILE Number > 9
Number ← Number – 9
ENDWHILE
17
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
8. Procedures and functions
Syllabus requirements
The definition and use of procedures and functions is explicitly required in the AS & A Level (9618)
syllabus. Any pseudocode functions used in an examination will be defined.
8.1. Defining and calling procedures
A procedure with no parameters is defined as follows:
PROCEDURE <identifier>
<statement(s)>
ENDPROCEDURE
A procedure with parameters is defined as follows:
PROCEDURE <identifier>(<param1> : <data type>, <param2> : <data type>...)
<statement(s)>
ENDPROCEDURE
The <identifier> is the identifier used to call the procedure. Where used, param1, param2 etc. are
identifiers for the parameters of the procedure. These will be used as variables in the statements of the
procedure.
Procedures defined as above should be called as follows, respectively:
CALL <identifier>
CALL <identifier>(Value1, Value2, ...)
These calls are complete program s tatem e nts .
When parameters are used, Value1, Value2... must be of the correct data type and in the same
sequence as in the definition of the procedure.
Unless otherwise stated, it should be assumed that parameters are passed by value. (See section 8.3).
18
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
Example – definition and use of procedures with and without parameters
PROCEDURE DefaultSquare
CALL Square(100)
ENDPROCEDURE
PROCEDURE Square(Size : INTEGER)
FOR Side ← 1 TO 4
CALL MoveForward(Size)
CALL Turn(90)
NEXT Side
ENDPROCEDURE
IF Size = Default THEN
CALL DefaultSquare
ELSE
CALL Square(Size)
ENDIF
8.2. Defining and calling functions
Functions operate in a similar way to procedures, except that in addition they return a single value to the point
at which they are called. Their definition includes the data type of the value returned.
A function with no parameters is defined as follows:
FUNCTION <identifier> RETURNS <data type>
<statement(s)>
ENDFUNCTION
A function with parameters is defined as follows:
FUNCTION <identifier>(<param1> : <data type>,
<param2> : <data type>…) RETURNS <data type>
<statement(s)>
ENDFUNCTION
The keyword RETURN is used as one of the statements within the body of the function to specify the value to
be returned. Normally, this will be the last statement in the function definition, however, if the RETURN
statement is in the body of the function its execution is immediate and any subsequent lines of code are
omitted.
Because a function returns a value that is used when the function is called, function calls are not complete
program statements. The keyword CALL should not be used when calling a function. Functions should only
be called as part of an expression. When the RETURN statement is executed, the value returned replaces the
function call in the expression and the expression is then evaluated.
19
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
Example – definition and use of a function
FUNCTION Max(Number1 : INTEGER, Number2 : INTEGER) RETURNS INTEGER
IF Number1 > Number2 THEN
RETURN Number1
ELSE
RETURN Number2
ENDIF
ENDFUNCTION
OUTPUT "Penalty Fine = ", Max(10, Distance*2)
8.3. Passing parameters by value or by reference
To specify whether a parameter is passed by value or by reference, the keywords BYVAL and BYREF precede
the parameter in the definition of the procedure. If there are several parameters passed by the same method,
the BYVAL or BYREF keyword need not be repeated.
Example – passing parameters by reference
PROCEDURE SWAP(BYREF X : INTEGER, Y : INTEGER)
Temp ← X
X ←Y
Y ← Temp
ENDPROCEDURE
If the method for passing parameters is not specified, passing by value is assumed. How this should
be called and how it operates has already been explained in Section 8.1.
Parameters should not be passed by reference to a function.
20
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
9. File handling
9.1. Handling text files
Text files consist of lines of text that are read or written consecutively as strings.
A file must be opened in a specified mode before any file operations are attempted. This is written
as follows:
OPENFILE <file identifier> FOR <file mode>
The file identifier may be a literal string containing the file names, or a variable of type STRING that has been
assigned the file name.
The following file modes are used:
• READ for data to be read from the file
• WRITE for data to be written to the file. A new file will be created and any existing data in the
file will be lost.
• APPEND for data to be added to the file, after any existing data.
A file should be opened in only one mode at a time.
Data is read from the file (after the file has been opened in READ mode) using the READFILE command as
follows:
READFILE <file identifier>, <variable>
The variable should be of data type STRING. When the command is executed, the next line of
text in the file is read and assigned to the variable.
The function EOF is used to test whether there are any more lines to be read from a given file. It is called as
follows:
EOF(<file identifier>)
This function returns TRUE if there are no more lines to read (or if an empty file has been opened in READ
mode) and FALSE otherwise.
Data is written into the file (after the file has been opened in WRITE or APPEND mode) using the
WRITEFILE command as follows:
WRITEFILE <file identifier> , <data>
Files should be closed when they are no longer needed using the CLOSEFILE command as follows:
CLOSEFILE <file identifier>
21
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
Example – handling text files
This example uses the operations together, to copy all the lines from FileA.txt to FileB.txt,
replacing any blank lines by a line of dashes.
DECLARE LineOfText : STRING
OPENFILE "FileA.txt" FOR READ
OPENFILE "FileB.txt" FOR WRITE
WHILE NOT EOF("FileA.txt")
READFILE "FileA.txt", LineOfText
IF LineOfText = "" THEN
WRITEFILE "FileB.txt", " ---------------------------- "
ELSE
WRITEFILE "FileB.txt", LineOfText
ENDIF
ENDWHILE
CLOSEFILE "FileA.txt"
CLOSEFILE "FileB.txt"
9.2. Handling random files
Random files contain a collection of data, normally as records of fixed length. They can be thought of as
having a file pointer which can be moved to any location or address in the file. The record at that location
can then be read or written.
Random files are opened using the RANDOM file mode as follows:
OPENFILE <file identifier> FOR RANDOM
As with text files, the file identifier will normally be the name of the file.
The SEEK command moves the file pointer to a given location:
SEEK <file identifier>, <address>
The address should be an expression that evaluates to an integer which indicates the location of a record to
be read or written. This is usually the number of records from the beginning of the file. It is good practice to
explain how the addresses are computed.
The command GETRECORD should be used to read the record at the file pointer:
GETRECORD <file identifier>, <variable>
When this command is executed, the record that is read is assigned to the variable which must be of
the appropriate data type for that record (usually a user-defined type).
The command PUTRECORD is used to write a record into the file at the file pointer:
PUTRECORD <file identifier>, <variable>
When this command is executed, the data in the variable is inserted into the record at the file pointer. Any
data that was previously at this location will be replaced.
22
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
Example – handling random files
The records from positions 10 to 20 of a file StudentFile.Dat are moved to the next position and
a new record is inserted into position 10. The example uses the user-defined type Student defined
in Section 4.1.
DECLARE Pupil : Student
DECLARE NewPupil : Student
DECLARE Position : INTEGER
NewPupil.LastName ← "Johnson"
NewPupil.Firstname ← "Leroy"
NewPupil.DateOfBirth ← 02/01/2005
NewPupil.YearGroup ← 6
NewPupil.FormGroup ← ꞌAꞌ
OPENFILE "StudentFile.Dat" FOR RANDOM
FOR Position ← 20 TO 10 STEP -1
SEEK "StudentFile.Dat", Position
GETRECORD "StudentFile.Dat", Pupil
SEEK "StudentFile.Dat", Position + 1
PUTRECORD "StudentFile.Dat", Pupil
NEXT Position
SEEK "StudentFile.Dat", 10
PUTRECORD "StudentFile.Dat", NewPupil
CLOSEFILE "StudentFile.dat"
23
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
10. Object-oriented Programming
10.1. Methods and Properties
Methods and properties can be assumed to be public unless otherwise stated. Where the access level is
relevant to the question, it will be explicit in the code using the keywords PUBLIC or PRIVATE.
Example code:
PRIVATE Attempts : INTEGER
Attempts ← 3
PUBLIC PROCEDURE SetAttempts(Number : INTEGER)
Attempts ← Number
ENDPROCEDURE
PRIVATE FUNCTION GetAttempts() RETURNS INTEGER
RETURN Attempts
ENDFUNCTION
Methods will be called using object methods, for example:
Player.SetAttempts(5)
OUTPUT Player.GetAttempts()
10.2. Constructors and Inheritance
Constructors will be procedures with the name NEW.
CLASS Pet
PRIVATE Name : STRING
PUBLIC PROCEDURE NEW(GivenName : STRING)
Name ← GivenName
ENDPROCEDURE
ENDCLASS
Inheritance is denoted by the INHERITS keyword; superclass/parent class methods will be called using the
keyword SUPER, for example:
CLASS Cat INHERITS Pet
PRIVATE Breed: INTEGER
PUBLIC PROCEDURE NEW(GivenName : STRING, GivenBreed : STRING)
SUPER.NEW(GivenName)
Breed ← GivenBreed
ENDPROCEDURE
ENDCLASS
To create an object, the following format is used:
<object name> ← NEW <class name>(<param1>, <param2> ...)
For example:
MyCat ← NEW Cat("Kitty", "Persian")
24
Pseudocode Guide for Teachers Cambridge International AS & A Level Computer Science (9618)
Index of symbols and keywords
-, 11 GETRECORD, 22
←, 5 IF, 14
*, 11 INHERITS, 24
/, 11 INPUT, 11
//, 3 INT, 13
+, 11 INTEGER, 4
<, 11 LCASE, 12
<=, 11 LENGTH, 12
<>, 11 MID, 12
=, 11 MOD, 11
>, 11 NEXT, 16
>=, 11 NEW, 23
^ (caret), 8 NOT, 12
&, 13 OPENFILE, 21
AND, 12 OR, 12
APPEND, 21 OTHERWISE, 15
ARRAY, 6 OUTPUT, 11
BOOLEAN, 4 PROCEDURE, 18
BYREF, 20 PRIVATE, 24
BYVAL, 20 PUBLIC, 24
CALL, 18 PUTRECORD, 22
CASE OF, 14 RAND, 13
CHAR, 4 RANDOM (files), 22
CLASS, 24 READ, 21
CLOSEFILE, 21 READFILE, 21
CONSTANT, 5 REAL, 4
DATE, 4 REPEAT, 16
DECLARE, 5 RETURN, 19
DIV, 11 RETURNS, 19
ELSE, 14 RIGHT, 12
ENDCASE, 15 SEEK, 22
ENDCLASS, 24 STEP, 16
ENDFUNCTION, 19 STRING, 4
ENDIF, 14 SUPER, 24
ENDPROCEDURE, 18 THEN, 14
ENDTYPE, 9 TRUE, 4
ENDWHILE, 17 TYPE, 8
EOF, 21 UCASE, 12
FALSE, 4 UNTIL, 16
FOR ... TO, 16 WHILE, 17
FOR (file handling), 21 WRITE, 21
FUNCTION, 19 WRITEFILE, 21
25
Cambridge Assessment International Education
The Triangle Building, Shaftesbury Road, Cambridge, CB2 8EA, United Kingdom
t: +44 1223 553554
e: [email protected] www.cambridgeinternational.org
Copyright © UCLES January 2021