0% found this document useful (0 votes)
3 views286 pages

A1 CS Notes by MAK

The document outlines the Cambridge International AS & A Level Computer Science syllabus for 2021-2023, focusing on computational thinking, data representation, multimedia, and compression. It emphasizes the importance of understanding binary systems, character encoding, and the practical applications of these concepts in the digital industry. Additionally, it covers the encoding of images and sound, as well as the principles of data compression.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views286 pages

A1 CS Notes by MAK

The document outlines the Cambridge International AS & A Level Computer Science syllabus for 2021-2023, focusing on computational thinking, data representation, multimedia, and compression. It emphasizes the importance of understanding binary systems, character encoding, and the practical applications of these concepts in the digital industry. Additionally, it covers the encoding of images and sound, as well as the principles of data compression.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 286

MUHAMMAD ALI KHAN

PAGE 1

!"#$%&'()(
!"#$%&'()(*%#
*+(
,#-(
PAGE 2

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 3

Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content

AS Content
Computational thinking is developed using a structured approach that includes the use of programming and
problem solving skills to provide solutions to real life problems. It requires the manipulation and storage of
different types of data and the communication of solutions over networks.

Computational thinking is supported by developing an understanding of how computer architecture, hardware,


systems software, security measures and communication systems, provide the infrastructure required in an efficient
and ethical way. The syllabus supports opportunities for students to apply their skills in practical contexts that are
required in the digital industry.

1 Information representation

1.1 Data Representation


Candidates should be able to: Notes and guidance
Show understanding of binary magnitudes and the Understand the difference between and use:
difference between binary prefixes and decimal
! kibi and kilo
prefixes
! mebi and mega
! gibi and giga
! tebi and tera
Show understanding of the basis of different number Use the binary, denary, hexadecimal number bases
systems and Binary Coded Decimal (BCD) and one’s and two’s
complement representation for binary numbers
Convert an integer value from one number base /
representation to another
Perform binary addition and subtraction Using positive and negative binary integers
Show understanding of how overflow can occur
Describe practical applications where Binary Coded
Decimal (BCD) and Hexadecimal are used
Show understanding of and be able to represent Familiar with ASCII (American Standard Code for
character data in its internal binary form, depending Information Interchange), extended ASCII and
on the character set used Unicode. Students will not be expected to memorise
any particular character codes
MUHAMMAD ALI KHAN
PAGE 4

Bit patterns in a computer:


The language that a computer understands is very simple, so simple that it only has 2 different
numbers:
1 and 0. This is called Binary. Everything you see on a computer, images, sounds, games, text,
videos, spreadsheets, websites etc. Whatever it is, it will be stored as a string of ones and
zeroes.
What is a bit?
A bit is the smallest unit in digital representation of information. A bit has only two values, ON
and OFF where ON is represented by 1 and OFF by 0. In terms of electrical signals a 1 (ON) is
normally a 5 volt signal and a 0 (OFF) is a 0 volt signal.

What is a nibble?
A group of 4 bits are referred to as a nibble.

What is a byte?
In the world of computers and microcontrollers, 8 bits are considered to be a standard group. It
is called a byte. Microcontrollers are normally byte oriented and data and instructions normally
use bytes. A Byte can be broken down into two nibbles.

Positive & negative Integers


Nearly all computers work purely in binary. That means that they only use ones and zeros, and
there's no - or + symbol that the computer can use. The computer must represent negative
numbers in a different way.
We can represent a negative number in binary by making the most significant bit (MSB) a sign
bit, which will tell us whether the number is positive or negative. The column headings for an 8
bit number will look like this:

!"##$%$&'$()$*+$$&(,&"*-(
MUHAMMAD ALI KHAN
PAGE 5

!"#$%&%'()&*)+*,(-(*./*,($)**0*1!"#"$%&'()*+&,-./&)00&12&34(&3"'(5&6!"01$%&
'()*+&6,---%&'784&12&34(&3"'(9&#73&34(:(&"+&34(&;13(*3")0&21:&
81*27+"1*&<4(*&=17&>(3&31&34(&"*3(:+(83"1*&12&+31:)>(?*(3<1:!"*>?
)*@&')"*&'('1:=9&<4(*&6!"01$%&"+&+1'(3"'(+&'()*3&31&'()*&6,-./%&
)*@&34"+&"+&0):>(0=&@7(&31&4"+31:"8)0&0)*>7)>(&7+)>(5&ABC&"+&3=;"8)00=&
@(+8:"#(@&<"34&34(&#"*):=&7+)>(D&)&6!"01#=3(&12&ABC%&"+&,-./&E9&#73&)&
!"01#=3(&12&FG&"+&3=;"8)00=&,---&E9&#73&+1'(&H'1+3IJ&KLM+&7+(&34(&
#"*):=&7+)>(+&<4(*&34(=&:(2(:&31&34"*>+&0"!(&2"0(&+"N(+&)*@&2:((&+;)8(5

F"+31:"8)00=9&34(&81';73(:&+8"(*3"+3+&#7"0@"*>&4):@<):(&)*@&'('1:=&
217*@&"3&()+"(+3&)*@&'1+3&81*O(*"(*3&31&817*3&34"*>+&"*&#"*):=&+"*8(&
34(=&<(:(&)837)00=&7+"*>&#"*):=&)3&)&01<&0(O(05&L"*8(&&.,-&&P,-./&"+&
;:(33=&801+(&31&&,-Q&9&34(&210!+&8:()3"*>&34(&4):@<):(?'('1:=&
)@@:(++"*>&)@1;3(@&34(&6!"01$%&;:(2"R&31&'()*&,-./&#=3(+&)*@&
6'(>)%&31&#(&&..-&&P,9-/S9TUV&"+&+3"00&;:(33=&801+(&31&&,-V&5
MUHAMMAD ALI KHAN
PAGE 6

The Standard ASCII Character Set


Bytes are frequently used to hold individual characters in a text document. In the ASCII
character set, each binary value between 0 and 127 is given a specific character. Most
computers extend the ASCII character set to use the full range of 256 characters available in a
byte. The upper 128 characters handle special things like accented characters from common
foreign languages.
You can see the 127 standard ASCII codes below. Computers store text documents, both on
disk and in memory, using these codes. For example, if you use Notepad in Windows OS to
create a text file containing the words, "Four score and seven years ago," Notepad would use 1
byte of memory per character (including 1 byte for each space character between the words --
ASCII character 32). When Notepad stores the sentence in a file on disk, the file will also
contain 1 byte per character and per space.
Try this experiment: Open up a new file in Notepad and insert the sentence, "Four score and
seven years ago" in it. Save the file to disk under the name getty.txt. Then use the explorer and
look at the size of the file. You will find that the file has a size of 30 bytes on disk: 1 byte for
each character. If you add another word to the end of the sentence and re-save it, the file size
will jump to the appropriate number of bytes.
Each character consumes a byte.
If you were to look at the file as a computer looks at it, you would find that each byte contains
not a letter but a number -- the number is the ASCII code corresponding to the character (see
below). So on disk, the
MUHAMMAD ALI KHAN
PAGE 7

uses between 8 and 32 bits per character, so it can represent characters from
languages from all around the world. It is commonly used across the internet. As it is
larger than ASCII, it might take up more space when saving documents.
Global companies, like Facebook and Google, would not use the ASCII character set
because their users communicate in many different languages.
MUHAMMAD ALI KHAN
PAGE 8

!"#$%&'()*+*',+-".$/'0!(,12'
3).+'#4.5+%6'$%+'#)7'8%)8+%'#4.5+%6'5+-$46+'79+&'*)#:7'5+9$;+'/"<+'#4.5+%6='>'5$%-)*+'
?)%'-9)-)/$7+'/))<6'/"<+'$'#4.5+%@'$#*'$'5$%-)*+'?)%'68)#A+'-$<+'/))<'/"<+'$'#4.5+%@'547'"?'
79+'5$%-)*+6'$%+'$**+*'7)A+79+%'79+'%+64/7'"6'#)7'79+'5$%-)*+'?)%'-9)-)/$7+'-$<+='B9+'
$%"79.+7"-'*)+6'#)7'A";+'$'6+#6"5/+'$#6C+%='
D$/4+6'/"<+'79"6'79$7'/))<'/"<+'#4.5+%6'547'*)'#)7'5+9$;+'/"<+'79+.'$%+')?7+#'67)%+*'"#'5"#$%&'
-)*+*'*+-".$/'0!(,1='E$-9'*"A"7'"6'6".8/&'-9$#A+*'"#7)'$'?)4%'5"7'5"#$%&'#4.5+%'C9"-9'$%+'
79+#'8/$-+*'$?7+%')#+'$#)79+%'"#')%*+%='
+=A='FGHIJK'"#'!(,
>#6C+%2'F'L'JJMM'G'L'MJJM
H'L'MJJJ'I'L'JMMJ
J'L'JJJJ'K'L'JJMJ
3)'FGHIJK'L'JJMMMJJMMJJJJMMJJJJJJJMJ'0"#'!(,1
N)7+2'>//'79+'O+%)6'$%+'+66+#7"$/')79+%C"6+'&)4'-$#:7'%+$*'"7'5$-<=

>88/"-$7")#'
B9+'!PQ3'"#'.$#&'8+%6)#$/'-).847+%6'67)%+6'79+'*$7+'$#*'7".+'"#'!(,'5+-$46+'79+'R(IHMH'
%+$/S7".+'-/)-<'-9"8'46+*'"#'79+')%"A"#$/'P!R'T('>B'.)79+%5)$%*'8%);"*+*'79+'7".+'+#-)*+*'
"#'!(,='B9"6'?)%.'"6'+$6"/&'-)#;+%7+*'"#7)'>3(PP'?)%'*"68/$&='
B9+'>7$%"'HS5"7'?$."/&')?'-).847+%6'46+*'!(,'7)'".8/+.+#7'?/)$7"#AS8)"#7'$/A)%"79.6='B9+'
RQ3'IUJK'8%)-+66)%'46+*'9$6'$'!(,'.)*+'79$7'$??+-76'79+'$**"7")#'$#*'6457%$-7")#'
"#67%4-7")#6='E$%/&'.)*+/6')?'79+'T/$&37$7")#'F'67)%+'79+'*$7+'$#*'7".+'"#'!(,='B9"6'/+*'7)'$'
C)%/*C"*+')47$A+')?'79+'-)#6)/+')#'M'R$%-9'KJMJ='B9+'/$67'7C)'*"A"76')?'79+'&+$%'67)%+*'$6'
!(,'C+%+'."6"#7+%8%+7+*'$6'MI'-$46"#A'$#'+%%)%'"#'79+'4#"7V6'*$7+@'%+#*+%"#A'.)67'?4#-7")#6'
"#)8+%$5/+='B9"6'9$6'5++#'%+?+%%+*'7)'$6'79+'W+$%'KJMJ'T%)5/+.='

!"#$%&'()*+*',+-".$/'0!(,1'!"#$
%&'()*+'!"#$'$,!)'#$!*-,.'#*/*('*+'0$10$+$&($#'23','452*('2*&,03'&6-2$07'
89:'*+',';,3'("'$<10$++'$,!)'"='()$'#$!*-,.'#*/*(+';*()','2*&,03'!"#$7'%&'
()$'89:>';*()'="60'2*(+';$'!,&'0$10$+$&('+*<($$&'&6-2$0+'?@@@@'("'
AAAAB7'86('*&'89:'!"#$'"&.3'=*0+('($&'"='()$+$',0$'6+$#'?@@@@'("'A@@AB7'
C)$'0$-,*&*&/'+*<'!"#$'!"-2*&,(*"&+'*7$7'A@A@'("'AAAA',0$'*&D,.*#'*&'89:7
PAGE 9

MUHAMMAD ALI KHAN


PAGE 10

MUHAMMAD ALI KHAN


PAGE 11

MUHAMMAD ALI KHAN


PAGE 12

MUHAMMAD ALI KHAN


PAGE 13

MUHAMMAD ALI KHAN


PAGE 14

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 15

!"#$%&'()(*(
!"#$%&'&()*+'#*+',("-.%&&!(*'

+,(-#.
PAGE 16

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 17

Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023.

1.2 Multimedia
Graphics
Candidates should be able to: Notes and guidance
Show understanding of how data for a bitmapped Use and understand the terms: pixel, file header,
image are encoded image resolution, screen resolution, colour depth, bit
depth
Perform calculations to estimate the file size for a
bitmap image
Show understanding of the effects of changing Use the terms: image resolution, colour depth
elements of a bitmap image on the image quality and
file size
Show understanding of how data for a vector graphic Use the terms: drawing object, property, drawing list
are encoded
Justify the use of a bitmap image or a vector graphic
for a given task

Sound
Candidates should be able to: Notes and guidance
Show understanding of how sound is represented and Use the terms: sampling, sampling rate, sampling
encoded resolution, analogue and digital data
Show understanding of the impact of changing the Impact on file size and accuracy
sampling rate and resolution

1.3 Compression
Candidates should be able to: Notes and guidance
Show understanding of the need for and examples of
the use of compression
Show understanding of lossy and lossless compression
and justify the use of a method in a given situation
Show understanding of how a text file, bitmap image, Including the use of run-length encoding (RLE)
vector graphic and sound file can be compressed
MUHAMMAD ALI KHAN
PAGE 18

!"#$%&'(!)"#*'#+,'-%.)/0

Graphic images that have been processed by a computer can usually be divided into two
distinct categories. Such images are either bitmap files or vector graphics. This section will
cover the two main image types: vector and bitmap, along with some compression techniques.

Bitmap Graphics U31T

Bitmaps images are exactly what their name says they are: a collection of bits that form an
image. The image consists of a matrix of individual dots (or pixels) that all have their own color
(described using bits, the smallest possible units of information for a computer).
Let’s take a look at a typical bitmap image to demonstrate the principle:

Pixel
The smallest possible addressable area defined by a solid color, represented as binary, in an
31TU! U31T

image

Resolution
Image Resolution - how many pixels does an image contains per inch/cm? The more pixels
31TU U31T

used to produce an image the more detailed that image can be i.e. the higher its resolution. For
MUHAMMAD ALI KHAN
PAGE 19

instance a 10 Megapixel digital camera makes use of over 10 million pixels per image thus
offering a very high photographic quality.

Screen Resolution - The screen resolution tells you how many pixels your screen can display
31TU U31T

horizontally and vertically. It's written in the form 1024 x 768. In this example, the screen can
show 1,024 pixels horizontally, and 768 vertically:

Color depth - The number of bits used to represent the color of a single pixel
U031T 31T31T 0T

Bitmap file header:


This block of bytes is at the start of the file and is used to identify the file. A typical application
reads this block first to ensure that the file is actually a BMP file and that it is not damaged.

What Are File Headers?


U

Many file types can be identified by using what’s known as a file header. A file header is a
‘signature’ placed at the beginning of a file, so the operating system and other software know
what to do with the following contents.
Many electronic discovery applications (computer programs) will use the file header as a means
to verify file types. The common fear is if a user changes a files extension or the file wasn’t
named using an applications default naming convention, that file will lose its association with the
program that created it.
For example, if you create a Microsoft Word document and name it ‘myfile.001’, instead of
‘myfile.doc’ and then attempt to locate all Microsoft Word files at a later date, you would miss
the file if you were looking for all files ending in ‘.doc’. There are specific file extensions
associated with the native application.

Estimating file size of bitmapped image of different resolutions


File size of a black white image
A black and white image has two dimensions that need to be considered the number of
pixels in the horizontal plane multiplied number of pixels along the vertical axis. Note that a
black and white image is not grey scale.
Example
The formula is:
File size = horizontal pixels × vertical pixels × bit depth -------------------------------------------
8(to convert to bytes) × 1024 (kilobytes)
This image has the properties of 208 pixels wide by 182 pixels high. The file size in bits can
then be worked out by multiplying horizontal pixels by vertical pixels.
file size = 208 × 182 x 1 8 × 1024
= 37856 ------ 8192 = 4.62 KB

Vector Graphics - images defined using mathematics and geometry such as points, lines,
U0T31T 0T

curves, and shapes or polygon(s). Allowing for scalability. Objects and properties stored
mathematically.

Drawing list - a set of commands used to define a vector image


0T 0T

Drawing objects and properties - Vector graphics are made up of objects and their properties.
An object is
a mathematical or geometrically defined construct such as a rectangle, line or circle.
<rect ... />
40T 40T 43T 41T43T
MUHAMMAD ALI KHAN
PAGE 20

31T

Comparison between vector and bitmaps


MUHAMMAD ALI KHAN
PAGE 21

1. Vector images scale without file size increase / decrease


2. Bitmap images scale resulting in file size increase / decrease
3. Vector images scale without distortion to the image
4. Bitmap images distort (pixelate) when scaling
5. Bitmaps are better for photo editing
6. Bitmaps require less processing power to display

Justification for using Bitmaps (Also Known As Raster Graphics)


Raster graphics have inherently unique characteristics that can’t be created inside Flash. The
only
warning related to using this option is to make sure you really need raster graphics. The
following are some cases that justify the use of raster graphics:
A photograph. The only time to consider using a vector alternative to a photograph is when the
picture is of a very geometric object. Otherwise, photographs should be raster graphics.
A series of still images extracted from frames of a short video.
An image with special effects that can’t be achieved by using a vector tool, such as clouds, fire,
water, and other natural effects.
If you’re unfamiliar with the difference between vector graphics and raster graphics, learning
when one choice is better than the other can take some time. The file formats .gif, .jpg, .png,
.bmp, and .pct are all raster graphics formats. However, just because a file was saved in one of
these formats doesn’t mean it was done appropriately. It’s the nature of the image in the file that
matters. If all you have is a .gif, for example, you need to first look at its contents to judge
whether it’s appropriate for raster graphics. Here’s an easy way to decide: If you can trace or
redraw the image in the file, you’re much better off redrawing it.
If it’s a photograph, you would never be able to trace it (so leave it as a raster graphic). If it’s a
picture of a plain box, maybe you could draw it and thus take advantage of all the benefits of
vector graphics without even bothering with raster graphics.
MUHAMMAD ALI KHAN
PAGE 22

Analogue and digital


For a computer to store sound files we need to get the continuous analogue sound waves into
discrete binary values:

Analogue to Digital Converter (ADC) - Converts analogue sound into digital signals that can
be stored on a computer
Digital to Analogue Converter (DAC) - Converts digital signals stored on a computer into
analogue sound that can be played through devices such as speakers

Sound Sampling
So we should know by now that sound waves are continuous and computers can only store
discrete data.
How exactly does an Analogue to Digital Converter convert a continuous sound wave into
discrete digital data? To do this we need to look at how computers sample sound.
Sampling Rate - The number of samples taken per second
31TU U0T31T 0T

Hertz (Hz) - the SI unit of frequency defined as the number of cycles per second of a periodic
31TU U0T31T 0T

phenomenon

31TU Sampling resolution - the number of bits assigned to each sample


U0T31T 0T
MUHAMMAD ALI KHAN
PAGE 23

As you saw earlier, different sounds can have different volumes. The sampling resolution allows
you to set the range of volumes storable for each sample. If you have a low sampling resolution
then the range of volumes will be very limited, if you have a high sampling resolution then the
file size may become unfeasible. The sampling resolution for a CD is 16 bits used per sample.

31TU Bit rate - the number of bits required to store 1 second of sound
U0T31T 0T

To work out the size of a sound sample requires the following equation:

File Size = Sample Rate * Sample Resolution * Length of sound

Sound Editing
If you are interested in sound editing you can start editing your own music using a program
called Audacity . Using Audacity you can create your own sound samples with different sample
0T 0T 31TU U 31T

rates and sample resolutions, listening to the difference between them and noting the different
file sizes.

Features
This is a list of features in Audacity, the free, open source, cross-platform audio editor.
Recording
Audacity can record live audio through a microphone or mixer, or digitize recordings from 0T 0T31TU

cassette tapes, records or minidiscs . With some sound cards, and on any Windows Vista,
U31T

Windows 7 or Windows 8 machine, Audacity can also capture streaming audio 0T 0T31TU U31T

Editing
1. Easy editing with Cut, Copy, Paste and Delete.
2. Unlimited sequential Undo (and Redo) to go back any number of steps.
3. Edit and mix large numbers of tracks.
4. Multiple clips are allowed per track.0T 0T31TU U0T 31T 0T

5. Label tracks with selectable Sync-Lock Tracks feature for keeping tracks and labels
31TU U0T31T 0T 0T 0T 31TU U0T31T 0T

synchronized.
6. Draw Tool to alter individual sample points.
7. Envelope Tool to fade the volume up or down smoothly.
31TU U0T31T 0T

8. Automatic Crash Recovery in the event of abnormal program termination


MUHAMMAD ALI KHAN
PAGE 24

Effects

1. Change the pitch without altering the tempo (or vice-versa).


2. Remove static, hiss, hum or other constant background noises.
3. Alter frequencies with Equalization, Bass and Treble, High/Low Pass and Notch Filter
effects.
4. Adjust volume with Compressor, Amplify, Normalize, Fade In/Fade Out and Adjustable
Fade effects.
5. Remove Vocals from suitable stereo tracks.
31TU U0T 31T 0T

6. Create voice-overs for podcasts or DJ sets using Auto Duck effect


0T 0T31TU U0T31T 0T
MUHAMMAD ALI KHAN
PAGE 25

Run-length encoding (RLE) is a very simple form of lossless data compression in which runs of
data (that is, sequences in which the same data value occurs in many consecutive data elements)
are stored as a single data value and count, rather than as the original run. This is most useful on
data that contains many such runs. Consider, for example, simple graphic images such as icons, line
drawings, and animations. It is not useful with files that don't have many runs as it could greatly
increase the file size.

For example, consider a screen containing plain black text on a solid white background. There will
be many long runs of white pixels in the blank space, and many short runs of black pixels within the
text. A hypothetical scan line, with B representing a black pixel and W representing white, might read
as follows:
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW

With a run-length encoding (RLE) data compression algorithm applied to the above hypothetical
scan line, it can be rendered as follows:
12W1B12W3B24W1B14W
PAGE 26

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 27

!"#$%&'(')*)'"+, ')-.
%"+&/%/"#$%
'(*0'+*)'"+1
MUHAMMAD ALI KHAN
PAGE 28

Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content

2 Communication
2.1 Networks including the internet
Candidates should be able to: Notes and guidance
Show understanding of the purpose and benefits of
networking devices
Show understanding of the characteristics of a LAN
(local area network) and a WAN (wide area network)
Explain the client-server and peer-to-peer models of Roles of the different computers within the network
networked computers and subnetwork models
Benefits and drawbacks of each model
Justify the use of a model for a given situation
Show understanding of thin-client and thick-client
and the differences between them
Show understanding of the bus, star, mesh and hybrid Understand how packets are transmitted between
topologies two hosts for a given topology
Justify the use of a topology for a given situation
Show understanding of cloud computing Including the use of public and private clouds.
Benefits and drawbacks of cloud computing
Show understanding of the differences between and Describe the characteristics of copper cable, fibre-
implications of the use of wireless and wired networks optic cable, radio waves (including WiFi), microwaves,
satellites
Describe the hardware that is used to support a LAN Including switch, server, Network Interface Card
(NIC), Wireless Network Interface Card (WNIC),
Wireless Access Points (WAP), cables, bridge, repeater
Describe the role and function of a router in a network
Show understanding of Ethernet and how collisions Including Carrier Sense Multiple Access / Collision
are detected and avoided Detection (CSMA / CD)
Show understanding of bit streaming Methods of bit streaming, i.e. real-time and
on-demand
Importance of bit rates / broadband speed on bit
streaming
Show understanding of the differences between the
World Wide Web (WWW) and the internet
Describe the hardware that is used to support the Including modems, PSTN (Public Switched Telephone
internet Network), dedicated lines, cell phone network
PAGE 29

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 30

!"#$%&#&$'()*&%#+,-'.#/#0$1*2/-*/#"*%0,-3#45678#$&#/#9,))*9%$,"#,+#),9/)2/-*/#"*%0,-3&#4:67&8#,-#
,%;*-#"*%0,-3&#%;/%#9,''<"$9/%*#0$%;#,"*#/",%;*-=##6#567#$&#*&&*"%$/))>#/#"*%0,-3#,+#"*%0,-3&.#
0$%;#%;*#!"%*-"*%#%;*#0,-)1?&#)/-@*&%#567=

A,1/>.#%;*-*#/-*#&*B*-/)#%>(*&#,+#567&.#C<$)%#+,-#/#B/-$*%>#,+#<&*#9/&*&#%;/%#%,<9;#B$-%</))>#*B*->#
/&(*9%#,+#',1*-"#)$+*=D,0#1$1#0$1*2/-*/#"*%0,-3$"@#&%/-%E
A;*#+$-&%#3",0"#567#0/&#9-*/%*1#C>#%;*#F=G=#6$-#H,-9*#$"#%;*#)/%*#IJKL&#%,#$"%*-9,""*9%#&$%*&#$"#
%;*#G*'$26<%,'/%$9#M-,<"1#N"B$-,"'*"%#4G6MN8#-/1/-#1*+*"&*#&>&%*'=#6"#*",-',<&#"*%0,-3#,+#
1*1$9/%*1#(;,"*#)$"*&.#%*)*(;,"*&.#/"1#',1*'&#)$"3*1#%;*#&$%*&#%,@*%;*-=
A;*#+,<"1/%$,"#,+#%;*#!O2C/&*1#!"%*-"*%#&%/-%*1#0$%;#%;*#61B/"9*1#P*&*/-9;#O-,Q*9%&#6@*"9>#
7*%0,-3#46PO67NA8.#%;*#+$-&%#0$1*2/-*/#(/93*%2&0$%9;$"@#"*%0,-3#0$%;#1$&%-$C<%*1#9,"%-,)#/"1#
%;*#+$-&%#"*%0,-3#%,#$'()*'*"%#AROS!O#(-,%,9,)#&<$%*=
6PO67NA#$"$%$/))>#$"%*-9,""*9%*1#%;*#F"$B*-&$%>#,+#R/)$+,-"$/.#:,&#6"@*)*&#4FR:68.#%;*#G%/"+,-1#
P*&*/-9;#!"&%$%<%*#4",0#GP!#!"%*-"/%$,"/)8.#%;*#F"$B*-&$%>#,+#R/)$+,-"$/.#G/"%/#T/-C/-/#4FRGT8.#/"1#
%;*#F"$B*-&$%>#,+#F%/;=
!"#$%&'%#%!()%*+,$-*.
6#567#-,<%*-.#/)&,#3",0"#/&#/"#*1@*#-,<%*-#,-#C,-1*-#-,<%*-#$&#/#1*B$9*#%;/%#-,<%*&#1/%/#(/93*%&#
C*%0**"#567#),9/%$,"&.#@$B$"@#/"#*"%*-(-$&*#/99*&&#%,#/#9/--$*-#"*%0,-3=##G*B*-/)#567#(-,%,9,)&#
;/B*#C**"#1*B*),(*1#,B*-#%$'*.#$"9)<1$"@#O/93*%#,B*-#GU7NASGVD#4O,G8.#W<)%$(-,%,9,)#:/C*)#
G0$%9;$"@#4WO:G8.#6AW.#/"1#H-/'*#P*)/>=

5;/%#$&#&,+%0/-*21*+$"*1#567#4GV25678E
G,+%0/-*21*+$"*1#567#4GV25678#$&#/"#/((-,/9;#+,-#'/3$"@#567#/-9;$%*9%<-*&#*/&$*-#%,#1*(),>.#
,(*-/%*.#/"1#'/"/@*=#!%#-*)$*&#,"#B$-%</)$X/%$,".#/(()$9/%$,"2)*B*)#(,)$9$*&#/"1#,B*-)/>#"*%0,-3&.#
/"1#,"&$%*#GV2567#1*B$9*&#/"1#&,+%0/-*#()/%+,-'&=
GV2567#$"9-*/&*&#1/%/2%-/"&+*-#*++$9$*"9$*&#/9-,&&#/#567#C>#',B$"@#%-/++$9#%,#),0*-29,&%#
"*%0,-3#)$"3&#%,#1,#%;*#0,-3#,+#',-*2*Y(*"&$B*#)*/&*1#,-#WO:G#)$"*&=#

5;/%#$&#567#,(%$'$X/%$,"E
:/%*"9>#/"1#C/"10$1%;#9,"&%-/$"%&#,+%*"#9/<&*#(*-+,-'/"9*#$&&<*&#$"#*"%*-(-$&*#567&=#567#
,(%$'$X/%$,"#<&*#/#B/-$*%>#,+#%*9;"$Z<*&.#$"9)<1$"@#1*1<()$9/%$,".#9,'(-*&&$,".#(-,%,9,)#
,(%$'$X/%$,".#%-/++$9#&;/($"@.#/"1#),9/)#9/9;$"@=#A;*&*#%*9;"$Z<*&#$'(-,B*#(/93*%#1*)$B*->#/"1#
%-/++$9#9,"%-,).#$"#%<-"#/)),0$"@#"*%0,-3#C/"10$1%;#%,#@-,0#,-#&;-$"3#1>"/'$9/))>#/&#"**1*1=
GV2567#%*9;",),@>#/"1#567#,(%$'$X/%$,"#9/"#C*#<&*1#&*(/-/%*)>#,-#%,@*%;*-=#G,'*#GV2567#
B*"1,-&#/-*#/11$"@#567#,(%$'$X/%$,"#+*/%<-*&#%,#%;*$-#(-,1<9%&

A>(*&#,+#567#%*9;",),@$*&
O/93*%#&0$%9;$"@
O/93*%#&0$%9;$"@#$&#/#'*%;,1#,+#1/%/#%-/"&'$&&$,"#$"#0;$9;#/#'*&&/@*#$&#C-,3*"#$"%,#&*B*-/)#(/-%&.#
9/))*1#(/93*%&.#%;/%#/-*#&*"%#$"1*(*"1*"%)>.#$"#%-$()$9/%*.#,B*-#0;/%*B*-#-,<%*#$&#,(%$'<'#+,-#*/9;#
(/93*%.#/"1#-*/&&*'C)*1#/%#%;*#1*&%$"/%$,"=#N/9;#(/93*%#9,"%/$"&#/#($*9*#(/-%.#9/))*1#%;*#(/>),/1.#
/"1#/"#$1*"%$+>$"@#;*/1*-#%;/%#$"9)<1*&#1*&%$"/%$,"#/"1#-*/&&*'C)>#$"+,-'/%$,"=#A;*#(/93*%&#/-*#
&*"%#$"#%-$()$9/%*#%,#9;*93#+,-#(/93*%#9,--<(%$,"=#NB*->#(/93*%#$&#B*-$+$*1#$"#/#(-,9*&&#%;/%#
9,'(/-*&#/"1#9,"+$-'&#%;/%#/%#)*/&%#%0,#9,($*&#'/%9;=#5;*"#B*-$+$9/%$,"#+/$)&.#/#-*Z<*&%#$&#'/1*#
+,-#%;*#(/93*%#%,#C*#-*2&*"%=
PAGE 31

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 32

!"#$%&'($)*$)+,-.$"

!"#$%&'#()*+#,-#,$./0#&$'+$1$0'+),'23)#0$144&'51)'/($+),35)3,#$)"1)$41,)')'/(+$)1+6$/,$
7/,6&/10$2#)7##($)"#$4,/-'0#,+$/8$1$,#+/3,5#$/,$+#,-'5#9$51&&#0$+#,-#,+9$1(0$+#,-'5#$
,#:3#+)#,+$51&&#0$5&'#()+;$<($)"#$5&'#()*+#,-#,$1,5"')#5)3,#9$7"#($)"#$5&'#()$5/.43)#,$+#(0+$
1$,#:3#+)$8/,$01)1$)/$)"#$+#,-#,$)",/3="$)"#$'()#,(#)9$)"#$+#,-#,$155#4)+$)"#$,#:3#+)#0$
4,/5#++$1(0$0#&'-#,$)"#$01)1$4156#)+$,#:3#+)#0$2156$)/$)"#$5&'#();$%&'#()+$0/$(/)$+"1,#$1(>$
/8$)"#',$,#+/3,5#+;[email protected]&#+$/8$%&'#()*A#,-#,$B/0#&$1,#$?.1'&9$C/,&0$C'0#$C#29$#)5;

/-0+&1$+!"#$%&'($)*$)+,-.$"+0-)23+4
<($)"'+$1,)'5&#$7#$1,#$=/'(=$)/$)16#$1$0'-#$'()/$)"#$%&'#()*A#,-#,$./0#&$1(0$"1-#$1$&//6$1)$
"/7$)"#$<()#,(#)$7/,6+$-'19$7#2$2,/7+#,+;$!"'+$1,)'5&#$7'&&$"#&4$3+$'($"1-'(=$1$+/&'0$
8/3(01)'/($/8$)"#$C?D$1(0$"#&4$'($7/,6'(=$7')"$C?D$)#5"(/&/='#+$7')"$#1+#;

!"#$%&5+C"#($7#$)1&6$)"#$7/,0$%&'#()9$')$.#1($)/$)1&6$/8$1$4#,+/($/,$1($/,=1('E1)'/($3+'(=$1$
41,)'53&1,$+#,-'5#;$A'.'&1,&>$'($)"#$0'=')1&$7/,&0$1$%&'#()$'+$1$5/.43)#,$FG/+)H$';#;$51412&#$/8$
,#5#'-'(=$'(8/,.1)'/($/,$3+'(=$1$41,)'53&1,$+#,-'5#$8,/.$)"#$+#,-'5#$4,/-'0#,+$FA#,-#,+H;
($)*$)35+A'.'&1,&>9$7"#($7#$)1&6$)"#$7/,0$A#,-#,+9$<)$.#1($1$4#,+/($/,$.#0'3.$)"1)$
+#,-#+$+/.#)"'(=;$A'.'&1,&>$'($)"'+$0'=')1&$7/,&0$1$A#,-#,$'+$1$,#./)#$5/.43)#,$7"'5"$
4,/-'0#+$'(8/,.1)'/($F01)1H$/,$155#++$)/$41,)'53&1,$+#,-'5#+;
A/9$')+$21+'51&&>$)"#$%&'#()$,#:3#+)'(=$+/.#)"'(=$1(0$)"#$A#,-#,$+#,-'(=$')$1+$&/(=$1+$')+$
4,#+#()$'($)"#$01)121+#;

!"#$%&$'()*+,*-./(%&01(2#(2*3+"(.4

!"#$%&'()"*+,-,$".+/($0+&''+*&$&+(#+&+,(#1'"+2'&3"4
!5,$+"66(3("#$+%"78(%",+'",,+.&(#$"#&#3"+35,$+&#*+9&$&+%"35:"%-+(,+25,,(;'"4
<0"+3&2&3($-+56+$0"+!'("#$+&#*+="%:"%,+3&#+;"+30&#1"*+,"2&%&$"'-4
5/)$"#$%&$'()*+,*-./(%&01(2#(2*3+"(.4

!'("#$,+&%"+2%5#"+$5+:(%8,",>+<%5?&#,+&#*+/5%.,+(6+2%","#$+(#+$0"+="%:"%+5%+82'5&*"*+(#$5+
$0"+="%:"%4
="%:"%+&%"+2%5#"+$5+9"#(&'+56+="%:(3"+@9A=B+&$$&3C,4
9&$&+2&3C"$,+.&-+;"+,2556"*+5%+.5*(6("*+*8%(#1+$%&#,.(,,(5#4
D0(,0(#1+5%+3&2$8%(#1+'51(#+3%"*"#$(&',+5%+5$0"%+8,"68'+(#65%.&$(5#+56+$0"+8,"%+&%"+35..5#+
&#*+EF<E@E&#+(#+$0"+E(**'"B+&$$&3C,+&%"+35..5#4
!
PAGE 33

MUHAMMAD ALI KHAN


PAGE 34

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 35

!"#$%&"'(%)&#"%*"+"',-./#)0"#$+#"0/&*"10,-"0)*,/0')*"*#,0)2",&"+"')&#0+("*)03)0"%&*#)+2",1"+"
(,'+(%4)2"$+02"20%3)5"6$%&"'(%)&#*"7,08"9:"',&&)'#%&;"0)-,#)(:"#,"+"*)03)0<9+*)2"
',-./#%&;")&3%0,&-)&#"7$)0)"-,*#"+..(%'+#%,&*="*)&*%#%3)"2+#+="+&2"-)-,0:="+0)"!"#$%&'(
)*+,"'(%)&#*"$+3)"+"&/-9)0",1"9)&)1%#*="%&'(/2%&;>
-*."(.$%("*%(.&/.,".0%!(#1(.()*+,(23+%,"4
!"#$%&'()"*+,-
.#/&#0"*+1"02%($3
,45%67"*+5%6*20$(7($3
!61$+1&7(#81
9"46$"+:6%;+<6'2$(6#
!"#$%$&&'('$)*%+,),-$,.'/'*0
1(,/,.'/'*0

6$%&"'(%)&#"2).(,:-)&#"%*"-,0)"',*#")11)'#%3)"#$+&"2).(,:%&;"0);/(+0"?@*5"A)'+/*)"*,"
-/'$"%*"')&#0+(%4)2"+#"#$)"*)03)0<*%2)="#$%&"'(%)&#"',-./#%&;"'+&"0)2/')"B6"*/..,0#"+&2"
(%')&*%&;"',*#*5

C)'/0%#:"'+&"9)"%-.0,3)2"#$0,/;$")-.(,:%&;"#$%&"'(%)&#*"9)'+/*)"#$)"#$%&"'(%)&#"%#*)(1"%*"
0)*#0%'#)2"9:"#$)"*)03)05"6$%&"'(%)&#*"'+&&,#"0/&"/&+/#$,0%4)2"*,1#7+0)="+&2"2+#+"'+&D#"9)"
',.%)2",0"*+3)2"+&:7$)0)")E').#"1,0"#$)"*)03)05"C:*#)-"-,&%#,0%&;"+&2"-+&+;)-)&#"%*"
)+*%)0"9+*)2",&"#$)"')&#0+(%4)2"*)03)0"(,'+#%,&5

6$%&"'(%)&#*"'+&"+(*,"9)"*%-.()0"#,"-+&+;)="*%&')"/.;0+2)*="*)'/0%#:".,(%'%)*="+&2"-,0)"
'+&"9)"-+&+;)2"%&"#$)"2+#+"')&#)0"%&*#)+2",1",&"#$)")&2.,%&#"-+'$%&)*5"6$%*"()+2*"#,"
()**"2,7&#%-)="%&'0)+*%&;".0,2/'#%3%#:"+-,&;"B6"*#+11"+*"7)(("+*")&2.,%&#"-+'$%&)"/*)0*5
MUHAMMAD ALI KHAN
PAGE 36

!"#$%&'(#)*+,
!"#$%&$'#()*+,&-'+.&$-''(/&"(-01&$'#()*+,&-2(&34''53(-*42(/&$.674*(2+&*"-*&-2(&$.))($*(/&*.&
-&)(*8.2%9&:)'#%(&*"#)&$'#()*+,&8"#$"&'-$%&"-2/&/2#0(+&-)/&.*"(2&3(-*42(+,&*"#$%&$'#()*+&-2(&
34)$*#.)-'&8"(*"(2&*"(1&-2(&$.))($*(/&*.&-&)(*8.2%&.2&).*9

;"#'(&-&*"#$%&$'#()*&#+&34''1&34)$*#.)-'&8#*".4*&-&)(*8.2%&$.))($*#.),&#*&#+&.)'1&-&<$'#()*<&
8"()&#*&#+&$.))($*(/&*.&-&+(20(29&!"(&+(20(2&6-1&72.0#/(&*"(&*"#$%&$'#()*&8#*"&72.=2-6+&
-)/&3#'(+&*"-*&-2(&).*&+*.2(/&.)&*"(&'.$-'&6-$"#)(>+&"-2/&/2#0(9&?*&#+&).*&4)$.66.)&3.2&
8.2%7'-$(+&*.&72.0#/(&*"#$%&$'#()*+&*.&*"(#2&(67'.1((+9&!"#+&()-@'(+&*"(6&*.&-$$(++&3#'(+&
.)&-&'.$-'&+(20(2&.2&4+(&*"(&$.674*(2+&.33'#)(9&;"()&-&*"#$%&$'#()*&#+&/#+$.))($*(/&32.6&
*"(&)(*8.2%,&#*&#+&.3*()&2(3(22(/&*.&-+&-&8.2%+*-*#.)9
PAGE 37

MUHAMMAD ALI KHAN


PAGE 38

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 39

!"#$%&'#%()(*(+,#-&./#0-12.-#2"#%/-#"-%3('4#2$#.(""-.%-0#%(#
&#.-"%'&*#0-12.-#.&**-0#/567#8"*24-#9-$/#%()(*(+,:#$%&'#%()(*(+,#0(-$";%#&**(3#02'-.%#
.(<<5"2.&%2("#6-%3--"#0-12.-$:#&#0-12.-#<5$%#/&1-#%(#.(<<5"2.&%-#%/'(5+/#/567#
!=#("-#0-12.-#3&"%$#%(#$-"0#0&%&#%(#(%/-'#0-12.-:#2%#/&$#%(#=2'$%#$-"0#%/-#0&%&#%(#/56#
&"0#%/-"#%/-#/56#%'&"$<2%#%/&%#0&%&#%(#%/-#0-$2+"&%-0#0-12.-7

!"#$%&$'()*+,*-&$.*&+/+0+'1
>7 ?-$$#-@)-"$21-#6-.&5$-#-&./#0-12.-#("*,#"--0#("-#!AB#)('%#&"0#"--0$#%(#6-
.(""-.%-0#32%/#/56#32%/#("-#*2"47
C7 D&$2-'#%(#2"$%&**
E7 ?-$$#&<(5"%#(=#.&6*-$#'-F52'-0#6-.&5$-#-&./#0-12.-#"--0$#%(#6-#.(""-.%-0
32%/#%/-#/56#("*,7
G7 H(65$%:#2=#("-#*2"4#=&2*$:#(%/-'#*2"4$#32**#3('4#I5$%#=2"-7
J7 D&$,#=&5*%#0-%-.%2("#6-.&5$-#%/-#*2"4#.&"#6-#-&$2*,#20-"%2=2-07
MUHAMMAD ALI KHAN
PAGE 40

!"#$%&'&(&)*
!"#$%&#'()(*(+,#'-./.#0&#1#210"#31$*.#1"4#1**#'-.#4.503.&#1/.#3("".3'.4#'(#'-0&#210"#
31$*.#'-/(%+-#4/()#*0".&6#7-./.#0&#1#4.503.#31**.4#'1)#'-1'#3("".3'&#'-.#4/()#*0".#'(#
'-.#210"#31$*.6#80"3.#1**#'-.#41'1#0&#'/1"&20''.4#(5./#'-.#210"#31$*.9#'-./.#0&#1#*020'#(:#
4/()#*0".&#1"4#'-.#40&'1"3.#1#210"#31$*.#31"#-15.6

;451"'1+.&#(:#$%&#'()(*(+,
<6 =1&,#0"&'1**1'0("9#.13-#31$*.#"..4&#'(#$.#3("".3'.4#>0'-#$13?$(".#31$*.6
@6 A.&&#31$*.&#/.B%0/.4#'-1"#C.&-#1"4#&'1/#'()(*(+,

D0&1451"'1+.&#(:#$%&#'()(*(+,
<6 D0::03%*'*,#0"#:1%*'#4.'.3'0("6
@6 E('#&31*1$*.#1&#'-./.#0&#1#*020'#(:#-(>#21",#"(4.&#,(%#31"#3("".3'#>0'-#$13?$(".
31$*.6
PAGE 41

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 42

!"#$%&'()*)+),"
PAGE 43

MUHAMMAD ALI KHAN


PAGE 44

MUHAMMAD ALI KHAN


PAGE 45

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 46

!"#$%&$'()*

!"#$%&'()*'*+,",&-+.
/00*##&1&)&,$
2-#,%(*3%4*"5.
6)*7&1&)&,$%8-3%93-:,4.
!88&0&*+,%3*0-;*3$.

+,)$"#$%&$'()*-
<-%)-+9*3%&+%0-+,3-)
="$%+-,%9*,%"))%,4*%8*",>3*#.
?-*#+@,%'*"+%$->%#4->)5%5-%":"$%:&,4%#*3;*3#.
<-%A*5>+5"+0$.
B"+5:&5,4%&##>*#.
MUHAMMAD ALI KHAN
PAGE 47

Benefits and drawbacks of using copper cables, fiber optic, radio waves, microwaves nd satellites

Copper cables

Common types are coaxial cable and twisted pair or unshielded twisted pair(UTP)

Advantages

"! Least expensive media for transmission for short distances!


" Can be used for both analogue and digital data transmission!

Disadvantages

"! More chances of electromagnetic interferences!


" Can’t be used for long distance communication!

Fiber optics

Consist of a large number of very fine glass strands down which pulses of light can be sent

Advantage

" Because means of communication is light rather than electrical signal, the data will remain
inference
! free!
"! They are also very difficult to hack into!
"! The cables do not corrode!
" They have much greater bandwidth than metal cables!

Disadvantages

"! Expensive to install but last longer than copper cables!


"! Can be broken or have transmission loses when wrapped around only a few centimeters!
" Requires more protections around the cable compared to copper!
MUHAMMAD ALI KHAN
PAGE 48

Radio waves

Radio waves have lower frequencies and longer wavelengths than microwaves. They are used to
transmit television and radio programs. They cannot transmit a lot of data simultaneously because
they are low frequencyContinued exposure to large amount of radio waves can cause health problems.
Despite these setbacks these can be used to transmit information from space t earth. Its frequency
ranges from 3 kHz to 300 kHz.

They travel at the speed of light in vacuum most commonly used in mobile radio communication,
computer networks, communication satellites, radar and broadcasting.

Microwaves

Microwaves are the electromagnetic or radio waves having higher frequencies so it can carry large
quantities of data. It is highly directional and transmits data between fixed positions. Wide bandwidth.
Less power requirement .some disadvantages include expensive towers and repeaters required also
subject to interference such as air plan, rain or building can disrupt microwave.

Satellites

It is a microwave repeater in space .it is a high bandwidth, coverage over a large geographical area and
can be cheaper over long distance.disadvantes include, huge initial cost, noise and interference,
propagation delay

!"#"$

!"#$%&'()%*$'+,-)#'$,.)',/'%0)'12$"+$3'4"!"'$%256$'/,#'4"#)()$$'!"6)("%7'256'"$'%0)'$2.)'
%0"58'2$'$27"58'49:;'<0"+0'$%256$'/,#'=4"#)()$$'9,+2(':#)2';)%<,#>3=

:'<"#)()$$'5)%<,#>'?$)$'#26",'<2-)$&'@?$%'(">)'+)(('A0,5)$&'%)()-"$",5$'256'#26",$'6,3'
B5'/2+%&'+,..?5"+2%",5'2+#,$$'2'<"#)()$$'5)%<,#>'"$'2'(,%'(">)'%<,C<27'#26",'
+,..?5"+2%",53'D)#)*$'<02%'02AA)5$E

:'+,.A?%)#*$'<"#)()$$'262A%)#'%#25$(2%)$'62%2'"5%,'2'#26",'$"852('256'%#25$."%$'"%'?$"58'
25'25%)5523
:'<"#)()$$'#,?%)#'#)+)"-)$'%0)'$"852('256'6)+,6)$'"%3'F0)'#,?%)#'$)56$'%0)'"5/,#.2%",5'
%,'%0)'B5%)#5)%'?$"58'2'A07$"+2(&'<"#)6'G%0)#5)%'+,55)+%",53
F0)'A#,+)$$'2($,'<,#>$'"5'#)-)#$)&'<"%0'%0)'#,?%)#'#)+)"-"58'"5/,#.2%",5'/#,.'%0)'
B5%)#5)%&'%#25$(2%"58'"%'"5%,'2'#26",'$"852('256'$)56"58'"%'%,'%0)'+,.A?%)#*$'<"#)()$$'
262A%)#3
MUHAMMAD ALI KHAN
PAGE 49

How internet works?


When you want to send a message or retrieve information from another computer, the
TCP/IP protocols are what make the transmission possible. Your request goes out over
the network, hitting! domain name servers (DNS)! along the way to find the target
0T 0T 40T 0T40T 0T

server. The DNS points the request in the right direction.


Once the target server receives the request, it can send a response back to your
computer. The data might travel a completely different path to get back to you. This
flexible approach to data transfer is part of what makes the Internet such a powerful tool.

Communication and internet technology


Client server model of networked computers

A server provides resource or service while a client requests for service. Client and servers
communicate over a computer network on separate hardware. Clients initiate communication
sessions with servers and await incoming requests.

Examples of computer applications that use the client server model are email, network
printing and World Wide Web.

Servers are classified by the services they provide e.web servers, serve WebPages and file
server serves computer files. Client and servers exchange messages in request-response-
messaging pattern. The language and rules of communication are defined in communication
protocols.

Example:

When a bank customer accesses online banking services with a web browser (the client),it
initiates a request to bank’s web server. The customer’s login credentials may be stored in a
database, and web server accesses the database server as a client. An application server
interprets the returned data by applying the bank’s business logic and provides the output to
the web server. Finally the web server returns the result to the client web browser for
display.
MUHAMMAD ALI KHAN
PAGE 50

Definition: The term “ WWW” refers to the “ World Wide Web” or simply the Web. The
0T 0T 0T 0T 0T 0T 0T 0T 0T 0T

World Wide Web consists of all the public Web sites connected to the Internet
worldwide, including the client devices (such as computers and cell phones) that access
Web content. The WWW is just one of many applications of the
Internet and computer networks.
The World Web is based on these technologies:

HTML - Hypertext Markup Language


HTTP - Hypertext Transfer Protocol
31TU U31T

Web servers and Web browsers


MUHAMMAD ALI KHAN
PAGE 51

!"#$%&!'%(&!()&*+%&'+,(#+(,&

www is a system of interlinked hypertext documents that are accessed


via the internet. With a web browser, one can view web pages that may
contain text, images, video and other multimedia and navigate between
them via hyperlinks.

Internet is a global system of interconnected computer networks that use


the standard protocol suit (TCP/IP) to link several billion devices
worldwide. It is an international network of networks that consist of
millions of private, public, academic, business and government packet
switched networks, linked by wireless and optical media.

Networks

Computer network or data network is a telecommunication network that


allows computer to exchange data. Data is transferred in the form of
packets. The connections between nodes are established using either
cable media or wireless media. The bet known compute network is
internet.

Network types

LAN-local area network

WAN-wide area network

LAN: it serves a small area, usually within a building or number of buildings


within a small geographical area. A LAN is used to share software,
hardware and files of data.

WAN: it is formed by connecting a number of LANs through a router or a


modem. It covers a much larger geographical area than LAN.
MUHAMMAD ALI KHAN
PAGE 52

Routers

A router enables data to be routed between different networks, e.g between an Ethernet LAN and a
WAN of any description. It provides any necessary conversion of protocols from Ethernet to TCP/IP.

It can incorporate a firewall to provide network security. It stores information about which computer is
connected to which network. Router will inspect every packet of data being sent by any computer on
network connected to it. It connects at least two networks e.g. between LAN and WAN or a LAN and its
ISP.

Gateways

A gateway deals with different communication protocols between the receiving LAN and the other
networks. Gateway regulates traffic between two dissimilar networks while routers regulate traffic
between similar networks.e.g a device that allows a Windows NT network to communicate with a
NetWare network. Gateway acts as a network point that is entrance point to another network.

Servers

A network server is a computer designed to process requests and deliver data to other (client)
computers over a local network or the internet. Network servers are typically configured with
additional processing, memory and storage capacity to handle the load of servicing clients. Common
types of network servers include

"! Web servers!


"! Proxy servers!
" FTP Servers!

!"#$%&
!"#$%&'()"*&+%,-"+*"."/01%+2'(%"#$%&'()"3(+45$"%-.%"0*$*"6!7".44($**$*"%'"8'(&.(4"4.%."
.%"%-$"4.%."1+#)"1.9$(":1.9$(";<"'8"%-$"=>?"/'4$1@">'/$"*&+%,-$*",.#".1*'"8'(&.(4"4.%.".%"
%-$"#$%&'()"1.9$(":1.9$("A<"39".44+%+'#.119"+#,'(2'(.%+#5"('0%+#5"80#,%+'#.1+%9@">0,-"
*&+%,-$*".($",'//'#19")#'&#".*"1.9$(BA"*&+%,-$*"'("/01%+1.9$("*&+%,-$*
MUHAMMAD ALI KHAN
PAGE 53

!"#$%&'()*#"&+,-"(-,&.(/!012(
!"#$%&'()"*#%$(+,-$"-,(."/0123"*4","5,(.&,($"-'67'#$#%"&*%5'8%"&5*-5","-'678%$("-,##'%"
9$"-'##$-%$."':$(","#$%&'();"1%"*4","-*(-8*%"9',(."*#4%,<<$."*#","-'678%$("%5,%"7(':*.$4","
.$.*-,%$."#$%&'()"-'##$-%*'#"%'"%5$"-'678%$(;"1%"*4",<4'"-,<<$."#$%&'()"*#%$(+,-$"-'#%('<<$(="
#$%&'()",.,7%$("'(">!0",.,7%$(;

34&5%6"
012",<<'&4"9'%5"&*($.",#."&*($<$44"-'668#*-,%*'#4;
012",<<'&4"-'668#*-,%*'#4"9$%&$$#"-'678%$(4"-'##$-%$.":*,"<'-,<",($,"#$%&'()
/>!03",4"&$<<",4"-'668#*-,%*'#4"':$("<,(?$@4-,<$"#$%&'()"%5('8?5"1#%$(#$%"A('%'-'<
/1A3;
012"*4"9'%5","75B4*-,<"<,B$(",#.",".,%,"<*#)"<,B$(".$:*-$="*;$;"*%"7(':*.$4"%5$"#$-$44,(B
5,(.&,($"-*(-8*%(B"4'"%5,%"%5$"75B4*-,<"<,B$("7('-$44$4",#."4'6$".,%,"<*#)"<,B$(
7('-$44$4"-,#"(8#"'#"*%;

7)&"8"66(*"#$%&'()*#"&+,-"(-%*#&%88"&(/7!012(

!"&*($<$44"#$%&'()"*#%$(+,-$"-'#%('<<$("/C0123"*4","#$%&'()"*#%$(+,-$"-'#%('<<$("&5*-5"-'##$-%4"
%'","&*($<$44"(,.*'@9,4$."-'678%$("#$%&'()="(,%5$("%5,#","&*($."#$%&'()="48-5",4"D')$#"E*#?"
'("F%5$(#$%;"!"C012="G84%"<*)$"'%5$("0124="&'()4"'#"%5$">,B$("H",#.">,B$("I"'+"%5$"JK1"L'.$<;"
D5*4"-,(."84$4",#",#%$##,"%'"-'668#*-,%$":*,"6*-('&,:$"(,.*,%*'#;"!"C012"*#",".$4)%'7"
-'678%$("*4"%(,.*%*'#,<<B"-'##$-%$."84*#?"%5$"A21"984;"J%5$("-'##$-%*:*%B"'7%*'#4",($"MKN",#."
A2"-,(.;"1#%$?(,%$."C0124",($",<4'",:,*<,9<$="/%B7*-,<<B"*#"L*#*"A21OA21"FP7($44"L*#*"2,(."
+'(63;
7)&"8"66(,--"66(5%)*#(/7932(
!"&*($<$44",--$44"7'*#%"/C!A3"*4","5,(.&,($".$:*-$"'("-'#+*?8($."#'.$"'#","<'-,<",($,"#$%&'()"
/>!03"%5,%",<<'&4"&*($<$44"-,7,9<$".$:*-$4",#."&*($."#$%&'()4"%'"-'##$-%"%5('8?5","&*($<$44"
4%,#.,(.="*#-<8.*#?"C*@Q*"'("N<8$%''%5;"C!A4"+$,%8($"(,.*'"%(,#46*%%$(4",#.",#%$##,$="&5*-5"
+,-*<*%,%$"-'##$-%*:*%B"9$%&$$#".$:*-$4",#."%5$"1#%$(#$%"'(","#$%&'();

!"!"#$%&'()&*+,""#$"%"&'()*+,-".,+/'-0#.1"2,3#&,"+4%+"&-,%+,$"%"$#.15,"%11-,1%+,".,+/'-0"
6-'("(*5+#)5,"&'((*.#&%+#'.".,+/'-0$"'-".,+/'-0"$,1(,.+$7"84#$"6*.&+#'."#$"&%55,2".,+/'-0"
9-#21#.17:;<"=-#21#.1"#$"2#$+#.&+"6-'("-'*+#.17">'*+#.1"%55'/$"(*5+#)5,".,+/'-0$"+'"&'((*.#&%+,"
#.2,),.2,.+5?"%.2"?,+"-,(%#."$,)%-%+,@"/4,-,%$"9-#21#.1"&'..,&+$"+/'"$,)%-%+,".,+/'-0$"%$"
#6"+4,?"/,-,"%"$#.15,".,+/'-07"A."+4,"BCA"('2,5@"9-#21#.1"#$"),-6'-(,2"#."+4,"2%+%"5#.0"5%?,-"
D5%?,-"EF7A6"'.,"'-"('-,"$,1(,.+$"'6"+4,"9-#21,2".,+/'-0"%-,"/#-,5,$$@"+4,"2,3#&,"#$"0.'/."%$"
%"/#-,5,$$"9-#21,7
!"#"$%"&
!"#$%&'()"*$+,-$"./$*"%'"($0$#$(1%$"'("($23,-1%$"1"/,0#134"5$2$1%$(/"1($"./$*",#"%(1#/6,//,'#"
/7/%$6/"%'"($0$#$(1%$"1#13'0"'("*,0,%13"/,0#13/"*,/%'(%$*"87"%(1#/6,//,'#"3'//4"!#13'0"($2$1%$(/"
9($:.$#%37"-1#"'#37"1623,97"%;$"/,0#13"&;,3$"*,0,%13"($2$1%$(/"-1#"($-'#/%(.-%"1"/,0#13"%'"#$1(",%/"
'(,0,#13":.13,%74
PAGE 54

MUHAMMAD ALI KHAN


PAGE 55

MUHAMMAD ALI KHAN


PAGE 56

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 57

PSTN (Public service telephone network)

The public switched telephone network is the aggregate of the world’s circuit switched telephone
networks that are operated by national, regional or local telephony operators, providing
infrastructure and services for public telecommunication.PSTN consists of telephone lines, fiber optic
cables, microwave transmission links, cellular networks communication satellites and undersea
telephone cables.

In relation to the internet, the PSTN actually furnishes much of the internet’s long distance
infrastructure. Internet service providers (ISP) pay the PSTN for access to their infrastructure and
share the circuit among many users though packet switching. Users pay usage tolls to their ISPs.

Bit streaming

A bit stream is a contiguous sequence of bits representing a stream of data transmitted continuously
over a communication path,serially.live streams are provide by means of called “true streaming”. It
sends the information straight to the computer without saving the file to hard disk e.g. during a
football game.

On-demand streaming is provide by means of “progressive streaming”. It saves the file to a hard disk
and then is played from that location.

Bandwidth and storage

A broadband speed of 2.5mbits/s or more is recommended for streaming movies. Storage size in
calculated from streaming bandwidth and length of media e.g.

Practical example: calculate the storage of one hour of video encoded at 300 Kbits/s

=128 MB
MUHAMMAD ALI KHAN
PAGE 58

P Addressing, Format of an IP address


An internet protocol address is a numerical label assigned to each device e.g. computer, priner in a
computer network that uses internet protocol for communication.

IP addresses are binary numbers but they are usually stored as text files and displayed in human
readable notations such as 172.16.254.1

The maximum address is 255.255.255.255.in practice these are not enough for all the possible
computes so other techniques are used e.g. local addressing and subnetting

IP address has two parts. The first part of an IP address is used as network address, the last part as a
host address e.g.

192.168.123.____ network

___.___.____.132 host

Public IP address

A public IP address is assigned to every compute that connects to the internet where each IP is unique.
User has no control over the public IP address that is assigned to the computer. It is assigned by an ISP
(internet service provider).A public IP can be either static or dynamic. A static IP address does not
change and is used primarily for hosting WebPages or services on the internet

A dynamic IP address is chosen from a pool of available addresses and changes each time one connects
to the internet

Private IP address

The internet assigned numbers authority (IANA) has reserved ranges of IP addresses for private
networks. Private IP addresses are used for numbering the computers in a private network including
home, school and business LANs in airports and hotels. Private IP addresses are used to exchange files
and share resources within the private network. Different private networks could use the same IP
addresses because computers in different networks don’t directly communicate. A network router
passes the data back and forth. The router is assigned a public IP address by ISP.tis single IP address
identifies the entire network on the internet.

How URL is used to locate resources on www and role of DNS

A URL is a formatted text string used by web browsers, email clients to identify a network resource
on the internt.URL string consists of three parts (sub strings)
I. Network protocol
II. Host name and address
III. File or resource location

E.g. protocol://host/location

The most commonly used protocols are http for viewing WebPages and FTP for transferring files over
the internet.
MUHAMMAD ALI KHAN
PAGE 59

A DNS server provides name resolution for TCP/IP based networks. It makes it possible to use name
rather than numeric IP addresses to identify remote hosts. A client computer sends the name of
remote host to a DNS server which responds with a corresponding IP address. If the DNS server does
not have an entry in its database for the remote host, it can respond to the client with the address of
DNS sever that is more likely to have information about that remote host or it can forward the request
to a different DNS server at next higher level in the hierarchy.

Explain how communication systems are used to support the Internet: The Public
Service Telephone Network (PSTN), dedicated lines, cell phone network

In relation to the Internet, the PSTN actually furnishes much of the Internet's long-distance
infrastructure.
Because Internet service providers ISP s pay the long-distance providers for access to their
0T 0T 31TU U31T

infrastructure and share the circuits among many users through packet-switching, Internet users
0T 0T

avoid having to pay usage tolls to anyone other than their ISPs.
MUHAMMAD ALI KHAN
PAGE 60

T h e F o rm a t o f a n IP A d d re s s
The format of an IP address is a 32-bit numeric address written as four numbers separated by periods. Each number

can be zero to 255. For example, 1.160.10.240 could be an IP address.


Within an isolated network, you can assign IP addresses at random as long as each one is unique. However,
connecting a private network to the Internet requires using registered IP addresses (called Internet addresses) to

avoid duplicates.

S ta tic V e rs u s D yn a m ic IP A d d re ss e s
An IP address can be static or dynamic. A static IP address will never change and it is a permanent Internet address.
A dynamic IP address is a temporary address that is assigned each time a computer or device accesses the Internet.

The four numbers in an IP address are used in different ways to identify a particular network and a host on that
network. Four regional Internet registries -- ARIN, RIPE NCC, LACNIC and APNIC-- assign Internet addresses from
the following three classes:
Class A - supports 16 million hosts on each of 126 networks

Class B - supports 65,000 hosts on each of 16,000 networks


Class C - supports 254 hosts on each of 2 million networks

The number of unassigned Internet addresses is running out, so a new classless scheme called CIDR is gradually
replacing the system based on classes A, B, and C and is tied to adoption of IPv6. In IPv6 the IP address size is
increased from 32 bits to 128 bits.

IP Addressing
IP addressing is a hardware-independent convention which in principle allows
every computer attached to the Internet to be given a unique logical address
(though we will see later on that there are some important exceptions to this).

IP addresses are currently 32-bit binary strings which are normally seen by
humans (e.g., network administrators, in dotted decimal as in the example:

223.58.1.10

The decimal numbers here have no meaning in isolation; this is simply a


convenient way of encoding the numbers so that administrators and others
find it easier to recognize them. What happens is that the 32-bit address is
broken up into four 8-bit sequences each of which is converted to decimal. So
the above address is in binary:

11011111 00111010 00000001 00001010


MUHAMMAD ALI KHAN
PAGE 61

IP Address Formats
Originally IP addresses were divided into five classes as shown below.
Classes A, B and C are the most important: the initial bits determine which
class an address belongs to, and the classes differ in how much of the
address is taken up with the network address and how much with the host
address.

Offsets

0 8 16 24

Class A

0 Network Host

Addresses 1.0.0.0 to 127.255.255.255


Class B

10 Network Host

Addresses 128.0.0.0 to 191.255.255.255


Class C

110 Network Host

Addresses 192.0.0.0 to 223.255.255.255


Class D

1110 Multicast address

Addresses 224.0.0.0 to 239.255.255.255


Class E

11110 Reserved for future use

Addresses 240.0.0.0 to 255.255.255.255


MUHAMMAD ALI KHAN
PAGE 62

Exclusions

Some address ranges are excluded from the above classes. All addresses of
the form 127.xx.yy.xx are used for diagnostics. The following address ranges
are designated as "private": meaning thay can only be used on networks
which are not connected to the global Internet:

10.0.0.0 - 10.255.255.255
172.16.0.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255

Examples

Find the class, network and host addresses for:

a. 4.23.145.90
b. 227.34.78.7
c. 246.7.3.8
d. 129.6.8.4
e. 198.76.9.23

Subnetting, Supernetting and Network Address


Translation
The classfull addressing scheme has proved to be too inflexible to
accommodate the demand for IP addresses; specifically, the convention that
the part of the address which identifies a physical network must come on an
8-bit boundary meant that the address space could not be allocated efficiently
and a significant proportion of addresses would be wasted. For instance, a
Class A network can in theory have 16 million host IDs, which is way more
than would be possible for a single physical network (subnet). Many
enterprises have been allocated Class B addresses, giving them a theoretical
maximum of 65,535 hosts, and may have no more than a few hundred hosts
or less: under the classfull scheme the remaining host IDs for that network ID
would be unused.

The lack of inflexibility in the addressing scheme is particulalrly undesirable


because according to many authorities there is a real danger of the Internet
MUHAMMAD ALI KHAN
PAGE 63

running out of addresses, as a result of several factors which were not


envisaged when the Internet protocols were originally designed, such as :

" take-up by business and domestic users


" increasing demand for "always-on" connections requiring a dedicated IP
address, so that ISPs have less ability to share out a limited number of
IP addresses by reallocating them as customers disconnect
" convergence of computing, communications and entertainment
industries could mean that every TV set, mobile phone, playstation and
DVD player will want to have an IP address.

Subnetting

The basic idea behind subnetting is that we take away some bits from the host
portion of the address and use them to identify the subnet. This will only be
visible to hosts and routers on the local network; from the point of view of the
Internet at large only the network ID portion will have any particular meaning.
The way this works is that the network administrator defines a subnet mask, a
string of 32 binary digits indicating the boundary between the subnet and host
sections of the "local" portion of an IP address. Some examples should help
make this clear:

1. Take the Class A address 9.67.38.1, where 9 is the network address


and 67.38.1 identifies a particular host on that network. Suppose the
network administrator wants to use bits 8 to 25 to identify the subnet,
leaving 26 to 31 for host addresses. This is done by means of
a mask which is all 1's from bits 0 to 25 with the remainder set to 0's:

11111111 11111111 11111111 11000000

The subnet can then be indentified by ANDing the complete IP


address with the mask giving the result shown below:

00001001 01000011 00100110 00000001 = class A


address 9.67.38.1

00001001 01000011 00100110 00000000 = subnet base


address 9.67.38.0

2. Suppose a class C network has the subnet mask

11111111 11111111 11111111 11100000


MUHAMMAD ALI KHAN
PAGE 64

This means that the first three bits from the host ID are used to
identify the subnet, and the remaining 5 bits indicate the host itself.
Take a host with the IP address

11010100 01110010 00010000 01110001 =


212.114.32.113

Applying the subnet mask gives us

11010100 01110010 00010000 01100000 = 212.114.32.96

The host ID proper comes out as 00010001 = 17.

For compatibility, routers include masks for unsubnetted addresses:

A. 255.0.0.0
B. 255.255.0.0
C. 255.255.255.0
D. N/A
E. N/A
Supernetting and Classless Inter-Domain Routing (CIDR)

CIDR is in a sense the converse of subnetting, in that bits are taken from the
network ID to identify a cluster of network addresses which are to be treated
as a single entity. The main reasons for this are:

" As a consequence of the address exhaustion problem, Class B


addresses are only assigned to organisations that can show a clear
need for them: organisations which do not meet the requirements are
instead given a contiguous block of Class C addresses.
" Having a series fo router table entries for networks which all map onto
the same route is wasteful of space and degrades routing algorithms.

CIDR uses a supernet mask along with the lowest network address in the
assigned block to identify the range of assigned network addresses.
MUHAMMAD ALI KHAN
PAGE 65

Network Address Translation and IPv6

Network Address Translation is a technique which allows for the composition


of a network to be completely hidden from the outside world, with the entire
network identified by a single IP address. Within the network, hosts and
routers have addresses which are unique to that network, typically taked from
the ranges designated as "private" (see above). In order to make sure that
responses get back to the right hosts when packets are sent out into the
Internet, the router will construct a table associating outgoing packets with
private IP addresses; the address of the relevant table entry will be stored in
the packet itself. This technique is controversial however; for one thing the
field in the packet where the index into the table is stored is part of the TCP
header, which violates the principles of modularity and encapsulation on
which the "protocol stack" models are based.

A longer term solution to the address exhaustion problem is offered by IP


version 6 (IPv6) which among other innovations will support 128-bit
addresses.
PAGE 66

MUHAMMAD ALI KHAN


PAGE 67

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 68

!"#$%$&'()*$(+),)-.(/0(,11&$++(-+(2")(.*,23$1(42)-5(-)(-+(6,24,557(.*,23$1(87()*$(2$)#"&9(
,16-2-+)&,)"&("&()*$(/2)$&2$)(:$&%-.$(0&"%-1$&(;/:0<=(>5+"'()*-+(,11&$++(1"$+(2")(.*,23$($,.*(
)-6$(#*$2()*$(4+$&(."22$.)+()"()*$(2$)#"&9=(/2(")*$&(#"&1+'()*$(1$%-.$(,5#,7+(4+$+()*$(+,6$(/0(
,11&$++()"(."22$.)()"()*$(-2)$&2$)=(?*$&$@"&$'()*$(+),)-.(/0(,11&$++-23(A&"%-1$+(645)-A5$(
,1%,2),3$+=(/)(3-%$+(6-2-646(1"#2)-6$(#*-5$(A&"%-1-23(&$6")$(,..$++=(>5+"'()*$(4+$&(.,2(
,..$++()*$(1$%-.$(@&"6(,27(5".,)-"2=

B*,)(-+(,(C72,6-.(/0(>11&$++
>(172,6-.(/0(,11&$++(-+(,2(,11&$++("8),-2$1(@&"6(,(C72,6-.(!"+)(D"2@-34&,)-"2(0&")"."5(
;C!D0<(+$&%$&=(/)(,++-32+(,(1$%-.$(#-)*(172,6-.(/0(,11&$++'(+482$)(6,+9'(1$@,45)(3,)$#,7'(,21(
,(CE:(+$&%$&=(/2(,(F-.&"+"@)(."6A4)$&'(+$5$.)-23()*$("A)-"2(G"8),-2(,2(/0(,11&$++(,4)"6,)-.,557H(
-2()*$(2$)#"&9(A&"A$&)7(#-21"#(#-55(+$)()*$(1$%-.$()"("8),-2(,2(/0(,11&$++(172,6-.,557=

?*$(172,6-.(/0(,11&$++(.*,23$+(@&$I4$2)57=(J,.*()-6$()*$(1$%-.$(."22$.)+()"()*$(2$)#"&9'()*$(
172,6-.(/0(,11&$++(.*,23$+=(B*$2()*$(1$%-.$()&-$+()"(."22$.)()"()*$(2$)#"&9'()*$(C!D0(+$&%$&(
A&"%-1$+(,(172,6-.(,11&$++=(B*$2()*$(4+$&()7A$+(,(KLM("2()*$(#$8(8&"#+$&'()*$(CE:(+$&%$&(
6,A+()*$(1"6,-2(2,6$()"()*$(/0(,11&$++=((N%$&,55'(C72,6-.(/0(,11&$++-23(-+(,4)"6,)-.(,21(-)(
6,9$+(6,2,3-23(,(2$)#"&9($,+-$&
PAGE 69

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 70

!"#$%&#$'(
)*%$+(
,$-"#$'(
.$/$+0(1"(&%(
."20
MUHAMMAD ALI KHAN
PAGE 71

Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content

3.1 Computers and their components Notes and guidance


Candidates should be able to:
Show understanding of the need for input, output,
primary memory and secondary (including removable)
storage Including: benefits and drawbacks of embedded
Show understanding of embedded systems systems
Including: Laser printer, 3D printer, microphone,
Describe the principal operations of hardware devices speakers, magnetic hard disk, solid state (flash)
memory, optical disc reader/writer, touchscreen,
virtual headset

Show understanding of the use of buffers Including their use in a range of devices and systems
Explain the differences between Random Access
Memory (RAM) and Read Only Memory (ROM) Include their use in a range of devices and systems
Explain the differences between Static RAM (SRAM)
and Dynamic RAM (DRAM)

Explain the difference between Programmable ROM and the reasons for using one instead of the other
(PROM), Erasable Programmable ROM (EPROM) and depending on the device and its use
Electrically Erasable Programmable ROM (EEPROM)
Show an understanding of monitoring and control Including:
systems
! difference between monitoring and control
! use of sensors (including temperature, pressure,
infra-red, sound) and actuators
! importance of feedback
PAGE 72

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 73

!"#$%&'(')*'+",$-&"$'*."'/.0$12,3'4-,#*1*0',#5'2%#6"&*$'1*'*%',#'"3"2*&12,3'
$17#,3'8.12.'2,#'9"'&",5'90',#'%9$"&6"&'%&'90',#0'"3"2*&%#12'1#$*&-+"#*'
31:"',#';<='2%#6"&*"&>';'$"#$%&'$*%&"$'*."'+",$-&"5'4-,#*1*0'*%'*."'
+"+%&0>

;?='@%#6"&*"&'(';#',#,3%7?*%?5171*,3'2%#6"&*"&'2%#6"&*$'*."',#,3%7'$17#,3
$"#*'90'*."'$"#$%&'1#*%','5171*,3'$17#,3>

A&%2"$$%&'B';!)@$'('A&%2"$$%&$'/&%2"$$'*."'5,*,'*%'+",$-&"'*."'%-*/-*'
,#5'$*%&"'1*'*%'*."'+"+%&0>

=?;'@%#6"&*"&'(';'5171*,3?*%?,#,3%7'2%#6"&*"&'2%#6"&*$'*."'5171*,3'5,*,'C"5
90'*."'/&%2"$$%&'*%',#,3%7'5,*,

;2*-,*%&'(';#',2*-,*%&'2%+/,&"$'*."'%-*/-*'716"#'90'*."'=?;'@%#6"&*"&'*%'
*."',2*-,3'D"E/"2*"5F'%-*/-*'$*%&"5'1#'1*',#5'$*%&"$'*."',//&%6"5'%-*/-*>
MUHAMMAD ALI KHAN
PAGE 74

Word/phrase Meaning

3D printer An output device that can generate a three-


dimensional (3D) physical object

hard disk A magnetic secondary storage device

inkjet printer An output device for printing pages using ink


cartridges

keyboard An input device that allows text characters and


symbols to be entered into a computer system

laser printer An output device for printing pages that uses


toner cartridges

microphone An input device that allows sound to be


entered into a computer system

optical discs Secondary storage devices

optical mouse An input device that is used to move a pointer


on a screen

scanner An input device that takes physical printed


information and converts it into a digitised
format

speakers Output devices that produce sound

solid state (flash) memory A secondary storage device that has no


moving parts

touchscreen Both an input and an output device: the display


outputs an image; it can receive inputs by
being touched by either a finger or a stylus
MUHAMMAD ALI KHAN
PAGE 75

!"#$%#&'%()*+$,%-+$*+$%#).%/$-&#0'%.'1(2'/3%
455%2-6*+$()0%/7/$'6/%2#)%8'%8&-9')%.-:)%()$-%#%8#/(2%()*+$,%*&-2'//()0,%
-+$*+$%#).%/$-&#0'%6-.'5;%

Microphone
A BBC Bitesize GCSE revision guide to how sound is sampled, including an overview
diagram
http://www.bbc.co.uk/education/guides/z7vc7ty/revision
How microphones convert sound into an electrical signal
http://www.mediacollege.com/audio/microphones/how-microphones-work.html

Touchscreen
Describes resistive, capacitive and surface acoustic wave touchscreens
http://computer.howstuffworks.com/question716.htm
Resistive and capacitive touchscreens with diagrams

https://techexplainer.wordpress.com/2012/04/02/resistive-vs-capacitive-touchscreen/

3.1.3 Output devices

Laser printer
How a laser printer works, based on a labelled diagram

http://www.computershopper.com/feature/how-it-works-laser-printer
Labelled diagram and explanation of laser printers
http://www.explainthatstuff.com/laserprinters.html

3D printer

!"#$%&'$%()*+&(,&%"+&-,.+/+,.+,%&,+01/'/+$&+2/*'(,(,3&45&/$(,%(,3&
"%%/6770008(,.+/+,.+,%8)#89:7*(;+<1%=*+73'.3+%1<',.<%+)"7;+'%9$+174.</$(,%(,3<
;#$<.9>>(+1<"#0<.#<4.</$(,%+$1<0#$:<?@@?A4B8"%>*&&
MUHAMMAD ALI KHAN
PAGE 76

Speakers

Explains sound signals, how the voice coil produces sound, and differences between
computer speakers and other speakers
http://www.ehow.com/how-does_4963948_how-computer-speakers-work.htmlHard disk
Description and labelled diagram of the parts in a hard disk
http://www.explainthatstuff.com/harddrive.html
Page 5 onwards: a more detailed explanation of the parts of a hard disk
http://computer.howstuffworks.com/hard-disk4.htm
Optical discs
Basic description of the operation of optical discs in BBC Bitesize Higher Computing
Science http://www.bbc.co.uk/education/guides/zws3gk7/revision/3
Solid state (flash) memory
An accessible simple description of flash memory, followed by a more detailed explanation
http://www.explainthatstuff.com/flashmemory.html

3.2.Videos
The following are all very brief videos that explain the principles of the
How a touchscreen works
https://www.youtube.com/watch?v=euCewYGHZB0
How a scanner works
https://www.youtube.com/watch?v=shnYIjG20i4
How a laser printer works
https://www.youtube.com/watch?v=WB0HnXcW8qQ
How a 3D printer works
https://www.youtube.com/watch?v=Vx0Z6LplaMU
How a hard disk works
https://www.youtube.com/watch?v=4iaxOUYalJUHow an optical drive works https://
www.youtube.com/watch?v=bRDuAa6nhpw
How solid state memory works
https://www.youtube.com/watch?v=TFoOyPXYJ-E&feature=youtu.be
PAGE 77

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 78

!"#$%&'
A sensor is a device that detects events or changes in quantities and provides a corresponding
output, generally as an electrical or optical signal. They can produce a stream of input data
automatically without any human intervention. Usually this is an analogue signal so it needs
to be converted into digital data for the computer to process. This is done using by an
Analogue-to-Digital Converter (ADC). Sensors are used extensively in monitoring
/ measuring / data logging systems, and also in computer control systems. Following is the
list of commonly used sensors:
Temperature
Magnetic Field Gas
Pressure Moisture
Humidity
Ph/Acidity/Alkalinity
Motion/ Infra-Red

Advantages of using sensors to collect data are:


1. They can collect data far more frequently than a person.
2. They are more reliable than a person, who may forget to take readings.
3. They are more accurate than a person who may misread the signal.
4. They can collect data from places where it is not possible for a person to go such as inside
a chemical or nuclear reaction vessel.
The disadvantage of using sensors is that they may need a power supply to work and may
need regular calibration to check their accuracy.
(")*"&+,-&".!"#$%&'

A temperature sensor produces a signal that depends on the temperature of its surroundings.
The computer process the digitize signal to display a measurement or to control an appliance.
We can use temperature sensor in many appliance such:
!" Automatic washing machine#
$" Digital thermometer#
%" Controlling heating system in buildings, including greenhouses and chemical reaction
vessels.#
/&"$$-&".$"#$%&'

A pressure sensor produces a signal that depends on the pressure to which it is exposed.
Pressure sensor can be used in many appliances such as automatic blood pressure monitor.
Pressure sensor can also control the pressure of gases or liquids in chemical reaction vessel.
0+1#",23.42"56'

The Magnetic Field Sensor can be used to study the field around permanent magnets, coils,
and electrical devices. This sensor uses a Hall effect transducer, and measures a vector
component of the magnetic field near the sensor tip. It has two ranges, allowing for
measurement of relatively strong magnetic fields around permanent magnets and
electromagnets, as well as measurement of weak fields such as the Earth’s magnetic field. The
articulated sensor tip allows you to measure both transverse and longitudinal magnetic fields.
7+$'

A gas sensor produces a signal depending on the concentration of a particular gas or vapor.
We can use gas sensor for an inflammable gas to monitor the atmosphere and sound an alarm
if there is a leakage. We can use gas sensor in other applications such as:
& Breathalyzer, which measure the concentration of alcohol vapour in a sample of
breath and estimate the concentration of alcohol in blood.#
MUHAMMAD ALI KHAN
PAGE 79
#
& Process control in chemical industry.#
& Environment monitoring of air pollution#
0%2$,-&"8.9-)262,:.$"#$%&#
A moisture sensor produces a signal that depends on the concentration of water vapors in the
atmosphere. A moisture sensor can control an irrigation system more efficiently only allow
water
# when soil is dry. We can use moisture sensor in many other application including:#
& Controlling a heating system and air conditioning system.#
& Maintaining sufficient humidity in the air in a greenhouse.#
& Measuring humidity for meteorological record and forecasting in a weather station.#
/98+3262,:8+5;+52#2,:.$"#$%&'#

PH Sensor measures the pH of aqueous solutions in industrial and municipal process applications. It is
designed to perform in the harshest of environments, including applications that poison conventional
pH sensors.
Typical activities using our pH sensor include:
& Acid-base titrations#
& Studies of household acids and bases#
& Monitoring pH change during chemical reactions or in an aquarium as a result of
# photosynthesis#
& Investigations of acid rain and buffering#
& Analysis of water quality in streams and lakes#
<#=&+&"6.$"#$%&'
An infra (IR) sensor produces a signal that depends on the level of invisible IR radiation falling on it.
All objects (unless they are extremely cold) emit significant IR radiation. Security camera equips with
lens and grid of IR sensors uses this IR radiation to form a detector for a person.

!3+##"&

Scanners are used to enter hardcopy images into a computer. The most common type is the
flatbed scanner where the user places the document flat on a glass panel and closes the lid.
An array of light sensors and a light source move underneath the document.
The sensor ‘reads’ the light reflected from the document or image. Most scanners use
charged-coupled device (CCD) array. Regardless of the technology used, a sensor array
contains light-sensitive diodes that convert analog light waves into a digital signal. Some
scanner arrays contain three rows of sensors. Each row is calibrated to measure red, blue
or green light.
MUHAMMAD ALI KHAN
PAGE 80

>",2#+.$3+##"&
The human retina is a thin tissue composed of
neural cells that is located in the posterior
portion of the eye. Because of the complex
structure of the capillaries that supply the
retina with blood, each person's retina is
unique. The network of blood vessels in the
retina is not entirely genetically determined
and thus even identical twins do not share a
similar pattern.
A retinal scan is performed by casting an
unperceived beam of low-energy infrared
light into a person’s eye as they look through the scanner's eyepiece. This beam of light traces
a standardized path on the retina. Because retinal blood vessels absorb light more readily
than the surrounding tissue, the amount of reflection varies during the scan. The pattern of
variations is digitized and compared with already stored patterns to verify the identity of the
person.
MUHAMMAD ALI KHAN
PAGE 81

42#1"&*&2#,.$3+##"&
The scanning process starts when you place your finger on a glass plate, and a CCD camera
takes a picture. The scanner has its own light source, typically an array of light-emitting
diodes, to illuminate the ridges of the finger. The CCD system actually generates an inverted
image of the finger, with darker areas representing more reflected light (the ridges of the
finger) and lighter areas representing less reflected light (the valleys between the ridges). If
the processor finds that the image is crisp and properly exposed, it proceeds to comparing
the captured fingerprint with fingerprints on file.
MUHAMMAD ALI KHAN
PAGE 82
?+$"&.*&2#,"&
This type of printer produces very
high quality hard copy. It consists
of drum that is electrically charged.
A laser is used to change the charge
on the drum for each dot of the
output to be produced. Electrically
charged toner is then attracted to
the oppositely charged dots. The
paper presses against the
toner coated drum and is output with the pattern of dots required which is then heated in
order to permanently fuse the text/imagery. The page cannot be printed until the whole
document has been stored in a large buffer.

!*"+;"&$
It is a device which produces sound as output. The digital data from the computer is converted
into analogue signals by a digital to analogue converter and are then amplified and output
using the speakers. At the front of a loudspeaker, there is a fabric, plastic, paper, or
lightweight metal cone. The inner part is fixed to an iron coil (sometimes called the voice coil)
that sits just in front of a permanent magnet (sometimes called the field magnet). when
electric current is passed through coil; it
becomes a temporary magnet
(electromagnet). As the electricity flows back
and forth in the cables, the electromagnet
either attracts or repels the permanent
magnet. This moves the coil back and forward,
pulling and pushing the loudspeaker cone
which produces sound.
MUHAMMAD ALI KHAN
PAGE 83
@+3;2#1.$,%&+1"'
Backing storage (also called auxiliary storage) stores programs and data for future use. In
order to store data while the electricity is switched off or unavailable storage must be non-
volatile. Access to backing storage is slower than internal memory. Operating systems and
program files are loaded into RAM from backing storage when required for execution. It is
important to distinguish between a storage device and storage medium. The storage device
is the machine that stores data; the storage medium is the material on which the device
stores data. There are three different types of backing storage device:

1. Magnetic storage device

2. Optical storage device

3. Solid state storage device.

9+&6.62$;.A!"#$%&'()*&+,"#%B
Hard disk is a type of magnetic storage.
It consists of one or more disks
(depending upon the capacity of hard
disk).They are mounted on a spindle
which is operated by a motor to spin
the disk very quickly. There is usually
one read/write head for each disk
surface being used. The disks are used
to store operating system as well as
software programs and data files. It
provides very fast access to data for
both reading from and writing to the
disks.
MUHAMMAD ALI KHAN
PAGE 84
C*,23+5.62$;
optical disc recording
technologies, an optical disc (OD)
is a flat, usually circular disc which
encodes binary data (bits) in the
form of pits (binary value of 0 or
off, due to lack of reflection when
read) and lands
(binary value of 1 or on, due to a reflection when read) on a special material (often aluminum)
on one of its flat surfaces.

!%526.$,+,".)")%&:
Solid state storage is a type of computer storage media that is made from silicon microchips.
it stores data electronically instead of magnetically, as spinning hard disk drives or magnetic
tape do.
An important advantage of solid-state storage is the fact that it contains no mechanical parts,
allowing data transfer to and from storage media to take place at a much higher speed and
providing a more predictable lifespan for the storage media. In addition to providing faster
and more consistent input/output (I/O) times, solid-state storage media offers the same levels
of
data integrity and endurance as
other electronic devices and
requires less power and cooling
than its electromechanical
equivalents. It also generally
weighs less.
MUHAMMAD ALI KHAN
PAGE 85
D3,-+,%&$
Actuators are used to convert computer signal into movement. Some devices such as motors
are considered to be actuators in their own right. The most common form of motor used with
computers is the stepper motor which moves n steps that can be very tiny, enabling precise
control .e.g. in home they are used in washing machines to make the drum go round. They
cause the water pumps to come on in central heating systems. They are also used in computer
controlled green houses to open the windows and switch on fans.

Buzzers
An actuator is connected from the computer to the buzzer. The actuator is set to switch the
buzzer either on or off. In the same way lights and heaters can be switched on or off.
MUHAMMAD ALI KHAN
PAGE 86

/&2)+&:.%&.0+2#.)")%&:
Main store (or computer !"!#$%) is divided into Read Only Memory (ROM) and
Random Access Memory (RAM).

!"#
!"#$is memory that cannot be changed by a$&$#'$(!$or user. ROM retains its memory$
even after the computer is turned off. For example, ROM stores the instructions for the
computer to start up when it is turned on again.

%&'(&)**)+,-$&-).$'/,0$*-*'&0$1%!"#2
A PROM is a memory chip on which data can be written only once. Once a program has
been written onto a PROM, it is permanent. Unlike RAM, PROM's retain their contents
when the computer is turned off. The difference between a PROM and a ROM (read
only memory) is that a PROM is manufactured as a blank memory, whereas a ROM is
programmed during the manufacturing process. To write data onto a PROM chip, a
special device called a PROM programmer or PROM burner is required.

3&)4)+,-$5&'(&)**)+,-$&-).$'/,0$*-*'&0$13%!"#2
This is a special type of PROM that can be erased by exposing it to ultraviolet (UV) light.
Once it has been erased, it can be re-programmed using an EPROM burner.
MUHAMMAD ALI KHAN
PAGE 87

3,-67&86),,0$-&)4)+,-$5&'(&)**)+,-$&-).$'/,0$*-*'&0$133%!"#2
An EEPROM is a special type of PROM that can be erased by exposing it to an electrical charge. Like
other types of PROM, EEPROM retains its contents even when the power is turned off.

!9#
!9#$is a fast 7-*5'&)&0 type of
memory in which
programs, (&&)*+(,*#-. and /(,( are
stored. Here are some examples of what's
stored in RAM:
& the #&"$(,*-'0.%.,"!#
&# applications#
&# the graphical user interface (GUI)#
If a computer loses power, all data stored
in its RAM is lost.#

RAM
# exist called SRAM (static RAM) and#
DRAM (dynamic RAM) – SRAM doesn’t need to be constantly refreshed to retain its memory
unlike DRAM. Also note that computers use cache which is a portion of memory made from
SRAM. Memory caching works since programs usually access the same data or instructions
over and over again.#
PAGE 88

MUHAMMAD ALI KHAN


PAGE 89

MUHAMMAD ALI KHAN


PAGE 90

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 91

4.2 Assembly Language


Candidates should be able to: Notes and guidance
Show understanding of the relationship between
assembly language and machine code
Describe the different stages of the assembly process Apply the two-pass assembler process to a given
for a two-pass assembler simple assembly language program
Trace a given simple assembly language program
Show understanding that a set of instructions are Including the following groups:
grouped ! Data movement
! Input and output of data
! Arithmetic operations
! Unconditional and conditional instructions
! Compare instructions
Modes of addressing Including Immediate, direct, indirect, indexed, relative
MUHAMMAD ALI KHAN
PAGE 92

Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content

The following table is an example of an instruction set:


Instruction Explanation
Opcode Operand

LDM #n Immediate addressing. Load the number n to ACC

LDD <address> Direct addressing. Load the contents of the location at the given address to
ACC
LDI <address> Indirect addressing. The address to be used is at the given address. Load the
contents of this second address to ACC
LDX <address> Indexed addressing. Form the address from <address> + the contents of the
index register. Copy the contents of this calculated address to ACC
LDR #n Immediate addressing. Load the number n to IX

MOV <register> Move the contents of the accumulator to the given register (IX)

STO <address> Store the contents of ACC at the given address

ADD <address> Add the contents of the given address to the ACC

ADD #n Add the denary number n to the ACC

SUB <address> Subtract the contents of the given address from the ACC

SUB #n Subtract the denary number n from the ACC

INC <register> Add 1 to the contents of the register (ACC or IX)

DEC <register> Subtract 1 from the contents of the register (ACC or IX)

JMP <address> Jump to the given address

CMP <address> Compare the contents of ACC with the contents of <address>

CMP #n Compare the contents of ACC with number n

CMI <address> Indirect addressing. The address to be used is at the given address. Compare the
contents of ACC with the contents of this second address
JPE <address> Following a compare instruction, jump to <address> if the compare was
True

JPN <address> Following a compare instruction, jump to <address> if the compare was
False
IN Key in a character and store its ASCII value in ACC

OUT Output to the screen the character whose ASCII value is stored in ACC

END Return control to the operating system

All questions will assume there is only one general purpose register available (Accumulator)
ACC denotes Accumulator
IX denotes Index Register
<address> can be an absolute or symbolic address
# denotes a denary number, e.g. #123
B denotes a binary number, e.g. B01001010
& denotes a hexadecimal number, e.g. &4A
MUHAMMAD ALI KHAN
PAGE 93

Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content

4.3 Bit manipulation


Candidates should be able to: Notes and guidance
Show understanding of and perform binary shifts logical, arithmetic and cyclic
Left shift, right shift
Show understanding of how bit manipulation can be Carry out bit manipulation operations
used to monitor / control a device Test and set a bit (using bit masking)

Instruction
Label Opcode Operand Explanation
AND #n Bitwise AND operation of the contents of ACC with the operand
AND <address> Bitwise AND operation of the contents of ACC with the contents
of <address>
XOR #n Bitwise XOR operation of the contents of ACC with the operand
XOR <address> Bitwise XOR operation of the contents of ACC with the contents
of <address>
OR #n Bitwise OR operation of the contents of ACC with the operand
OR <address> Bitwise OR operation of the contents of ACC with the contents of
<address>
<address> can be an absolute address or a symbolic address
LSL #n Bits in ACC are shifted logically n places to the left. Zeros are
introduced on the right hand end
LSR #n Bits in ACC are shifted logically n places to the right. Zeros are
introduced on the left hand end
<label>: <opcode> <operand> Labels an instruction
<label>: <data> Gives a symbolic address <label> to the memory location with
contents <data>
MUHAMMAD ALI KHAN
PAGE 94

Instruction has two main parts

! Op code (abbreviated from operation code) is the portion of a machine language instruction
" that specifies the operation to be performed"
! Operand address or data on which the operation is to be performed."

Addressing modes

" ! Immediate"
! Direct"
! Indirect"
! Indexed"
! Relative"

Immediate addressing

Immediate addressing means that the data to be used is hard-coded into the instruction
itself.This is the fastest method of addressing as it does not involve main memory at all.

For example, you want to add 2 to the content of the accumulator

The instruction is:

ADD #2

Nothing has been fetched from memory; the instruction simply adds 2 to the accumulator

immediately. Immediate Addressing is very useful to carry out instructions involving


constants (as opposed to variables). For example you might want to use 'PI' as a constant
3.14 within your code.
MUHAMMAD ALI KHAN
PAGE 95

Direct addressing

This is a very simple way of addressing memory - direct addressing means the code refers
directly to a location in memory

For example SUB (3001)

In this instance the value held at the absolute location 3001 in RAM is subtracted from the

accumulator. The good thing about direct addressing is that it is fast (but not as fast as
immediate addressing) the bad thing about direct addressing is that the code depends
on the correct data always being present at same location.

It is generally a good idea to avoid referring to absolute memory addresses in order to


have 'relocatable code' i.e. code that does not depend on specific locations in memory.

You could use direct addressing on computers that are only running a single program. For
example an engine management computer only ever runs the code the car engineers
programmed into it, and so direct memory addressing is excellent for fast memory access.
MUHAMMAD ALI KHAN
PAGE 96

Indirect addressing
MUHAMMAD ALI KHAN
PAGE 97

Indexed addressing

The address is formed by the operand plus the number in the index register.

CIR
ADI 10 10 200
.
IR(index register) + .
150 .
160 120
accumulator
120 .
200 395
Index addressing is fast and is excellent for manipulating data structures such as arrays as
all you need to do is set up a base address (e.g. 10 in CIR) then use the index in your code
to access individual elements. Another advantage of indexed addressing is that if the array
is re-located in memory at any point then only the base address needs to be changed. The
code making use of the index can remain exactly the same.

Relative addressing

Quite often a program only needs to jump a little bit in order to jump to the next instruction.
Maybe just a few memory locations away from the current instruction. A very efficient way of
doing this is to just add a small offset to the current address in the program counter.
(Remember that the program counter always points to the next instruction to be
executed).This is called 'relative addressing'

DEFINITION:

Relative addressing means that the next instruction to be carried out is an offset number
of locations away, relative to the address of the current instruction. Consider this bit of
pseudo-code:

jmp +3 if accumulator == 2
Code executed if accumulator is NOT = 2
jmp +5 (unconditional relative jump to avoid the next line of code)
acc:
Code executed if accumulator is = 2)
Carry on:

In the code snippet above, the first line of code is checking to see if the accumulator has the
value of 2 in it. If it is has, then the next instruction is 3 lines away. This is called a conditional
jump and it is making use of relative addressing.
Another example of relative addressing can be seen in the jmp +5 instructions. This is telling the
CPU to effectively avoid the next instruction and go straight to the 'carryon' point.
MUHAMMAD ALI KHAN
PAGE 98

Summary of addressing modes

Application of all addressing modes


PAGE 99

MUHAMMAD ALI KHAN


PAGE 100

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 101

!"#$%&#$'()$*+$(%$'%$,(-"%(%"(
'.")("/+()$01-$''$'2(3/%(%"(
,&'4"5$+("/+('%+$-6%.'7
MUHAMMAD ALI KHAN
PAGE 102
Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content

4 Processor Fundamentals
4.1 Central Processing Unit (CPU) Architecture
Candidates should be able to: Notes and guidance
Show understanding of the basic Von Neumann
model for a computer system and the stored program
concept
Show understanding of the purpose and role of Special purpose registers including:
registers, including the difference between general
! Program Counter (PC)
purpose and special purpose registers
! Memory Data Register (MDR)
! Memory Address Register (MAR)
! The Accumulator (ACC)
! Index Register (IX)
! Current Instruction Register (CIR)
! Status Register
Show understanding of the purpose and roles of the
Arithmetic and Logic Unit (ALU), Control Unit (CU)
and system clock, Immediate Access Store (IAS)
Show understanding of how data are transferred
between various components of the computer system
using the address bus, data bus and control bus
Show understanding of how factors contribute to the Including:
performance of the computer system
! processor type and number of cores
! the bus width
! clock speed
! cache memory
Understand how different ports provide connection to Including connection to:
peripheral devices
! Universal Serial Bus (USB)
! High Definition Multimedia Interface (HDMI)
! Video Graphics Array (VGA)
Describe the stages of the Fetch-Execute (F-E) cycle Describe and use ‘register transfer’ notation to
describe the F–E cycle
Show understanding of the purpose of interrupts Including:
! possible causes of interrupts
! applications of interrupts
! use of an Interrupt service (ISR) handling routine
! when interrupts are detected during the fetch-
execute cycle
! how interrupts are handled
MUHAMMAD ALI KHAN
PAGE 103

CPU Architecture ENCE BY MAK


Control unit: The Control Unit makes
Von Neumann model decisions and sends the appropriate signal
down its lines to other parts of the
computer. It controls the timing of
Von Neumann introduced the idea of the stored
operations in the computer and controls the
program. Previously data and programs were stored in instructions sent to the processor and the
separate memories.von Neumann realized that data peripheral devices.

and programs are indistinguishable and can therefore


use the same memory.
Von Neumann architecture uses a single processor. It follows a linear sequence of !"#$%&
'"$('"&")"$*#"+operations for sequence of instructions which makeup the program. In+order
to do this a processor has to use some special registers.

A register is simply a location that can store extremely limited amount of instruction or data
only immediately before or after processing. The registers are outside the immediate access
store and consequently allow faster access to the data they store.

Processor uses a group of special purpose registers to execute a program

! Program counter (PC): Program counter is sometimes called sequence control


register. It stores the address of the next instruction to be fetched.
! Memory address register (MAR): When the next instruction is needed, its address
is copied from the PC and placed in the memory address register.
! Memory data registers (MDR): It is sometime called the memory buffer register
(MBR) because it acts like a buffer, temporarily storing a data value before passing it
on to e.g. CIR.
! Index register (IR): An index register in a computer's CPU is a processor
register used for modifying operand addresses during the run of a program , typically for
doing vector/array operations. If the address is an indexed address, add the address to
the contents of the index register to form the address of actual data.
! Current instruction register (CIR): Holds the instruction that is about to be executed.
! Status register: A status register, flag register, or condition code register is a
collection of status flag bits for a processor. The status register is a hardware
register which contains information about the state of the processor.

Role of arithmetic logic unit (ALU), control unit (CU) and system clock

Arithmetic logic unit

In digital electronics, an arithmetic logic unit (ALU) is a digital circuit that


performs arithmetic and bitwise logical operations on integer binary numbers. It is a
fundamental building block of the central processing unit (CPU) found in many computers. An
ALU performs basic arithmetic and logic operations. Examples of arithmetic operations are
addition, subtraction, multiplication, and division. Examples of logic operations are
comparisons of values such as NOT, AND, and OR.
MUHAMMAD ALI KHAN
PAGE 104

!"#$%"&' (#)$! The control unit is a component of a computer's central processing unit
(CPU) that directs operation of the processor. It tells the computer's memory, arithmetic/
logic unit and input and output devices how to respond to a program's instructions.

It directs the operation of the other units by providing timing and control signals. All
computer resources are managed by the CU (Control Unit).It directs the flow of data between
the Central Processing Unit (CPU) and the other devices.
MUHAMMAD ALI KHAN
PAGE 105

System clock

Every computer contains an internal clock that regulates the rate at which instructions are
executed and synchronizes all the various computer components. The CPU requires a fixed
number of clock ticks (or $,($-+$.$,"/) to execute each instruction. The faster the clock, the
more instructions the CPU can execute per second.
Clock speeds are expressed in mega hertz (MHz) or giga hertz ((GHz).

Clock rate0 the speed at which a microprocessor executes instructions.


Address bus

An address bus is a computer bus (a series of lines connecting two or more devices) that is
used to specify the address from/to which the CPU wishes to read or write. The number of
bits of address bus determines the maximum size of memory which the processor can access.
For example, a system with a 32-bit address bus can address 232 (4,294,967,296) memory
locations. If each memory address holds one byte, the addressable memory space is 4 GB.
Data bus

Data bus is used to carry the data that needs to be transferred from one hardware component
to another. The memory data register (MDR) is at one end of the data bus. The data bus is
bi-directional because same bus is used for data transmission from microprocessor to memory
location or input/output device and vice versa.
MUHAMMAD ALI KHAN
PAGE 106

Control bus

Control bus is used to send control signals from the control unit to the other components of
the system. A separate wire is dedicated to a particular control signal e.g.

! " A completed data transfer(read/write)operation!


" Reset button pressed!
" Interrupt request!
" Interrupt acknowledgement!

How bus width and clock speed affect the performance of the computer system

" The clock speed (or clock rate) is stated in megahertz (MHz) or gigahertz (GHz),
and refers to the speed at which the processor can execute instructions. The faster
! the clock, the more instructions the processor can complete per second.!
" The number of wires in data bus determines the quantity of data that the bus
can carry at any one time.!

" Increasing the data bus will increase the quantity of data the bus can carry at
one time so speeds up the performance/processing of the computer!

A compute with a data bus of 32 lines is called a 32 bit computer and word length
is 32.
MUHAMMAD ALI KHAN
PAGE 107

Ports:

In computer hardware, a port serves as an interface between the computer and


other computers or peripheral devices. Computer ports have many uses, to
connect a monitor, webcam, speakers, or other peripheral devices. On the physical
layer, a computer port is a specialized outlet on a piece of equipment to which
a plug or cable connects. Electronically it provides a method to transfer signals
between devices.
Hardware ports can be divided into two groups based on the signal transfer:
! " Serial ports send and receive one bit at a time via a single wire.!
" Parallel ports send multiple bits at the same time over several sets of wires.!
After ports are connected, they typically require handshaking, where transfer type,
transfer rate, and other necessary information is shared before data are sent. Plug-
and-play ports are designed so that the connected devices automatically start
handshaking as soon as they are connected. USB ports and FireWire ports are plug-
and-play.!
PAGE 108

MUHAMMAD ALI KHAN


PAGE 109

MUHAMMAD ALI KHAN


PAGE 110

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 111

1.4.2 The fetch-execute cycle


An instruction cycle (sometimes called fetch-and-execute cycle, fetch-decode-execute
cycle, or FDX) is the basic operation cycle of a computer. It is the process by which a
computer retrieves a program instruction from its memory, determines what actions the
instruction requires, and carries out those actions. This cycle is repeated continuously
by the central processing unit (CPU), from bootup to when the computer is shut down.

" Program counter (PC) - an incrementing counter that keeps track of the memory
address of the instruction that is to be executed next.!
" Memory address register (MAR) - holds the address of a memory block to be read
from or written to.!
" Memory data register (MDR) - a two-way register that holds data fetched from
memory (and ready for the CPU to process) or data waiting to be stored in memory.!
" Current Instruction register (IR) - a temporary holding ground for the instruction
that has just been fetched from memory.!
" Control unit (CU) - decodes the program instruction in the IR, selecting machine
resources such as a data source register and a particular arithmetic operation, and
coordinates activation of those resources.!
" Arithmetic logic unit (ALU) - performs mathematical and logical operations.!
MUHAMMAD ALI KHAN
PAGE 112

Description in the form of flowchart!"#$%&&'($!)*#+,-#.

Register transfer notation

1. [MAR] " [PC]


2. PC " [PC] + 1
3. MDR " [[MAR]]
4. CIR " [MDR]
5. DECODE
6. EXECUTE
7. GO TO STEP 1
MUHAMMAD ALI KHAN
PAGE 113

Step by step description of fetch-execute-cycle

1. Copy the address that is in program counter(pc)into the memory


address register (MAR)

!" Increment the PC (ready for next fetch)


#" Load the instruction that is in the memory address given by the MAR into the!memory data
register (MDR)

After increment
MUHAMMAD ALI KHAN
PAGE 114

4. The MBR loads the Current Instruction Register with the instruction to be executed.

!"#$%"$&$'("")*$+*,#**-$."/*$0/"'*))"/$'"/*)$"/$1$(23(*/$'4"'5$)0**%6
"#!$%!&%'()*'%+!,%-*.%/!,*(0!1.*2%##*.!2*.%#!3'+!24*25!#1%%+!3.%!%##%'()34!(*!*1%.3()'6!7*8.!
2*&18(%.9!:87)'6!3!2*&18(%.!$)(0!&84()14%!2*.%#!3'+!3!#81%.!0)60!24*25!#1%%+!#*8'+#!)+%34!;!,8(!
$03(!+*%#!(0)#!344!.%3447!&%3'!-*.!-8'2()*'34)(7!)'!7*8.!2*&18(%.<
:3#)23447/!03=)'6!3!0)60!24*25!#1%%+!,8(!>8#(!*'%!*.!($*!2*.%#!&%3'#!7*8.!2*&18(%.!$)44!,%!3,4%!(*!
4*3+!3'+!)'(%.32(!$)(0!3!#)'64%!3114)23()*'!?8)25479!@*'=%.#%47/!03=)'6!&*.%!1.*2%##*.!2*.%#/!,8(!3!
#4*$%.!24*25!#1%%+!&%3'#!7*8.!2*&18(%.!23'!$*.5!$)(0!&*.%!3114)23()*'#!3(!3!()&%/!,8(!%320!&37!
.8'!3!4)((4%!#4*$%.9
A0%'!2*&13.)'6!2*&18(%.#/!)(B#!&*#(!)&1*.(3'(!(*!(0)'5!3,*8(!7*8.!*$'!4)-%#(74%9!C*(!%=%.7*'%!
'%%+#!(0%!#3&%!4%=%4!*-!1.*2%##)'6!#1%%+#!*.!2*.%#9!A%B44!+)#28##!0*$!63&)'6!2*&18(%.#!3'+!+37;(*;
+37!$*.5!*.!1%.#*'34!2*&18(%.#!+)--%.!$0%'!)(!2*&%#!(*!(0%#%!-%3(8.%#!)'!3!,)(9!D).#(/!$%B44!6%(!)'(*!
$03(!(0%#%!&%3'!-*.!431(*1!3'+!+%#5(*1!2*&18(%.#9
PAGE 115

MUHAMMAD ALI KHAN


PAGE 116

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 117

1.4.3 The processor’s instruction set

An instruction set is a group of commands for a CPU in machine language. The instruction
set consists of multiple pieces, including addressing modes, instructions, native data types,
registers, memory architecture, interrupt, exception handling and external I/O.

Classification of instruction sets

Complex instruction set computer (CISC) has many specialized instructions, some of
which may only be rarely used in practical programs.

A reduced instruction set computer (RISC) simplifies the processor by only


implementing instructions that are frequently used in programs
MUHAMMAD ALI KHAN
PAGE 118

Instruction has two main parts

" Op code (abbreviated from operation code) is the portion of a machine language instruction
! that specifies the operation to be performed!
" Operand address or data on which the operation is to be performed.!

Addressing modes

! " Immediate!
" Direct!
" Indirect!
" Indexed!
" Relative!

Immediate addressing

Immediate addressing means that the data to be used is hard-coded into the instruction
itself.This is the fastest method of addressing as it does not involve main memory at all.

For example, you want to add 2 to the content of the accumulator

The instruction is:

ADD #2

Nothing has been fetched from memory; the instruction simply adds 2 to the accumulator

immediately. Immediate Addressing is very useful to carry out instructions involving


constants (as opposed to variables). For example you might want to use 'PI' as a constant
3.14 within your code.
MUHAMMAD ALI KHAN
PAGE 119

Direct addressing

This is a very simple way of addressing memory - direct addressing means the code refers
directly to a location in memory

For example SUB (3001)

In this instance the value held at the absolute location 3001 in RAM is subtracted from the

accumulator. The good thing about direct addressing is that it is fast (but not as fast as
immediate addressing) the bad thing about direct addressing is that the code depends
on the correct data always being present at same location.

It is generally a good idea to avoid referring to absolute memory addresses in order to


have 'relocatable code' i.e. code that does not depend on specific locations in memory.

You could use direct addressing on computers that are only running a single program. For
example an engine management computer only ever runs the code the car engineers
programmed into it, and so direct memory addressing is excellent for fast memory access.
MUHAMMAD ALI KHAN
PAGE 120

Indirect addressing
MUHAMMAD ALI KHAN
PAGE 121

Indexed addressing

The address is formed by the operand plus the number in the index register.

CIR
ADI 10 10 200
.
IR(index register) + .
150 .
160 120
accumulator
120 .
200 395
Index addressing is fast and is excellent for manipulating data structures such as arrays as
all you need to do is set up a base address (e.g. 10 in CIR) then use the index in your code
to access individual elements. Another advantage of indexed addressing is that if the array
is re-located in memory at any point then only the base address needs to be changed. The
code making use of the index can remain exactly the same.

Relative addressing

Quite often a program only needs to jump a little bit in order to jump to the next instruction.
Maybe just a few memory locations away from the current instruction. A very efficient way of
doing this is to just add a small offset to the current address in the program counter.
(Remember that the program counter always points to the next instruction to be
executed).This is called 'relative addressing'

DEFINITION:

Relative addressing means that the next instruction to be carried out is an offset number
of locations away, relative to the address of the current instruction. Consider this bit of
pseudo-code:

jmp +3 if accumulator == 2
Code executed if accumulator is NOT = 2
jmp +5 (unconditional relative jump to avoid the next line of code)
acc:
Code executed if accumulator is = 2)
Carry on:

In the code snippet above, the first line of code is checking to see if the accumulator has the
value of 2 in it. If it is has, then the next instruction is 3 lines away. This is called a conditional
jump and it is making use of relative addressing.
Another example of relative addressing can be seen in the jmp +5 instructions. This is telling the
CPU to effectively avoid the next instruction and go straight to the 'carryon' point.
MUHAMMAD ALI KHAN
PAGE 122

Summary of addressing modes

Application of all addressing modes


MUHAMMAD ALI KHAN
PAGE 123

!"#$%&%'($)*)%#+$,$-.*/-%$%0/1+12$
3%$-,#$-4/#5$+*$+.%$6,1+$*'$
%)7',-%$+.%$/#%&/+,7/4/+($*8$
-.,#5%$,#9$,44*:$,$7'/5.+%'$
8;+;'%$+*$;#8*49$7%8*'%$;12$<;-.$
,#$;#-%'+,/#$8;+;'%$),($-,44$8*'$
%&%#$)*'%$;#-%'+,/#$,44/%12$
=/+.%'$:,(>$,$#%:$9,($/1$-*)/#5$
:.%+.%'$:%$4/?%$/+$*'$#*+2$@.%$
A;%1+/*#$/1$:/44$(*;$-*#+'*4$/+>$*'$
:/44$/+$-*#+'*4$(*;BC
PAGE 124

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 125

5 System Software
5.1 Operating System
Candidates should be able to: Notes and guidance
Explain why a computer system requires an Operating
System (OS)
Explain the key management tasks carried out by the Including memory management, file management,
Operating System security management, hardware management
(input / output / peripherals), process management
Show understanding of the need for typical utility Including disk formatter, virus checker,
software provided with an Operating System defragmentation software, disk contents analysis/disk
repair software, file compression, back-up software
Show understanding of program libraries Including:
! software under development is often constructed
using existing code from program libraries
! the benefits to the developer of software
constructed using library files, including Dynamic
Link Library (DLL) files

5.2 Language Translators


Candidates should be able to: Show Notes and guidance
understanding of the need for:
! assembler software for the translation of an
assembly language program
! a compiler for the translation of a high-level
language program
! an interpreter for translation and execution of a
high-level language program
Explain the benefits and drawbacks of using either a
compiler or interpreter and justify the use of each
Show awareness that high-level language programs
may be partially compiled and partially interpreted,
such as Java
Describe features found in a typical Integrated Including:
Development Environment (IDE) ! for coding, including context-sensitive prompts
! for initial error detection, including dynamic
syntax checks
! for presentation, including prettyprint, expand
and collapse code blocks
! for debugging, including single stepping,
breakpoints, i.e. variables, expressions, report
window
MUHAMMAD ALI KHAN
PAGE 126

1.5.1 Operating system

Why a computer system requires an operating system

An operating system (OS) is software that manages computer


hardware and software resources and provides common services for computer
programs. The operating system is an essential component of the system
software in a computer system.

Application programs usually require an operating system to function. The application


programs make use of the operating system by making requests for services through
a defined application program interface (API).

Operating systems perform basic tasks, such as recognizing input from


the keyboard, sending output to the display screen, keeping track of files and
directories on the disk, and controlling peripheral devices such as disk
drives and printers.

Summary

" ! OS system manages the physical resource of computer"


! OS provides the interface between human user and computer"
! It provides a platform for applications softwares to run"
! It hides the complexity of hardware from the user"
! It provides security e.g. passwords on files and access rights for
different users."
MUHAMMAD ALI KHAN
PAGE 127

Types of Operating System

Batch Processing:

When computing was still a new science, there were not enough machines to satisfy
the demand for processor time from students in universities who wanted great
calculations done, firms who wanted their payroll worked out, and many others. The
big problem was the ‘speed mismatch’ between the user sitting at the keyboard who
was very slow, and the machine which was very fast. This meant that the expensive
part, the computer, was sitting there doing nothing while the human being decided
what to do. There are two simple solutions to this problem, one is to buy more
machines and the other is to make the machines work more effectively by taking
away the slowest part of the system “the human being”. Nowadays we might well
opt to buy more machines, but was too costly in the past. This problem gave rise to
the development of batch processing.

A Batch processing OS is one that does not allow for interaction between the user
and the processor during the execution of the work. Lots of programs or data that
need to be run are collected together (to form a batch) and they are sent to the
computer in one go. The batch operating system then controls their passage through
the computer.

Nowadays, batch processing is used where:

" ! Processing cannot be started until all the data is collected"


! Large amounts of data to be processed,"
! The data is very similar in nature and…"
! Requires similar processing,"
! The computer system has identifiable times when it is not being used, and so
" has available processor time"
! The application does not require human intervention."

Example of applications of the Batch processing OS:

" ! In banks for the production of bank statements from customer files"
! The production of utility bills from customer records"
! Compilation of high level language programs where a number of users want
programs compiled."

Real-time processing:

A real-time O.S. is one which can react quickly enough to a process and get ready
for the next input or process to be carried out.
The following examples of real-time applications show why immediate response can
be vital:

! In a chemical plant the temperature is critical to the result of the process. The
temperature is monitored by a compute that accepts input from a sensor. The
compute uses the sensor data to make decisions about adjusting"
MUHAMMAD ALI KHAN
PAGE 128

the heating elements. A delay in the decision-making process might corrupt


the reaction.
! A robot trolley is controlled by a processor that takes input from a sensor
following a blank line of the floor. The processor makes decisions about
steering to keep the trolley on the black line. The trolley might lose its
" directions if it was not steering quickly enough."
! A catalogue shop processes orders. The code for a product is input and the
system compared it with information in its files. When it finds the correct code,
it can report to the user the quantity of that product in stock. It is necessary
to record a purchase before the next shopper’s request is processed otherwise
the second person might be sold the same item."

Single user

A single user operating system controls a system which has only one user and their
programs at one time. A perfect example of a single user system is the one that you
may have at home. Only one person uses it at a time. Most single user systems are
also multi-tasking.

Multi-user

This type of operating system allows the computer to service more than one user
simultaneously. A multi-user OS has a single (normally powerful) computer which is
connected to a number of terminals. These terminals are not computers, although
they may have a very limited amount of processing power.

The computer sends a message to each of the terminals in turn which is called a
time-share or a round robin system. Each of the small amount of time is called a
“time slice”.

Multi-tasking

A multi-tasking allows several applications to be available simultaneously. On a single


user system, you might load number of processes in main memory at the same time.
e.g. spreadsheet along with a word processing application and browsing internet as
well as playing music etc.

The OS can switch between tasks so quickly that it seems to the user as if they are
all being done at once. The tasks are allocated time slices similar to multi-user OS.

Network OS

A network contains number of computers linked together for the purpose of


communication and the sharing of resources. A network operating system is required
to manage the network computers and resources. One machine is used to control
rest of the system which is called server. A network OS must carry out tasks such as

" ! Control of access to the network"


! Management of the filing system"
! Managing all application programs available from the server"
! Management of all shared peripherals."
MUHAMMAD ALI KHAN
PAGE 129

1.5.2 Utility programs

Disk formatter

When a disk is first produced the surface is blank. It cannot be used to store data
until it has been formatted by disk formatter software. The formatting process divides
the disk into smaller areas, each of which can be searched more easily.
The disk surface is divided into a number of tracks an each track is divided into
smaller blocks called sectors.

The amount of information that can be stored is enormous. One of the tracks is used
as an index to hold data about where the other data are stored. The formatting
process removes all data from the disk so you should save the contents of a disk
elsewhere before re-formatting it.

Virus checker

A computer virus is a small program that can reproduce itself. If it “infects” a


computer system, a virus can cause a range of damage including deleting files.

A virus checker utility program continually compares a dictionary of known viruses


against the files accessed by the computer. It alerts the user if any of the files
matches a virus “signature”.

It is crucial that the virus dictionary is kept up-to-data o a daily basis as new viruses
are constantly appearing.

Defragmenter software

it is a utility software to increase access speed by re-arranging files stored on a disk


to occupy contiguous storage locations, a technique called defragmentation.
Defragmenting a disk minimizes head travel, which reduces the time it takes to read
files from and write files to the disk. Disk Defragmenter also reduces system startup
times.

Disk content analysis /Disk repair software

Disk checker software can scan a hard disk to find files or areas that are corrupted
in some way, or were not correctly saved, and eliminate them for a more efficiently
operating hard drive. This is not to be confused with a disk cleaner, which can find
MUHAMMAD ALI KHAN
PAGE 130

files that are unnecessary to computer operation, or take up considerable amounts


of space.

Some disk checkers can perform a whole surface to attempt to find any possible bad
sectors, whereas others scan only the contents of the hard disk.

File compression

Files containing video information are usually large in size. File compression software
reduces the size of a file by cutting out much of the duplication of data in the file.

If file is to be sent electronically e.g. a an email attachment, you can use a utility
(such as WinZip) to compress .files may also be compressed to save space on a
secondary storage device.

Backup software

Files on a computer need to be protected from being damaged. A backup or archiving


utility is a simple routine that copies the contents of files to another location. If the
original file is damaged, the copy can be used to replace it.

Key feature of backup software

Volumes: Voluming allows the ability to compress and split backup data into
separate parts for storage on smaller, removable media such as CDs. It was
often used because CDs were easy to transport off-site and inexpensive
compared to hard drives or servers. However, the recent increase in hard drive
capacity and decrease in drive cost has made voluming a far less popular
solution
Data compression: Since hard drive space has cost, compressing the data
will reduce the size allowing for less drive space to be used to save money.
Differential and incremental backups: Backup solutions generally support
differential backups and incremental backups in addition to full backups, so
only material that is newer or changed compared to the backed up data is
actually backed up. The effect of these is to increase significantly the speed of
the backup process over slow networks while decreasing space requirements.
Encryption: To prevent data theft, some backup software offers cryptography
features to protect the backup.
MUHAMMAD ALI KHAN
PAGE 131

1.5.3 Library programs

In computer science, a library is a collection of non-volatile resources used by


computer programs, often to develop software. These may include configuration
data, documentation, help data, message templates, pre-written code and
subroutines, classes etc. Library code is organized in such a way that it can be used
by multiple programs that have no connection to each other, while code that is part
of a program is organized to only be used within that one program.

What is DLL?

A DLL is a library that contains code and data that can be used by more than one
program at the same time. For example, in Windows operating systems, the
Comdlg32 DLL performs common dialog box related functions. Therefore, each
program can use the functionality that is contained in this DLL to implement an Open
dialog box. This helps promote code reuse and efficient memory usage.

Updates are easier to apply to each module without affecting other parts of the
program. For example, you may have a payroll program, and the tax rates change
each year. When these changes are isolated to a DLL, you can apply an update
without needing to build or install the whole program again.

DLL advantages

The following list describes some of the advantages that are provided when a program
uses a DLL:

Uses fewer resources

When multiple programs use the same library of functions, a DLL can reduce the
duplication of code that is loaded on the disk and in physical memory. This can
greatly influence the performance of not just the program that is running in the
foreground, but also other programs that are.

Promotes modular architecture

A DLL helps promote developing modular programs. This helps you develop large
programs that require multiple language versions or a program that requires
modular architecture. An example of a modular program is an accounting program
that has many modules that can be dynamically loaded at run time.

Eases deployment and installation

When a function within a DLL needs an update or a fix, the deployment and
installation of the DLL does not require the program to be re-linked with the DLL.
Additionally, if multiple programs use the same DLL, the multiple programs will all
benefit from the update or the fix. This issue may more frequently occur when you
use a third-party DLL that is regularly updated or fixed.
MUHAMMAD ALI KHAN
PAGE 132

1.5.4 Language translators

Assembler

It converts the code written in assembly language into machine language. The
assembly process is relatively simple because assembly language has a one-to-one
relationship with machine code. That is, every assembly language instruction
translates into exactly one machine code instruction.

Basically the assembler translate the mnemonics (e.g. LDA,STO)into binary by having
a simple lookup table with mnemonics in one column and the binary machine code
equivalents alongside.

Advantages of using an Assembler disadvantages of using an Assembler

1. Very fast in translating assembly 1. Assembly language is written for a


language to machine code as 1 certain instruction set and/or
to 1 relationship processor
2. Assembly code is often very 2. Assembly tends to be optimized for
efficient (and therefore fast) the hardware it's designed for,
because it is a low level meaning it is incompatible with
language different hardware
3. Assembly code is fairly easy to 3. Lots of assembly code is needed to
understand due to the use of do relatively simple tasks, and
English-like mnemonics complex programs require lots of
programming time

Compiler

A compiler takes a program written in a high-level language(source program)and


translates it into an equivalent program in machine code(object program).once this
is done, the machine code version can be loaded into the machine an executed
without any further need of compiler.

Advantages of using a compiler disadvantages of using a compiler

1. The final object (.exe) can easily 1. The final object file can only be
be distributed among many users. produced after all errors in source
2. Once the .exe file is produced, code have been located and fixed.
users do not need the compiler 2. The compilation process uses a lot
software. of computer resources.
3. Users have no sight of the original
source code and so there is no
risk that it could be changed.
MUHAMMAD ALI KHAN
PAGE 133

Interpreter

The interpreter identifies each instruction in sequence and executes it until a


statement is found which contains an error. Each instruction is executed before the
next instruction is identified.

Advantages of using an interpreter disadvantages of using an interpreter

1. The programmer can run the 1. Execution of a program is slow


program at any time before all compared to that of a compiles
the code has been written programduetoline-by-line
2. Debugging is generally easier translation.
and faster using an interpreter 2. The interpreter software has to be
present in memory every time an
attempt is made to run the program

!"#$"%&&'($)*#+,-%".)%(/),0.)123
!"#$#%&$#%'&()%*$+,$&''-(,%.&(,/&,#01%!+%#2#3/4#5%4"#)%"&6#%4+%7#%3+'*-.#8%+$%
-(4#$*$#4#81%9(%:;<%=-(4#,$&4#8%8#6#.+*'#(4%#(6-$+('#(4>%-0%/0#8%4+%?$-4#%3+8#5%4#04%
@+$%#$$+$0%&(8%4$&(0.&4#%&%*$+,$&'1:;<
9(%-(4#,$&4#8%8#6#.+*'#(4%#(6-$+('#(4%=:;<>%-0%&(%&**.-3&4-+(%/0#8%4+%3$#&4#%
0+@4?&$#1%9(%:;<%3&(%+@4#(%0/**+$4%8-@@#$#(4%.&(,/&,#01

123*)"&6#%&%(/'7#$%+@%8-@@#$#(4%4++.0%&(8%@/(34-+(0%4"&4%&00-04%&%8#6#.+*#$%-(%4"#%
3$#&4-+(%+@%0+@4?&$#1

4#/.)./',#"
!"#%#(6-$+('#(4%?"#$#%4"#%/0#$%3&(%?$-4#%3+8#%-0%3&..#8%4"#%0"#..1%!"#%3+8#%#8-4+$%-0%
&%4#24%#8-4%&$#&%4"&4%&..+?0%8#6#.+*#$0%4+%?$-4#5%#8-4%&(8%0&6#%&%8+3/'#(4%+@%3+8#1%:4%
"&0%@#&4/$#0%4"&4%&00-04%?-4"%4"#%?$-4-(,%&(8%#8-4-(,%+@%3+8#1%!"#0#%-(3./8#A

56,#78#&9:.,'#();#")8#/.)8#&9:.,'#(<=)!"-0%-0%8#0-,(#8%4+%0&6#%4-'#%?"-.#%
?$-4-(,%3+8#1%90%)+/%04&$4%4+%4)*#%4"#%@-$04%*&$4%+@%&%@/(34-+(5%-4%0/,,#040%+$%3+'*.#4#0%
4"#%@/(34-+(%&(8%&()%&$,/'#(40%+$%6&$-&7.#01
B$&3C#4%'&43"-(,1%!"-0%-0%/0#8%@+$%.&(,/&,#0%4"&4%/0#%*&-$0%+@%7$&3C#40%4+%'&$C%+/4%
7.+3C0%+@%3+8#1%:4%&..+?0%4"#%3+8#%4+%7#%$#&8%&(8%/(8#$04++8%'+$#%D/-3C.)1%:@%)+/%
@+$,#4%4+%3.+0#%&%7$&3C#4%?"-.#%?$-4-(,5%3+.+/$#8%0#34-+(0%'&)%"#.*%)+/%4+%8#4#34%
'-00-(,%7$&3C#401
>?(,%@)80.8A*=%!"-0%$#3+,(-0#0%-(3+$$#34%/0#%+@%0)(4&2%&(8%"-,".-,"40%&()%#$$+$01
PAGE 134

MUHAMMAD ALI KHAN


PAGE 135

MUHAMMAD ALI KHAN


PAGE 136

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 137

6 Security, privacy and data integrity


6.1 Data Security
Candidates should be able to: Notes and guidance
Explain the difference between the terms security,
privacy and integrity of data
Show appreciation of the need for both the security of
data and the security of the computer system
Describe security measures designed to protect Including user accounts, passwords, authentication
computer systems, ranging from the stand-alone PC techniques such as digital signatures, firewall, anti-
to a network of computers virus software, anti-spyware, encryption
Show understanding of the threats to computer and Including malware (virus, spyware), hackers, phishing,
data security posed by networks and the internet pharming
Describe methods that can be used to restrict the risks
posed by threats
Describe security methods designed to protect the Including encryption, access rights
security of data

6.2 Data Integrity


Notes and guidance

Including range check, format check, length check,


presence check, existence check, limit check, check
digit
During data entry including visual check, double entry
During data transfer including parity check (byte and
block), checksum

1.6.1 Data security

Information/data security

Information security, sometimes shortened to InfoSec, is the practice of defending


information from unauthorized access, use, disclosure, disruption, modification,
perusal, inspection, recording or destruction. It is a general term that can be used
regardless of the form the data may take (e.g. electronic, physical).
MUHAMMAD ALI KHAN
PAGE 138

IT Security

Information security means protecting information and information systems from


unauthorized access, use, disclosure, disruption, modification or destruction. The
terms information security, computer security and information assurance are
frequently incorrectly used interchangeably. These fields are interrelated often and
share the common goals of protecting the confidentiality, integrity and availability of
information; however, there are some subtle differences between them. Information
security is concerned with the confidentiality, integrity and availability of data
regardless of the form the data may take: electronic, print, or other forms. Computer
security can focus on ensuring the availability and correct operation of a computer
system without concern for the information stored or processed by the computer.

Confidentiality

Confidentiality is the term used to prevent the disclosure of information to


unauthorized Individuals or systems. For example, a credit card transaction on the
Internet requires the credit card number to be transmitted from the buyer to the
merchant and from the Merchant to a transaction processing network. The system
attempts to enforce confidentiality by encrypting the card number during
transmission, by limiting the places where it might appear (in databases, log files,
backups, printed receipts, and so on), and by restricting access to the places where
it is stored. If an unauthorized person obtains the card number in any way, a breach
of confidentiality has occurred.

Breaches of confidentiality take many forms. Someone looking at your computer


screen behind your back while you have confidential data displayed on it could be a
breach of confidentiality. If a laptop computer containing sensitive information about
a company's employees is stolen or sold, it could result in a breach of confidentiality.
Giving out confidential information over the telephone is a breach of confidentiality if
the caller is not authorized to have the information. Confidentiality is necessary (but
not sufficient) for maintaining the privacy of the people whose personal information
a system holds.
MUHAMMAD ALI KHAN
PAGE 139

Integrity

In information security, integrity means that data cannot be modified without


permission. Integrity is violated when an employee accidentally or with malicious
intent deletes important data files, when a computer virus infects a computer, when
an employee is able to modify his own salary in a payroll database, when an
unauthorized user vandalizes a web site, when someone is able to cast a very large
number of votes in an online poll, and so on. There are many ways in which integrity
could be violated without malicious intent. In the simplest case, a user on a system
could mis-type someone's address. On a larger scale, if an automated process is not
written and tested correctly, bulk updates to a database could alter data in an
incorrect way, leaving the integrity of the data compromised. Information security
professionals are tasked with finding ways to implement controls that prevent errors
of integrity.

System Security measures

1.Authentication and Authorization

Remove or disable accounts upon loss of eligibility: Accounts which are no longer
needed must be disabled in a timely fashion using an automated or documented
procedure.
Separate user and administrator accounts: Administrator accounts must not be used
for non-administrative purposes. System administrators must be provisioned with
non-administrator accounts for end-user activities, and a separate administrator
account that is used only for system-administration purposes.
Use unique passwords for administrator accounts: Privileged accounts must use
unique passwords that are not shared among multiple systems. Credentials which
are managed centrally, such as the NetID/password combination, are considered a
single account, regardless of how many systems they provide access to.
Throttle repeated unsuccessful login-attempts: A maximum rate for unsuccessful
login attempts must be enforced. Account lockout is not required, but the rate of
unsuccessful logins must be limited.
Enable session timeout: Sessions must be locked or closed after some reasonable
period.
Enforce least privilege: Non-administrative accounts must be used whenever
possible. User accounts and server processes must be granted the least-possible level
of privilege that allows them to perform their function.

2. Firewall
Systems must be protected by a firewall that allows only those incoming connections
necessary to fulfill the business needs of that system. Client systems which have no
business need to provide network services must deny all incoming connections.
Systems that provide network services must limit access to those services to the
smallest reasonably manageable group of hosts that need to reach them.
MUHAMMAD ALI KHAN
PAGE 140

A firewall is a software program or piece of hardware that helps screen out hackers,
viruses, and worms that try to reach your computer over the Internet.

3.Password Protection
All accounts and resources must be protected by passwords which meet the
following requirements, which must be automatically enforced by the system:
" ! Must be at least eight characters long."
! Must NOT be dictionary or common slang words in any language, or be
" relatively easy to guess."
! Must include at least three of the following four characteristics, in any order:
upper case letters, lower case letters, numbers, and special characters, such
as “! @#$%^&*”."
! Must be changed at least once per year."
4. Digital signature
It is basically a way to ensure that an electronic document (e-mail, spreadsheet, text
file, etc.) is authentic. Authentic means, you know who created the document and
you know that it has not been altered in any way since that person created it.
Digital signatures rely on certain types of encryption to ensure authentication.
Encryption is the process of taking all the data that one computer is sending to
another and encoding it into a form that only the other computer will be able to
decode.
Authentication is the process of verifying that information is coming from a trusted
source. These two processes work hand in hand for digital signatures.
MUHAMMAD ALI KHAN
PAGE 141

Security measures designed to protect the security of data


Data Backup: Data protection is crucial for protecting your business's continuity. If
your only data backup is on a computer and the hard disk crashes or is damaged by
a power surge, your business’s data is gone. And having paper copies of business
data isn't adequate data protection; what if your business premises burns to the
ground or destroyed in a flood? Once again the data you need to carry on your
business could be irretrievably lost.
" ! Methods of data backups"
! Archiving Critical Business Data"
! Creating physical data backups"
! Creating off-sight backups"
! Real-time backups take place at any time and must have a procedure for
handling files that are open during backup. In most cases, the backup system
" tracks open files and returns to back them up later."
! Disk mirroring is a real-time strategy that writes data to two or more disks at
the same time. If one disk fails, the other continues to operate and provide
access for users. Server mirroring provides the same functionality, except that
an entire server is duplicated. This strategy allows users to continue accessing
data if one of the servers fails. See "Fault Tolerance and High Availability" for
" additional information on these strategies."
! Replication copies information to alternate servers on distributed networks to
make that information more readily available to people in other locations.
While replication is not necessarily a backup technique, replicated data on
remote servers can be made available to local users if the server close to them
" goes down."
! Remote vaulting is an automatic backup technique that transmits data to
alternate sites. The alternate sites can be more than just warehouses for
backups. They may be entire data centers that can be brought online when the
primary data center goes offline in the event of a major disaster."

Encryption
Encryption involves applying a mathematical function, using a key value, to a
message that can only be read by the sender and the intended receiver. There
are many techniques for this. There are a number of terms used with encryption.
" ! Plain text describes the original unaltered text as created by the sender."
! Encryption algorithm is the calculation which is used to change the plain
text into the encrypted text"
! Cipher text is the message text after the encryption has been performed"
! Decryption is the process of converting the message text back to the"
original pliant text
Symmetric encryption
It is the simplest technique for encryption. The same algorithm and key is used
for both encryption and decryption. The receiver therefore must be in possession
of both the algorithm and the key in order to decrypt the cipher text.
MUHAMMAD ALI KHAN
PAGE 142

Asymmetric encryption
Most modern systems of encryption use the idea of two keys working together,
a public key and a private key.
The public key is universally known and the private key is known only to the
holder.
To use asymmetric encryption, the user must purchase a digital certificate from
a certification authority, such as versign.The certificate contains
" ! The holder’s name"
! An ID number"
! An expiry date"
! The public
" key How it works?"
Suppose Ahmad and Ali each has a digital certificate which gives each their own
public and private keys. So according to rule"
! Ahmad never knows ali’s private key"
! Ali never knows Ahmad’s private key"
MUHAMMAD ALI KHAN
PAGE 143

1.6.2 Data integrity


Data validation
Validation is a check on DATA INPUT to the system by comparing the data input
with a set of rules that the computer software has been programmed to
implement. If the data does not match up with the rules then there must be an
error. There are many different types of validation checks that can be used to
check input in different applications:
. Range check. A mathematics exam is out of 100. A simple validation rule that
the computer can apply to input data is that the mark must be between 0 and 100
inclusive. Consequently, a mark of 101 would be rejected by this check as being
outside the acceptable range.
2. Character check. A person’s name will consist of letters of the alphabet and
sometimes a hyphen or apostrophe. This rule can be applied to input of a person’s
name so that “dav2d” will immediately be rejected as unacceptable.
3. Format check. A particular application is set up to accept a national insurance
number. Each person has a unique national insurance number, but they all have
the same format of characters, 2 letters followed by 6 digits followed by a single
letter. If the computer knows this rule then it knows what the format of a NI
number is and would reject “ABC12345Z” because it is in the wrong format, it
breaks the rule.
4. Length check. A NI number has 9 characters, if more or fewer than 9
characters are keyed in then the data cannot be accurate.
5. Existence check. A bar code is read at a supermarket check-out till. The code is
sent to the main computer which will search for that code on the stock file. If the
code is found in the stock file then it is known to exist and is accepted.
6. Check digit. When the code is read on the item at the supermarket, it consists
of numbers. One number is special; it is called the check digit. If the other
numbers have some arithmetic done to them using a simple algorithm the answer
should be this special digit. When the code is read at the check-out till, if the
arithmetic does not give the check digit it must have been read wrongly, it is at
this point that the beeping sound would normally be heard if everything is alright.
7. Presence check. A value must be present when filling in an online form, the
system does not allow the user to progress to the next data item unless some
input to the present value is provided. (Be careful about distinguishing between
existence and presence checks, they are often confused by candidates in exam
questions)
8. Uniqueness check: This check makes sure that a certain field is unique.
9. List check: only a limited number of values are allowed e.g. the gender of a
person must be M or F, usually implemented by drop down list.
MUHAMMAD ALI KHAN
PAGE 144

Data verification
Verification means checking the input data with the original data to make sure
that there have been no transcription errors (transcription means copying the
data)
Verification can be performed in a few ways
1. Entering the data twice: think about you choose a new password, you have
to type it in twice. This lets the computer check if you have typed it exactly
the same both times and not made a mistake. It is not ideal for large
amount of data because a person will take a lot of time entering the data
twice, the person can make the same mistake twice so it wouldn’t get
picked up and you would end up with two copies of the data.
2. Checking the data on screen with the original paper document
3. Printing out a copy of the data and comparing the printout to the original
paper document.

Data verification during transmission


Parity check
A parity check involves checking that the number of 1 bits in a byte totals to an
even number (called “even parity”) or an odd number (called “odd parity”).
If two devices that are communicating decide to use off parity, there must always
be an odd number of 1’s,an error must have occurred .e.g. the byte 01011000 is
sent, it has three 1 bits so it passes the odd parity check. When it is transmitted
the byte received is 11011000.this has four 1 bits, which is an even number so
there must have been an error in transmission. The receiving device would ask
for it to be sent again.
Parity is also used when data are transferred between different components of
CPU.
If two mistakes are made in the same byte they cancel each other out and the
faulty data are accepted. This problem can be overcome using parity blocks.
Parity block
It is a group of byte with an additional parity byte. The data bytes and parity bytes
are together called parity block
MUHAMMAD ALI KHAN
PAGE 145

Check Sum: Data will normally be sent from one place to another as a block of
bytes rather than as individual bytes. The computer can add numbers together
without any trouble, so another checking procedure is to add all the bytes together
that are being sent in the block of data. The carry, out of the byte, is not taken
into account, so the answer is an 8 bit number, just like the bytes. This answer is
calculated before the data is sent, and then calculated again when it is received,
and if there are no errors in the transmission, the two answers will match.if,
however the two bytes are different there must be at least one checksum that has
been corrupted and the whole block of data has to be re-sent.

Echoing back
The simplest way of checking the transfer of the data is to send the data back
again. If the data sent back are the same as the data sent in the first place then
the original data must have reached the destination unaltered. If not, the data
must be sent again. This is known as echoing back. This method is very effective,
but suffers from having to send data twice. The transmission mode needs to be
either duplex or half duplex to allow data transfer in both directions.
PAGE 146

MUHAMMAD ALI KHAN


PAGE 147

MUHAMMAD ALI KHAN


PAGE 148

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 149

7.1 Ethics and Ownership


Notes and guidance
Understand the importance of joining a professional
ethical body including BCS (British Computer Society),
IEEE (Institute of Electrical and Electronic Engineers)

Licences to include free Software Foundation, the


Open Source Initiative, shareware and commercial
software
Understand the impact of AI including social,
economic and environmental issues
Understand the applications of AI

Word/phrase Meaning
code of conduct a set of rules governing the behaviour of a
group or organisation (e.g. computer
professionals)
computer ethics moral principles governing the design,
building, implementation and use of computer
systems
copyright the legal right to intellectual property
freeware copyrighted software that is available free of
charge
intellectual property something unique that has been physically
created by someone (an idea that hasn’t been
implemented is not intellectual property)
licence a permit to use/distribute/copy/adapt software
open source software software that can be freely copied, distributed
and adapted
shareware copyrighted software that is available free of
charge for a limited period, after which a
licence must be obtained
MUHAMMAD ALI KHAN
PAGE 150

!"#$%#&'%'$"()*+%
Societies are a collection of individuals, each having their own ideas and beliefs about the type
of behaviour that is acceptable, or not acceptable. These ideas and beliefs can vary widely, and
what one person believes is good and right, another may see as bad and wrong. To make sure
that societies function successfully, they develop principles that define what is morally good and
right behaviour for individuals and the society itself. These principles are known as ethics.
Computer ethics are a set of principles that define what is morally good and right behaviour
when using computers. These ethics cover:
computers’ contribution to the health, safety and welfare of the public
privacy
intellectual property rights (copyright)
censorship.

Computers have an increasingly central role in society, industry, commerce, education, health
and medicine, warfare and government. With so many people using, and being affected by
computers, it is extremely important to have ethics that relate to the design, behaviour and use
of computer systems.
!"!#$%&'(#%)#*%+&,*-#
A code of conduct is a set of rules or practices defining how a group or organisation should
behave – organisations such as businesses, schools, and hospitals have codes of conduct.
Many codes contain rules that seek to protect the organisation from the behaviour of individuals,
as well as protecting the individuals within the organisation. For example, a school’s code of
conduct may include rules about behaviour, dress codes, bullying and respect for others and
their property.
Codes of conduct are also applied to computers and their use. They seek to make sure that
computers are used safely and lawfully, and to protect the interests of organisations and
individuals.
Computer professionals in particular have a need to follow codes of conduct. The computer
systems they design, build, implement and use may have a great impact on, for example, the
success of an organisation, the protection and privacy of its employees, and the protection,
privacy and safety of the public. When designing and building systems, software developers
(engineers) have opportunities to cause harm to their clients and to the public, such as:
failing to make sure their software is fit for purpose (for example, consider the implications of
a safety system that has faulty software)
including malicious software designed to spread malware
including unauthorised and undeclared ways into the system (backdoor) so that they can later
gain access without their client’s knowledge.

In order to prevent these types of behaviour and their consequences, computer codes of conduct are
becoming increasingly important.
MUHAMMAD ALI KHAN
PAGE 151

2.3 The ACM/IEEE Software Engineering Code of Ethics


Organisations exist that aim to provide standards for professionals. Two organisations that
represent computing professionals are the Association for Computing Machinery (ACM), and
the Institute of Electrical and Electronics Engineers (IEEE) Computer Society. Between them,
these organisations developed the ACM/IEEE Software Engineering Code of Ethics. These
ethics aim to provide rules, standards and protection for software developers and their clients.
The Code of Ethics has eight principles:
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 lifelong learning regarding the practice of their
profession and shall promote an ethical approach to the practice of the profession. Source:
http://www.acm.org/about/se-code
Collectively, these principles seek to ask software engineers to: behave ethically and to use
ethical judgement in their work, as opposed to blindly following rules or client instructions; to
consider who is affected by the decisions they make; and to put the welfare and safety of the
public above everything else.
2.4 Applying the ACM/IEEE Code of Ethics principles
2.4.1 The Google self-driving Car
The ‘Google car’ is a concept for a self-driving car that autonomously takes the passenger
where they wish to go. When designing, building and testing the software for the car, Google’s
software developers had one principle placed above all others: the safety of the passenger and
the public. In doing so, Google’s developers had to consider ethical questions about safety and
breaking the law.
Consider this situation: a passenger in a Google car may fall ill and need urgent hospital attention. The
Google car is programmed to stay within speed limits, even if the road is clear. However, keeping to the
speed limit may mean that the passenger does not receive medical treatment in time. Google’s
developers have to consider the ethical considerations of both the passenger and the public at large. In
this situation, speeding may endanger the public, but driving legally might endanger the passenger.
What should the car do?
2.4.2 The smartwatch
The introduction of smartwatches has raised privacy concerns that developers have had to
address. Many smartwatches have health-monitoring facilities such as detection of heart rate
and the amount of exercise the user has undertaken. The data from this monitoring is often sent
over the internet to third-party applications, to help users monitor their fitness. Developers have
an ethical duty to make sure that this data remains private: developers of the watch need to
make sure that the data is transmitted securely, and developers of the third-party applications
have to make sure that the data remains private.
2.4.3 Borland Interbase
MUHAMMAD ALI KHAN
PAGE 152

Developers at Borland included a backdoor in their Interbase database product to make sure
that a client could never be accidentally locked out of their database. This backdoor could be
accessed over the internet. When knowledge of this backdoor became public, Borland were
faced with the possibility that any client’s database could be accessed by an unauthorised user.
From an ethical point of view, Borland originally included the backdoor with the aim of protecting
their clients’ data. After the backdoor was exposed, Borland acted ethically and closed the
backdoor through issuing a software patch.
2.4.4 Network monitoring
In the workplace, computer users might find themselves placed in a situation with conflicting
ethics. For example, the management of a company might suspect that an employee is wasting
work time accessing social networking sites on the company’s computers. This highlights the
importance of having a computer code of conduct in place. If the code of conduct forbids access
to social networking sites via the company’s computers, then the management have an ethical
right to check that the code is being upheld. Without a code, checking on the employee could be
considered an invasion of privacy. However, even with a code of conduct, to behave ethically
the company could only check on those employees for whom they have evidence of unethical
behaviour, as employees’ privacy must still be considered.
2.5 Ownership
When we create something unique, we have ownership of it. The thing that has been created
(which in computing, could be software or hardware, but not simply an idea) is known as
intellectual property. Copyright laws exist to protect our intellectual property. Copyright gives an
individual (or an organisation) the sole and exclusive right to copy intellectual property, sell it,
develop it or license it to others. Copyright makes it illegal for anyone else to duplicate,
replicate, sell or license to others our intellectual property.
Many countries have copyright laws. For example, in the United Kingdom the Copyright,
Designs and Patents Act (1998) protects intellectual property, and the United States of America
has the Copyright Act of 1976.
A lot of intellectual property exists in digital format. Computers make the copying and
distribution of digital property very easy, meaning that unauthorised copies can also be easily
made and distributed. Money made from these illegal copies is essentially theft. Copyright acts
make it illegal to copy and distribute intellectual property without the permission of the copyright
owner, whether via a computer or otherwise.
Many websites offer free downloads of copyrighted music, books, films, television programs,
images and software. This distribution is illegal unless:
the website holds the copyright of whatever is being distributed
the website has the copyright owner’s permission
no copyright exists.
Websites that have copyright permission are given a licence. The licence grants permission for
the copying and distribution of copyrighted material.
2.6 Software licensing
Several types of licence can apply to software:
Commercial – copyrighted software that must be paid for. The copying, distribution and
selling of such software is restricted to those individuals or organisations that hold a licence to
that software.
Freeware – software that is copyrighted but made available free of charge. Keeping hold of
the copyright allows the author to retain control and ownership of the software in case they wish
to charge for it or develop it in the future. The licence does not allow the software to be
modified.
MUHAMMAD ALI KHAN
PAGE 153

Shareware – copyrighted software that is initially given away on a free basis. The software
usually remains free to use for a limited period of time, after which a licence must be obtained.
Software is often made available as shareware to allow users to try it out and to encourage its
distribution. Shareware licences do not allow software to be modified.
Open source software – software that allows anyone to copy, distribute, amend or develop for
their own purposes. Open source software is often developed collaboratively by anyone who
has an interest.

Several bodies exist that promote open source software and freeware:
The Free Software Foundation (FSF) promotes and encourages the right to freely copy,
distribute and modify software. FSF aims to allow users to collaboratively develop software that
is free for anyone to use and adapt. Such software holds the GNU Public Licence that states
that no-one can copyright the software. The FSF also developed GNU, a collection of free
software that users can employ to build an operating system similar to Unix.
The Open Source Initiative promotes open source software. It encourages open source
software to meet certain licence requirements, such as:
free redistribution
the original source code must be supplied alongside any developed work
the original licence must apply to any derived work
the software must be available for anyone to use – no-one must be barred from using it.

A user should always be careful to note the licence that software holds. Failure to so do may lead to
illegal activity and prosecution.

The Association for Computing Machinery (ACM) is the world’s largest educational
and scientific computing society. It has its own Code of Ethics and another set of
ethical principles that were also approved by the IEEE as the standard for teaching
and practicing software engineering.

* Contribute to society and human well-being. Programmers should work to develop


computer systems that can reduce negative consequences to society, such as threats
to safety and health, and that can make everyday activities and work easier. It is “an
obligation to develop to high standards”

* Avoid harm to others. Computer systems have an indirect impact on third parties.
They can cause loss of information and resources that might result severely harmful
for users, the general public, or employers. Therefore, software developers should
minimize the risk of harming others due to coding errors, or security issues, by
following standards to design and test systems
MUHAMMAD ALI KHAN
PAGE 154

* Be honest and trustworthy. This principle encourages programmers to be honest


and aware of their limitations in knowledge and education when writing computer
systems. Also, if a programmer knows there is something wrong with a computer
system, he or she should report it immediately to avoid undesirable consequences.

* Give proper credit for intellectual property. It is mandatory for every software
developer to never use and take credit for someone else’s work, even when it has
not been protected by a copyright law, patent, etc. They must recognize and fully
credit other people’s works, and they should use their own ideas to develop software.

* Respect the privacy of others. Computer systems are wrongly used by some people
to violate the privacy of others. Software developers should write programs that can
protect users’ private information and that can avoid other undesired people to have
unauthorized access to.

* Honor confidentiality. Unless required by law or any other ethical guideline, a


programmer must keep secret any additional information related to his or her
employer that arises from working in a project.

* Approve software only if they have a well-founded belief it is safe and meets
specifications. Programmers cannot assume that a system is ready to use only
because it performs the tasks needed. They should make sure these systems are also
safe and meet every specification required by the user. If programs are not safe,
users are unprotected from hackers that could steal important information or money.
Therefore, several tests should be performed in order to ensure a system’s security
before approving it.

* Accept full responsibility for their own work. If a program presents errors, the
software developer should accept full responsibility for his or her work, and
should work on revising, correcting, modifying, and testing it.

* Not knowingly use software that is obtained or retained either illegally or


unethically. If a computer system will be used as a base for the creation of another,
then permission to do so should be asked by the programmer. This principle prohibits
using any other software for any purpose if the way it was gotten is not clear or is
known to be illegal or unethical.

* Identify, define, and address ethical, economic, cultural, legal and environmental
issues related to work projects. If a programmer notices and identifies that working
on a project will lead to any kind of problems, then the programmer should report it
to his or her employer before continuing.
MUHAMMAD ALI KHAN
PAGE 155

* Ensure that specifications for software on which they work satisfy the users’
requirements and they have the appropriate approvals. Software developers should
come to their employers to ask for the correspondent approval to the system they
are creating before continuing working on the next part. If it doesn’t meet the
requirements, then a modification to the source code of the system should be made.

* Ensure adequate testing, debugging and review of software . Programmers should


perform the appropriate tests to the pieces of software they work with, and should
check for errors and system security holes to make sure that the programs are well
implemented.

* Not engage in deceptive financial practices such as bribery, double billing, or


other improper financial practices. Programmers are exposed to be participants on
illegal activities to get money. They get involved in them due to threats, economical
issues, or simply because they want to obtain easy money taking advantage of their
knowledge about how computer systems work. This guideline prohibits programmer
to form part of such unlawful actions.

* Improve their ability to create safe, reliable, and useful quality software. Since
technology advances faster year by year, and so does virtual criminality, the need of
well-structured and designed programs is increasing. Computer systems get old and
limited by new ones and new devices. Programmers should “further their knowledge
of developments in the analysis, specification, design, development, maintenance,
and testing software and related documents
MUHAMMAD ALI KHAN
PAGE 156

1.7.2 Ownership

Concept of ownership and copyright of software

What happens when you purchase a specific software application? And if you’ve
purchased software, what is the license agreement for? Do you now own the software
because you paid for it?

Simply put, no. Though you may have paid for the software, what you have actually
done is licensed the application, essentially paying for the rights to use the software
according to guidelines determined by the owner. The owner of the software remains
the person or entity that holds the copyright, giving them the sole legal authority
power to sell, distribute, copy and/or change the content of the software. And unless
the person or organization transfers ownership rights, the rights remain with the
owner no matter how many times the owner legally distributes the software.

When a user either purchases software or freely downloads software from the
Internet, the user is not buying the ownership rights to the software but a license to
use the software according to the licensing agreement, or EULA (for end user
licensing agreement). The EULA is a legal agreement between the two parties and is
legally actionable if either party violates the terms of the agreement. While no two
EULAs are exactly the same.

It’s a good idea to actually read all the way through the licensing agreements of
software you buy or download. One way that spyware has been able to proliferate
over the Internet is by individuals not paying attention to the licensing agreements
that state that along with the intended software the program will also be installing
spyware on your system.

Legislation to protect ownership, usage and copyright

Computer software is protected by copyright law and international copyright treaties


as well as other intellectual property laws and treaties. Copyright law and other
intellectual property laws in many countries or regions protect the rights of a software
owner by granting to the owner a number of exclusive rights, including the right to
reproduce or "copy" the software. Copying software without the permission of the
owner is "copyright infringement" and the law imposes penalties on infringers.

You make a "copy" of a software program whenever you:

1) Load the software into your computer's temporary memory by running the
program from a floppy disk, hard disk, CD-ROM, or other storage media;
MUHAMMAD ALI KHAN
PAGE 157

2) Copy the software onto other media such as a floppy disk or your computer's
hard disk;
3) Run the program on your computer from a network server on which the
software is resident or stored.

4.1 Quiz
1. Computer ethics are:
a. a set of moral principles that govern the design, building, implementation and use of
computers*
b. a set of legal rules defining how a computer must be used
c. laws defining ownership of intellectual property

2. A code of conduct for computers is:


a. a law restricting the circumstances in which a computer may be used
b. a set of rules defining what can and cannot be done with computers*
c. a set of rules defining how software may be distributed

3. The ACM/IEEE Software Engineering Code of Ethics aims to:


a. provide professional standards for software developers*
b. Encourage the free use of software
c. Restrict the use of shareware

4. Copyright aims to:


a. encourage the distribution of commercial software
b. encourage the distribution of open source software
c. protect intellectual property*

5. Shareware entitles a user to:


a. use source software for free
b. freely modify the software
c. use software for free for a limited period*
MUHAMMAD ALI KHAN
PAGE 158

Almost all commercial computer software is licensed directly or indirectly from the
copyright owner (the software publisher) for use by the customer through a type of
contract called an "End User License Agreement" (also known as a EULA). Different
products may have different types of EULAs.

Data Protection Act 1998

The Data Protection Act 1998 controls the way that companies, organizations and
individuals handle personal data.

It states that:

1. Data may only be used for the specific purposes for which it was collected.
2. Data must not be disclosed to other parties without the consent of the
individual whom it is about, unless there is legislation or other overriding
legitimate reason to share the information (for example, the prevention or
detection of crime). It is an offence for Other Parties to obtain this personal
data without authorization.
3. Individuals have a right of access to the information held about them, subject
to certain exceptions (for example, information held for the prevention or
detection of crime).
4. Personal information may be kept for no longer than is necessary and must
be kept up to date.
5. Personal information may not be sent outside the European Economic Area
unless the individual whom it is about has consented or adequate protection is
in place, for example by the use of a prescribed form of contract to govern the
transmission of the data.
6. Subject to some exceptions for organizations that only do very simple
processing, and for domestic use, all entities that process personal information
must register with the Information Commissioner's Office.
7. The departments of a company that are holding personal information are
required to have adequate security measures in place. Those include technical
measures (such as firewalls) and organizational measures (such as staff
training)
8. Subjects have the right to have factually incorrect information corrected
MUHAMMAD ALI KHAN
PAGE 159

Regulation of Investigatory Powers Act 2000

The Regulation of Investigatory Powers Act was passed in 2000, and introduces
the power to intercept communications with the aim of taking into account the
growth of the Internet. It regulates the manner in which certain public bodies may
conduct surveillance and access a person's electronic communications
! enables certain public bodies to demand that an ISP provide access
" to a customer's communications in secret;"
! enables mass surveillance of communications in transit;"
! enables certain public bodies to demand ISPs fit equipment to
" facilitate surveillance;"
! enables certain public bodies to demand that someone hand over keys
to protected information;"
! allows certain public bodies to monitor people's internet activities;"
! Prevents the existence of interception warrants and any data collected
with them from being revealed in court."

Free software foundation (FSF)

Free software developers guarantee everyone equal rights to their programs; any
user can study the source code, modify it, and share the program. By contrast,
most software carries fine print that denies users these basic rights, leaving them
susceptible to the whims of its owners and vulnerable to surveillance.
! The FSF provides critical infrastructure and funding for theGNU project, the
foundation of the popular GNU/Linux family of free operating systems and
" the keystone of the Internet."
! Campaigns Team creates educational materials about free software,
convenes the yearly LibrePlanet conference and goes toe to toe against
" powerful interests that threaten computer user rights."
! Licensing & Compliance Lab defends freely licensed software from
proprietary hoarding, advises on licensing issues, and certifies devices that
Respect Your Freedom"

Open Source Initiative (OSI)

The Open Source Initiative (OSI) is an organization dedicated to promoting


open-source software.
MUHAMMAD ALI KHAN
PAGE 160

Shareware

Most shareware is delivered free of charge for trial basis e.g. 30 days, but the
author usually requests that you pay a small fee if you like the program and use
it regularly. By sending the small fee, you become registered with the producer
so that you can receive service assistance and updates. You can copy shareware
and pass it along to friends and colleagues, but they too are expected to pay a
fee if they use the product.

Shareware is inexpensive because it is usually produced by a single programmer


and is offered directly to customers. Thus, there is practically no packaging or
advertising expenses.

Commercial software

Commercial software, or sometimes payware is a software that is designed for


sale to serve a commercial need. Commercial software is usually proprietary
software, but in some instances it may be public-domain software.
PAGE 161

MUHAMMAD ALI KHAN


PAGE 162

MUHAMMAD ALI KHAN


PAGE 163

MUHAMMAD ALI KHAN


PAGE 164

MUHAMMAD ALI KHAN


MUHAMMAD ALI KHAN
PAGE 165

8.1 Database Concepts


Candidates should be able to: Notes and guidance
Show understanding of the limitations of using a file-
based approach for the storage and retrieval of data
Describe the features of a relational database that
address the limitations of a file-based approach
Show understanding of and use the terminology Including entity, table, record, field, tuple, attribute,
associated with a relational database model primary key, candidate key, secondary key, foreign
key, relationship (one-to-many, one-to-one, many-to-
many), referential integrity, indexing
Use an entity-relationship (E-R) diagram to document
a database design
Show understanding of the normalisation process First Normal Form(1NF), Second Normal Form (2NF)
and Third Normal Form (3NF)
Explain why a given set of database tables are, or are
not, in 3NF
Produce a normalised database design for a description
of a database, a given set of data, or a given set of tables
MUHAMMAD ALI KHAN
PAGE 166

Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content

8.2 Database Management System (DBMS)


Candidates should be able to: Notes and guidance
Show understanding of the features provided by a Including:
Database Management System (DBMS) that address
! data management, including maintaining a data
the issues of a file based approach
dictionary
! data modelling
! logical schema
! data integrity
! data security, including backup procedures and
the use of access rights to individuals / groups of
users
Show understanding of how software tools found Including the use and purpose of:
within a DBMS are used in practice
! developer interface
! query processor

8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
Candidates should be able to: Notes and guidance
Show understanding that DBMS carries out all
creation / modification of the database structure using
its Data Definition Language (DDL)
Show understanding that the DBMS carries out all
queries and maintenance of data using its DML
Show understanding that the industry standard for Understand a given SQL script
both DDL and DML is Structured Query Language
(SQL)
Understand given SQL (DDL) commands and be able Create a database (CREATE DATABASE)
to write simple SQL (DDL) commands using a sub-set Create a table definition (CREATE TABLE), including
of commands the creation of attributes with appropriate data types:
! CHARACTER
! VARCHAR(n)
! BOOLEAN
! INTEGER
! REAL
! DATE
! TIME
change a table definition (ALTER TABLE)
add a primary key to a table (PRIMARY KEY (field))
add a foreign key to a table (FOREIGN KEY (field)
REFERENCES Table (Field))
Write an SQL script to query or modify data (DML) Queries including SELECT... FROM, WHERE, ORDER
which are stored in (at most two) database tables BY, GROUP BY, INNER JOIN, SUM, COUNT, AVG

Data maintenance including. INSERT INTO, DELETE


FROM, UPDATE
MUHAMMAD ALI KHAN
PAGE 167

1.8.1 Database management systems (DBMS)

File based approach for storage and retrieval of large volume of

data Flat files

1. flat files contains one table at a time generally

2. flat files contains values at each row and separated with a special symbol so to
reach the data you have to parse each row and obtaining an array of values and
then you can query the data.

3. to control the data in a file , you have to read it line by line and parse it and
because of it they are slow

4. there is no control mechanism in files


MUHAMMAD ALI KHAN
PAGE 168

Disadvantages of using flat file(file-based) approach to store data


MUHAMMAD ALI KHAN
PAGE 169

Relational database

The line between the fields has a ‘1’ on one side and the infinity sign n the other.
This is called a one-to-many relationship.

After creating the relationship, if you open the table city, it will look like similar to
following screen shot. If you click the ‘+’ symbol, it will show the customers in that
particular city.
MUHAMMAD ALI KHAN
PAGE 170

Features of a relational database


MUHAMMAD ALI KHAN
PAGE 171

Data dictionary

In database management systems, a file that defines the basic organization of a


database. A data dictionary contains a list of all files in the database, the number of
records in each file, and the names and types of each field. Most database
management systems keep the data dictionary hidden from users to prevent them
from accidentally destroying its contents.

Data dictionaries do not contain any actual data from the database, only book keeping
information for managing it. Without a data dictionary, however, a database
management system cannot access data from the database.

Data modeling
MUHAMMAD ALI KHAN
PAGE 172

1.8.2 Relational database

Each database is a collection of related tables; these are also called relations, hence
the name "relational database". Each table is a physical representation of an entity
or object that is in a tabular format consisting of columns and rows. Columns are the
fields of a record or the attributes of an entity. The rows contain the values or data
instances; these are also called records or tuples.

Primary key

Primary key uniquely specifies a tuple within a table. In order for an attribute to be
a good primary key it must not repeat.

Foreign key

A foreign key is a field in a relational table that matches the primary key column of
another table. The foreign key can be used to cross-reference tables. Foreign keys
need not have unique values in the referencing relation.

Candidate key

A candidate key is a column, or set of columns, in a table that can uniquely identify
any database record without referring to any other data. Each table may have one or
more candidate keys, but one candidate key is special, and it is called the primary
key. This is usually the best among the candidate keys. When a key is composed of
more than one column, it is known as a composite key.

Secondary key

A secondary key is made on a field that you would like to be indexed for faster
searches. A table can have more than one secondary key. When database become
large, possibly with hundreds of thousands of records, they can take a while to
search. A database can be set up so that it can be searched more efficiently.
MUHAMMAD ALI KHAN
PAGE 173

Referential integrity

Referential integrity is a property of data which, when satisfied, requires every value
of one attribute (column) of a relation (table) to exist as a value of another attribute
in a different (or the same) relation (table).For referential integrity to hold in a
relational database, any field in a table that is declared a foreign key can contain
either a null value, or only values from a parent table's primary key or a candidate
key. In other words, when a foreign key value is used it must reference a valid,
existing primary key in the parent table
MUHAMMAD ALI KHAN
PAGE 174

Normalization

Database normalization is the process of organizing the fields and tables of


a relational database to minimize redundancy. Normalization usually involves dividing
large tables into smaller (and less redundant) tables and defining relationships
between them. The objective is to isolate data so that additions, deletions, and
modifications of a field can be made in just one table and then propagated through
the rest of the database using the defined relationships.

Edgar F. Codd, the inventor of the relational model, introduced the concept of
normalization and what we now know as the First Normal Form (1NF) in 1970. Codd
went on to define the Second Normal Form (2NF) and Third Normal Form (3NF) in
1971, and Codd and Raymond F. Boyce defined the Boyce-Codd Normal Form (BCNF)
in 1974. Informally, a relational database table is often described as "normalized" if
it is in the Third Normal Form.

1st Normal Form

A database is in first normal form if it satisfies the following conditions:

# !" Contains only atomic values#


$" There are no repeating groups#

An atomic value is a value that cannot be divided. For example, in the table shown
below, the values in the [Color] column in the first row can be divided into "red" and
"green", hence [TABLE PRODUCT] is not in 1NF.

A repeating group means that a table contains two or more columns that are closely
related. For example, a table that records data on a book and its author(s) with the
following columns: [Book ID], [Author 1], [Author 2], [Author 3] is not in 1NF
because [Author 1], [Author 2], and [Author 3] are all repeating the same attribute.

1st Normal Form Example

How do we bring an un-normalized table into first normal form? Consider the
following example:
MUHAMMAD ALI KHAN
PAGE 175

To bring this table to first normal form, we split the table into two tables and
now we have the resulting tables:

Now first normal form is satisfied, as the columns on each table all hold just one
value.

nd
2 Normal Form
A database is in second normal form if it satisfies the following conditions:

# !" It is in first normal form#


$" All non-key attributes are fully functional dependent on the primary key#

In a table, if attribute B is functionally dependent on A, but is not functionally


dependent on a proper subset of A, then B is considered fully functional dependent
on A. Hence, in a 2NF table, all non-key attributes cannot be dependent on a subset
of the primary key. Note that if the primary key is not a composite key, all non-key
attributes are always fully functional dependent on the primary key. A table that is
in 1st normal form and contains only a single key as the primary key is automatically
in 2nd normal form.

2nd Normal Form Example

Consider the following example:


MUHAMMAD ALI KHAN
PAGE 176

This table has a composite primary key [Customer ID, Store ID]. The non-key
attribute is [Purchase Location]. In this case, [Purchase Location] only depends on
[Store ID], which is only part of the primary key. Therefore, this table does not satisfy
second normal form.

To bring this table to second normal form, we break the table into two tables, and
now we have the following:

What we have done is to remove the partial functional dependency that we initially
had. Now, in the table [TABLE_STORE], the column [Purchase Location] is fully
dependent on the primary key of that table, which is [Store ID].

3rd Normal Form

A database is in third normal form if it satisfies the following conditions:

# !" It is in second normal form#


$" There is no transitive functional dependency#

By transitive functional dependency, we mean we have the following relationships in


the table: A is functionally dependent on B, and B is functionally dependent on C. In
this case, C is transitively dependent on A via B.

3rd Normal Form Example

Consider the following example:

In the table able, [Book ID] determines [Genre ID], and [Genre ID] determines
[Genre Type]. Therefore, [Book ID] determines [Genre Type] via [Genre ID] and
MUHAMMAD ALI KHAN
PAGE 177

we have transitive functional dependency, and this structure does not satisfy third
normal form.

To bring this table to third normal form, we split the table into two as follows:
MUHAMMAD ALI KHAN
PAGE 178

1.8.1 Database management systems (DBMS)

File based approach for storage and retrieval of large volume of data Flat files

!" flat files contains one table at a time generally

#" flat files contains values at each row and separated with a special symbol so to
reach the data you have to parse each row and obtaining an array of values and
then you can query the data.

$" to control the data in a file , you have to read it line by line and parse it and
because of it they are slow

%" there is no control mechanism in files


MUHAMMAD ALI KHAN
PAGE 179

Disadvantages of using flat file(file-based) approach to store data


MUHAMMAD ALI KHAN
PAGE 180

Relational database

The line between the fields has a ‘1’ on one side and the infinity sign n the other.
This is called a one-to-many relationship.

After creating the relationship, if you open the table city, it will look like similar to
following screen shot. If you click the ‘+’ symbol, it will show the customers in that
particular city.
MUHAMMAD ALI KHAN
PAGE 181

Features of a relational database


MUHAMMAD ALI KHAN
PAGE 182

Data dictionary

In database management systems, a file that defines the basic organization of a


database. A data dictionary contains a list of all files in the database, the number of
records in each file, and the names and types of each field. Most database
management systems keep the data dictionary hidden from users to prevent them
from accidentally destroying its contents.

Data dictionaries do not contain any actual data from the database, only book
keeping information for managing it. Without a data dictionary, however, a
database management system cannot access data from the database.

Data modeling

Referential integrity

Referential integrity is a property of data which, when satisfied, requires every


value of one attribute (column) of a relation (table) to exist as a value of another
attribute in a different (or the same) relation (table).For referential integrity to hold
in a relational database, any field in a table that is declared a foreign key can
contain either a null value, or only values from a parent table's primary key or a
candidate key. In other words, when a foreign key value is used it must reference a
valid, existing primary key in the parent table.
MUHAMMAD ALI KHAN
PAGE 183

1.8.2 Relational database

Each database is a collection of related tables; these are also called relations, hence
the name "relational database". Each table is a physical representation of an entity
or object that is in a tabular format consisting of columns and rows. Columns are
the fields of a record or the attributes of an entity. The rows contain the values or
data instances; these are also called records or tuples.

Primary key

Primary key uniquely specifies a tuple within a table. In order for an attribute to be
a good primary key it must not repeat.

Foreign key

A foreign key is a field in a relational table that matches the primary key column of
another table. The foreign key can be used to cross-reference tables. Foreign keys
need not have unique values in the referencing relation.

Candidate key

A candidate key is a column, or set of columns, in a table that can uniquely identify
any database record without referring to any other data. Each table may have one
or more candidate keys, but one candidate key is special, and it is called the
primary key. This is usually the best among the candidate keys. When a key is
composed of more than one column, it is known as a composite key.

Secondary key

A secondary key is made on a field that you would like to be indexed for faster
searches. A table can have more than one secondary key. When database become
large, possibly with hundreds of thousands of records, they can take a while to
search. A database can be set up so that it can be searched more efficiently.
MUHAMMAD ALI KHAN
PAGE 184

Normalization

Database normalization is the process of organizing the fields and tables of


a relational database to minimize redundancy. Normalization usually involves
dividing large tables into smaller (and less redundant) tables and defining
relationships between them. The objective is to isolate data so that additions,
deletions, and modifications of a field can be made in just one table and then
propagated through the rest of the database using the defined relationships.

Edgar F. Codd, the inventor of the relational model, introduced the concept of
normalization and what we now know as the First Normal Form (1NF) in 1970.
Codd went on to define the Second Normal Form (2NF) and Third Normal Form
(3NF) in 1971, and Codd and Raymond F. Boyce defined the Boyce-Codd Normal
Form (BCNF) in 1974. Informally, a relational database table is often described as
"normalized" if it is in the Third Normal Form.

1st Normal Form

A database is in first normal form if it satisfies the following conditions:

# !" Contains only atomic values#


$" There are no repeating groups#

An atomic value is a value that cannot be divided. For example, in the table shown
below, the values in the [Color] column in the first row can be divided into "red"
and "green", hence [TABLE PRODUCT] is not in 1NF.

A repeating group means that a table contains two or more columns that are
closely related. For example, a table that records data on a book and its author(s)
with the following columns: [Book ID], [Author 1], [Author 2], [Author 3] is not in
1NF because [Author 1], [Author 2], and [Author 3] are all repeating the same
attribute.

1st Normal Form Example

How do we bring an un-normalized table into first normal form? Consider the
following example:
MUHAMMAD ALI KHAN
PAGE 185

To bring this table to first normal form, we split the table into two tables and
now we have the resulting tables:

Now first normal form is satisfied, as the columns on each table all hold just one
value.

nd
2 Normal Form
A database is in second normal form if it satisfies the following conditions:

# !" It is in first normal form#


$" All non-key attributes are fully functional dependent on the primary key#

In a table, if attribute B is functionally dependent on A, but is not functionally


dependent on a proper subset of A, then B is considered fully functional dependent
on A. Hence, in a 2NF table, all non-key attributes cannot be dependent on a subset
of the primary key. Note that if the primary key is not a composite key, all non-key
attributes are always fully functional dependent on the primary key. A table that is
in 1st normal form and contains only a single key as the primary key is
automatically in 2nd normal form.

2nd Normal Form Example

Consider the following example:


MUHAMMAD ALI KHAN
PAGE 186

This table has a composite primary key [Customer ID, Store ID]. The non-key
attribute is [Purchase Location]. In this case, [Purchase Location] only depends on
[Store ID], which is only part of the primary key. Therefore, this table does not
satisfy second normal form.

To bring this table to second normal form, we break the table into two tables, and
now we have the following:

What we have done is to remove the partial functional dependency that we initially
had. Now, in the table [TABLE_STORE], the column [Purchase Location] is fully
dependent on the primary key of that table, which is [Store ID].

3rd Normal Form

A database is in third normal form if it satisfies the following conditions:

# !" It is in second normal form#


$" There is no transitive functional dependency#

By transitive functional dependency, we mean we have the following relationships


in the table: A is functionally dependent on B, and B is functionally dependent on C.
In this case, C is transitively dependent on A via B.

3rd Normal Form Example

Consider the following example:


MUHAMMAD ALI KHAN
PAGE 187

we have transitive functional dependency, and this structure does not satisfy third
normal form.

To bring this table to third normal form, we split the table into two as follows:
MUHAMMAD ALI KHAN
PAGE 188

Data Definition Language (DDL)

DDL, which is usually part of a DBMS, is used to define and manage all attributes and properties of a database,
including row layouts, column definitions, key columns, file locations, and storage strategy. DDL statements
are used to build and modify the structure of tables and other objects such as views, triggers, stored procedures,
and so on. For each object, there are usually CREATE, ALTER, and DROP statements (such as, CREATE
TABLE, ALTER TABLE, and DROP TABLE). Most DDL statements take the following form:

CREATE object _ name

ALTER object _ name

DROP object _ name


In DDL statements, object_namecan be a table, view, trigger, stored procedure, and so on.

CREATE DATABASE

Many database servers allow for the presence of many databases. In order to create a database, a
relatively standard command ‘CREATE DATABASE’ is used.

The general format of the command is:


CREATE DATABASE <database-name> ;

anything; usually it shouldn’t have spaces (or those spaces) have to be properly
escaped). Some databases allow hyphens, and/or underscores in the name. The name is usually limited in size
(some databases limit the name to 8 characters, others to 32—in other words, it depends on what database you
use).

DROP DATABASE

Just like there is a ‘create database’ there is also a ‘drop database’, which simply removes the database.
Note that it doesn’t ask you for confirmation, and once you remove a database, it is gone forever.

DROP DATABASE <database-name> ;


MUHAMMAD ALI KHAN
PAGE 189
CREATE TABLE

Probably the most common DDL statement is ‘CREATE TABLE’. Intuitively enough, it is used to
create tables. The general format is something along the lines of:

CREATE TABLE <table-name> (

...

);

The ... is where column definitions go. The general format for a column definition is the

column name followed by column type. For example:

PERSONID INT

Which defines a column name PERSONID, of type INT. Column names have to be comma separated, i.e.:

CREATE TABLE PERSON (

PERSONID INT,

LNAME VARCHAR(20),

FNAME VARCHAR(20) NOT NULL,

DOB DATE,

PRIMARY KEY(PERSONID)

);

The above creates a table named person, with person id, last name, first name, and date of birth. There is also
‘primary key’ definition. A primary key is a column value that uniquely identifies a database record. So
example, we can have two ‘person’ records with the same last name and first name, but with different ids.

Besides for primary key, there are many other flags we can specify for table columns. For example, in the
above example, FNAME is marked as NOT NULL, which means it is not allowed to have NULL values.

Many databases implement various extensions to the basics, and you should read the documentation to
determine what features are present/absent, and how to use them.
MUHAMMAD ALI KHAN
PAGE 190

There is a command to ‘alter’ tables after you create them. This is usually only useful if the table already has
data, and you don’t want to drop it and recreate it (which is generally much simpler). Also, most databases
t ‘alter table’ is allowed to do. For example, Oracle allows you do add a
column, but not remove a column.

The general syntax to add a field is:

ALTER TABLE <table-name>

ADD <field-name><data-type>

is in the ‘create table’ statement.

The general syntax to drop a field is:

ALTER TABLE <table-name>

DROP <field-name>

Note that very few databases let you drop a field. The drop command is mostly present to allow for dropping
of constraints (such as indexes, etc.) on the table.

The general syntax to modify a field (change its type, etc.) is:

ALTER TABLE <table-name>

MODIFY <field-name><new-field-declaration>

Note that you can only do this to a certain extent on most databases. Just as with ‘drop’, this is mostly
useful for working with table constraints (changing ‘not null’ to ‘null’, etc.)
MUHAMMAD ALI KHAN
PAGE 191
1.8 Database and data

DataManipulation Language (DML)

DML is used to select, insert, update, or delete data in the objects defined with DDL. All database users can
1.8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
use these commands during the routine operations on a database. The different DML statements are as
follows:

SELECT statement

INSERT statement

UPDATE statement

DELETE statement

INSERT Statement

To get data into a database, we need to use the ‘insert’ statement. The general syntax is:
INSERT INTO <table-name> (<column1>,<column2>,<column3>,...)
VALUES (<column-value1>,<column-value2>,<column-value3>);

The column names (i.e.: column1, etc.) must correspond to column values (i.e.: column-value1,etc.). There is
a short-hand for the statement:

INSERT INTO <table-name>

VALUES (<column-value1>,<column-value2>,<column-value3>);

In which th
‘createtable’ declaration. It must be noted, that this sort of statement should (or rather, must)be
avoided! If someone changes the table, moves columns around in the table declaration, the code using
the shorthand insert statement will fail.
A typical example, of inserting the ‘person’ record we’ve created earlier would be:

INSERT INTO PERSON(PERSONID,LNAME,FNAME,DOB)


VALUES(1,’DOE’,’JOHN’,’1956-11-23’);
MUHAMMAD ALI KHAN
PAGE 192
1.8 Database and data
SELECTStatement

Probably the most used statement in all of SQL is the SELECT statement. The select statement as the general
format of:
1.8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
SELECT <column-list>
FROM <table-list>
WHERE <search-condition>

The column-list indicates what columns you’re interested in (the ones which you want
to appear in the result), the table-list is the list of tables to be used in the query, and
search-condition specifies what criteria you’re looking for.

An example of a short-hand version to retrieve all ‘person’ records we’ve been using:
SELECT * FROM PERSON;

The WHERE Clause

The WHERE clause is used in UPDATE, DELETE, and SELECT statements, and has the same
format in all these cases. It has to be evaluated to either true or false. Table 1 lists some of the common
operators.

= equals to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
<> not equal to
Table 1: SQL Operators

There is also IS, which can be used to check for NULL values, for example:

column-name IS NULL

We can also use AND, OR and parenthesis to group expressions.


Besides for these operators, we can also call built-in functions (as well as stored procedures we define
ourselves—that is, if the database supports stored procedures).
An example of the operators in use would be: something < 5 OR something is NULL
AND somedate = TO DATE(’01/03/93’,’MM/DD/YY’).
MUHAMMAD ALI KHAN
PAGE 193
1.8 Database and data
UPDATEStatement

The update statement is used for changing records. The general syntax is:

1.8.3 Data Definition Language (DDL) and Data Manipulation Language (DML) UPDATE <table-name>
SET <column1> = <value1>, <column2> = <value2>,...
WHERE <criteria>

The criteria is what selects the records for update. The ‘set’ portion indicates which columns
should be updated and to what values. An example of the use would be:

UPDATE PERSON
SET FNAME=’Clark’, LNAME=’Kent’
WHERE FNAME=’Superman’;

DELETE Statement

The ‘delete’ is used to remove elements from the database. The syntax is very
update and select statements:

DELETE FROM <table-name>


WHERE <criteria>

Basically we select which records we want to delete using the where clause. An example use would be:

DELETE FROM PERSON


WHERE PERSONID=12345;

AND Clause

SELECT column1, column2, ...


FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
MUHAMMAD ALI KHAN
PAGE 194

!"#$%&'()#
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

*!+#$%&'()#
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;

,**-"#.!,*#$%&'()#
SELECT column_name(s)
FROM table1
INNER JOIN table2 ON table1.column_name = table2.column_name;

SELECT Orders.OrderID, Customers.CustomerName


FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

/"!01#23#$%&'()#
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country;
MUHAMMAD ALI KHAN
PAGE 195

!"#$%&'()&*$+,*$-.$/&,)0,$0)1#,#
The following SQL creates a PRIMARY KEY on the "ID" column when the
"Persons" table is created:

!"#$%&

CREATE TABLE Persons (


ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);

!"#$23&,'45$+,*$-.$/&,)0,$0)1#,#
The following SQL creates a FOREIGN KEY on the "PersonID" column when the
"Orders" table is created:

!"#$%&

CREATE TABLE Orders (


OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
9 Algorithm design and problem solving
In this chapter, you will learn about
• computational thinking skills (abstraction and decomposition)
• how to write algorithms that provide solutions to problems using structured English,
flowcharts and pseudocode
• the process of stepwise refinement.

In order to design a computer system that performs a specific task, or solves a given problem, the
task or problem has to be rigorously defined and set out, showing what is going to be computed
and how it is going to be computed.
This chapter introduces tools and techniques that can be used to design a software solution to
work with associated computer hardware to form a computer system.
Practice is essential to develop skills in computational thinking. Designs shown with pseudocode
or flowcharts can be traced to check if the proposed solution works, but the best way to actually
test that a computer system works is to code it and use it or, even better, get somebody else to
use it. Therefore, practical programming activities, alongside other activities, will be suggested at
every stage to help reinforce the skills being learnt and develop the skill of programming.
The programming languages to use are:
• Java
• Python
• VB.NET.
Computational thinking skills
Key terms
Abstraction – the process of extracting information that is essential, while ignoring what is not
relevant, for the provision of a solution.
Decomposition – the process of breaking a complex problem into smaller parts.
Pattern recognition – the identification of parts of a problem that are similar and could use the
same solution.

Computational thinking is used to study a problem and formulate an effective solution that can
be provided using a computer. There are several techniques used in computational thinking,
including abstraction, decomposition, algorithms and pattern recognition.
Using abstraction
Abstraction is an essential part of computational thinking. It enables computer scientists to
develop clear models for the solution to complex problems. Abstraction involves extracting
information that is essential while ignoring what is not relevant for the provision of a solution,
only including what is necessary to solve that problem.
Abstraction encourages the development of simplified models that are suited to a specific
purpose by eliminating any unnecessary characteristics from that model. Many everyday items
use abstraction, such as maps, calendars and timetables.
Maps use abstraction to show what is required for a specific purpose, for example, a road map
should only show the necessary detail required to drive from one place to another. The road map
in Figure 9.1 has reduced the complexity by only showing the essential details needed, such as
roads, road numbers and towns, and removing other information about the terrain that would not
be helpful (as shown in the satellite view).
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.

Figure 9.1 Road map and satellite view

The first stage of abstraction is to identify the purpose of the model of the situation that is to be
built. The situation could be one that occurs in real life, an imaginary one, or a future event such
as modeling the route of a deep space probe.
Once the purpose has been identified, sources of information need to be identified. These can
include observations, views of potential users, and evidence from other existing models.
The next stage is to use the information gathered from appropriate sources to identify what
details need to be included in the model, how these details should be presented and what details
are extraneous and need to be removed from the model.
For example, maps are used for many different purposes and can take different forms depending
on the identified use. The purpose of the road map model in Figure 9.1 is to allow a driver to
plan a journey, therefore, it includes towns and roads with their numbers. The roads depicted are
a scaled down version of the actual road to help the driver visualise the route.
A rail map model has another purpose and, therefore, looks very different, only showing rail
lines, stations and perhaps details about accessibility for wheelchair users at different stations. A
train passenger has no need to visualise the route, so the rail lines are simplified for clarity.
Using decomposition
Decomposition is also an essential part of computational thinking. It enables computer scientists
to break a complex problem into smaller parts that can be further subdivided into even smaller
parts until each part is easy to examine and understand, and a solution can be developed for it.
When a rigorous decomposition is undertaken, many simple problems are found to be more
complex than at first sight.
Pattern recognition is used to identify those parts that are similar and could use the same
solution. This leads to the development of reusable program code in the form of subroutines,
procedures and functions. When writing a computer program, each final part is defined as a
separate program module that can be written and tested as a separate procedure or function, as
shown in Figure 9.2. Program modules already written and tested can also be identified and
reused, thus saving development time. See Chapter 12 for further details.

Figure 9.2 Decomposition of a program into modules


Algorithms
Key terms
Structured English – a method of showing the logical steps in an algorithm, using an agreed
subset of straightforward English words for commands and mathematical operations.
Flowchart – a diagrammatic representation of an algorithm.
Algorithm – an ordered set of steps to be followed in the completion of a task.
Pseudocode – a method of showing the detailed logical steps in an algorithm, using keywords,
identifiers with meaningful names, and mathematical operators.
Stepwise refinement – the practice of subdividing each part of a larger problem into a series
of smaller parts, and so on, as required.
9.2.1 Writing algorithms that provide solutions to
problems
There are several methods of writing algorithms before attempting to program a solution. Here
are three frequently used methods.
• Structured English is a method of showing the logical steps in an algorithm, using an agreed
subset of straightforward English words for 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.
• 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.
Pseudocode does not need to follow the syntax of a specific programming language, but it
should provide sufficient detail to allow a program to be written in a high-level language.
Below, you will see the algorithm from the What you should already know section on page 217
written using each of these three methods.

Structured English

1 Ask for the number of values

2 Loop that number of times

3 Enter a value in loop

4 Add the value to the Total in loop

5 Calculate and output average

Pseudocode
ACTIVITY 9A
You have been asked to write an algorithm for drawing regular polygons of any size.
In pairs, divide the problem into smaller parts, identifying those parts that are similar.
Write down your solution as an algorithm in structured English.
Swap your algorithm with another pair.
Test their algorithm by following their instructions to draw a regular polygon. Discuss any
similarities and differences between your solutions.

Flowchart
Figure 9.3
9.2.2 Writing simple algorithms using pseudocode
Each line of pseudocode is usually a single step in an algorithm. The pseudocode used in this
book follows the rules in the Cambridge International AS & A Level Computer Science
Pseudocode Guide for Teachers and is set out using a fixed width font and indentation, where
required, of four spaces, except for THEN, ELSE and CASE clauses that are only indented by
two spaces.
All identifier names used in pseudocode should be meaningful; for example, the name of a
person could be stored in the variable identified by Name. They should also follow some basic
rules: they should only contain the characters A–Z, a–z and 0–9, and should start with a letter.
Pseudocode identifiers are usually considered to be case insensitive, unlike identifiers used in a
programming language.
It is good practice to keep track of any identifiers used in an identifier table, such as Table 9.1.

Identifier name Description


StudentName Store a student name
Counter Store a loop counter
StudentMark Store a student mark
Table 9.1

Pseudocode statements to use for writing algorithms.


To input a value:

To output a message or a value or a combination:

To assign a value to a variable (the value can be the result of a process or a calculation):
Operators used in pseudocode assignment statements:

ACTIVITY 9B
Identify the values stored in the variables when the assignment statements in the example
above have all been completed. The function ASC returns the ASCII value of a character.

To perform a selection using IF statements for a single choice or a choice and an alternative, and
CASE statements when there are multiple choices or multiple choices and an alternative:
Relational operators used in pseudocode selection statements:

= Equal to

<> Not equal to

> Greater than

> Less than

>= Greater than or equal to


<= Less than or equal to

Programming languages may not always have the same selection constructs as pseudocode, so it
is important to be able to write a program that performs the same task as a solution given in
pseudocode.
Here are three programs, one in each of the three prescribed programming languages, to
demonstrate the single choice IF statement. Note the construction of the IF statement, as it is
different from the pseudocode.
While the Cambridge International AS Level syllabus does not require you to be able to write
program code, the ability to do so will increase your understanding, and will be particularly
beneficial if you are studying the full Cambridge International A Level course.
Python
The identifier table for this algorithm is presented in Table 9.2.

Identifier name Description


Total Running total of integer values entered

Number Number of integer values to enter


Value Integer value input
Average Average of all the integer values entered
Writing pseudocode from a structured English
description
There are no set rules for writing structured English – the wording just needs to be unambiguous
and easily understandable. Pseudocode is more precise and usually follows an agreed set of rules.
From a structured English description, the following things need to be possible:
• Any variables that need to be used can be identified and put in an identifier table – these can be
items input or output as the results of calculations.
• Input and output can be identified from the wording used, for example, Enter, Read, Print,
Write.
• Selection can be identified from the wording used, for example, If, Then, Choose.
• Any iteration required can be identified from the wording used, for example, Loop, Repeat.
• Any processes needed can be identified from the wording used, for example, Set, Calculate.
When the identifier table is complete, each structured English statement can be used to write one
or more pseudocode statements, keeping the same order as the structured English.
Here is an example of an algorithm to calculate a runner’s marathon time in seconds, using
structured English.

1 Enter time taken to run marathon in hours, minutes and seconds


2 Calculate and store marathon time in seconds
3 Output marathon time in seconds

This can be used to identify the variables required and complete the identifier table (Table 9.3).

Identifier name Description


MarathonHours The hours part of the marathon time
MarathonMinutes The minutes part of the marathon time
MarathonSeconds The seconds part of the marathon time
TotalMarathonTimeSeconds Total marathon time in seconds
Table 9.3

Using these identifiers, each step of the structured English algorithm can be converted to
pseudocode, as demonstrated below.

1 Enter time taken to run marathon in hours, minutes and seconds

There are three variables used: MarathonHours, MarathonMinutes and MarathonSeconds. This is
explicitly input and implicitly output as the user needs to understand what input is required. The
pseudocode required is as follows.
2 Calculate and store marathon time in seconds

This is a process using the variables MarathonHours, MarathonMinutes and MarathonSeconds


and using an assignment statement to store the result in TotalMarathonTimeSeconds. The
pseudocode required is as follows.

3 Output marathon time in seconds

This is output using the variable TotalMarathonTimeSeconds. The pseudocode required is as


follows.

ACTIVITY 9G
The structured English description has been extended below to check the runner’s time against
their personal best.

1 Enter time taken to run marathon in hours, minutes and seconds


2 Calculate and store marathon time in seconds
3 Output marathon time in seconds
4 Enter personal best time in seconds
5 If marathon time in seconds is shorter than the personal best time then
6 Reset personal best time in seconds
7 Output the personal best time
9.2.4 Writing pseudocode from a flowchart
Flowcharts are diagrams showing the structure of an algorithm using an agreed set of symbols, as
shown in Table 9.4.

Pseudocode Flowchart symbol


INPUT or OUTPUT

IF or CASE
Part of FOR, REPEAT and WHILE

FOR, REPEAT and WHILE

Returning flow line

Assignment ← using a calculation or a pre-defined process, for


example, INT

Table 9.4

Flowcharts can be used to identify any variables required and you can then complete an identifier
table. Each flowchart symbol can be used to identify and write one or more pseudocode
statements.
Here is an example of a flowchart of an algorithm that can be used to check an exam grade:
Figure 9.4

The same algorithm is presented in pseudocode on the left. Below is the identifier table:

Identifier name Description


Mark Exam mark
Grade Exam grade
Table 9.5

and form a nested selection (IF) structure, as each following statement is part of
the ELSE clause. It is only at that the selection is complete. The flowchart shows this clearly
and the pseudocode uses indentation to show the nesting.
O OUTPUT 11 Enter your exam mark 11
0 INPUT Mark
0 IF Mark < 40
THEN
Grade +- 11Fail"

ELSE
e IF Mark < 60
THEN
Grade +- 11 Pass"

ELSE
IF Mark < 80
THEN
Grade +- 11 Merit 11

ELSE
0 Grade +- 11 Distinction 11

ENDIF
ENDIF
ENDIF
OUTPUT 11 Your grade is Grade
Q
11 ,
Stepwise refinement
The algorithms looked at so far have been short and simple. 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.
Many problems are more complex than they seem if a robust solution is to be developed. Look at
the first step of the structured English to calculate a time in seconds.

1 Enter time taken to run marathon in hours, minutes and seconds


2 Calculate and store marathon time in seconds
3 Output marathon time in seconds

The first step can be further broken down, as follows:

1.1 Enter the hours


1.2 Enter the minutes
1.3 Enter the seconds
Extend the identifier table and write the extra pseudocode to complete the algorithm. Then
check your algorithm works by writing a short program from your pseudocode statements
using the same names for your identifiers.

Each of these steps can be broken down further:

1.1.1 Input value for hours


1.1.2 Check input in the range 2 to 8
1.1.3 Reject if out of range or not a whole number and re-input value step 1.1.1
1.1.4 Accept and store value in hours
1.2.1 Input value for minutes
1.2.2 Check input in the range 0 to 59
1.2.3 Reject if out of range or not a whole number and re-input value step 1.2.1
1.2.4 Accept and store value in minutes
1.3.1 Input value for seconds
1.3.2 Check input in the range 0 to 59
1.3.3 Reject if out of range or not a whole number and re-input value step 1.3.1
1.3.4 Accept and store value in seconds

These steps can now be written in pseudocode. For example, the input routine for the seconds:
10 Data types and structures
In this chapter, you will learn about
• basic data types, and how to select and use them
• two different data structures: records and arrays
• how to handle text files consisting of many lines, using pseudocode
• three different abstract data types (ADTs): stacks, queues and linked lists.

WHAT YOU SHOULD ALREADY KNOW


Try this activity to see if you can use one-dimensional arrays before you read the first part of
this chapter.
Write an algorithm, using pseudocode, to find the largest and smallest of five numbers. The
numbers are to be input with appropriate prompts, stored in an array, and the largest and
smallest are to be output with appropriate messages. If you haven’t used an array before store
the values in five separate variables.

Key terms
Data type – a classification attributed to an item of data, which determines the types of value it
can take and how it can be used.
Identifier – a unique name applied to an item of data.
Record (data type) – a composite data type comprising several related items that may be of
different data types.
Composite data type – a data type constructed using several of the basic data types available
in a particular programming language.
Array – a data structure containing several elements of the same data type.
Index (array) – a numerical indicator of an item of data’s position in an array.
Lower bound – the index of the first element in an array, usually 0 or 1.
Upper bound – the index of the last element in an array.
Linear search – a method of searching in which each element of an array is checked in order.
Bubble sort – 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.
File – a collection of data stored by a computer program to be used again.
Abstract data type (ADT) – a collection of data and a set of operations on that data.
Stack – a list containing several items operating on the last in, first out (LIFO) principle.
Queue – a list containing several items operating on the first in, first out (FIFO) principle.
Linked list – a list containing several items in which each item in the list points to the next
item in the list.
10.1 Data types and records
Any computer system that is reusable needs to store data in a structured way so that it can be
reused in the future. One of the most powerful tools in computer science is the ability to search
large amounts of data and obtain results very quickly. This chapter introduces data structures that
enable effective and efficient computer-based storage and searching to take place.

10.1.1 Data types


Data types allow programming languages to provide different classifications for items of data,
so they can be used for different purposes. For example, integers are discrete whole numbers
used for counting and indexing, whereas real numbers can be used to provide accurate
measurements.
You need to be able to understand and make appropriate use of data types when writing
pseudocode or programs to provide a solution to a problem.
Programming languages have a number of built in data types. Table 10.1 lists the basic data
types that you need to know and how they are referred to in pseudocode and different
programming languages.
10.1.2 Records
Records are composite data types formed by the inclusion of several related items that may be
of different data types. This allows a programmer to refer to these items using the same
identifier, enabling a structured approach to using related items. A record will contain a fixed
number of items. For example, a record for a book could include title, author, publisher, number
of pages, and whether it is fiction or non-fiction.
A record data type is one example of a composite user-defined data type. A composite data type
references other existing data types when it is defined. A composite data type must be defined
before it can be used. Any data type not provided by a programming language must be defined
before it can be used.
In pseudocode, a record data type definition takes the following form:

For example, the book record data type could be defined like this:

The data type, TbookRecord, is now available for use and an identifier may now be declared in
the usual way:
Items from the record are now available for use and are identified by:

For example:

10.2 Arrays
An array is a data structure containing several elements of the same data type; these elements
can be accessed using the same identifier name. The position of each element in an array is
identified using the array’s index. The index of the first element in an array is the lower bound
and the index of the last element is the upper bound.
The lower bound of an array is usually set as zero or one. Some programming languages can
automatically set the lower bound of an array.
Arrays can be one-dimensional or multi-dimensional. In this chapter, we will look at one-
dimensional (1D) and two-dimensional (2D) arrays.
10.2.1 1D arrays
A 1D array can be referred to as a list. Here is an example of a list with nine elements and a
lower bound of zero.

Figure 10.1 Example of a 1D array

When a 1D array is declared in pseudocode, the lower bound (LB), upper bound (UB) and data
type are included:

For example:

The declared array can then be used, as follows:


10.2.2 2D arrays
A 2D array can be referred to as a table, with rows and columns. Here is an example of a table
with nine rows and three columns (27 elements) and lower bounds of zero.

Figure 10.2 Example of a 2D array

When a 2D array is declared in pseudocode, the lower bound for rows (LBR) and the upper
bound for rows (UBR), the lower bound for columns (LBC) and the upper bound for columns
(UBC), and data type are included:

For example:

The declared array can then be used, as follows:


using a nested FOR … NEXT loop.
2 In your chosen programming language, write a short program to complete this task, then
output the contents of the array.

Arrays are used to store multiple data items in a uniformly accessible manner. All the data items
use the same identifier and each data item can be accessed separately by the use of an index. In
this way, lists of items can be stored, searched and put into an order. For example, a list of names
can be ordered alphabetically, or a list of temperatures can be searched to find a particular value.
10.2.3 Using a linear search
To find an item stored in an array, the array needs to be searched. One method of searching is a
linear search. Each element of the array is checked in order, from the lower bound to the upper
bound, until the item is found or the upper bound is reached.
For example, the search algorithm to find if an item is in the populated 1D array myList could be
written in pseudocode as:
This algorithm uses the variables upperBound and lowerBound so that the algorithm is easier to
adapt for different lengths of list. The REPEAT … UNTIL loop makes use of two conditions, so
that the algorithm is more efficient, terminating as soon as the item is found in the list.
As stated in Chapter 9, it is good practice to provide an identifier table to keep track of and
explain the use of each identifier in an algorithm. This allows the programmer to keep track of
the identifiers used and provides a useful summary of identifiers and their uses if the algorithm
requires modification at a later date. Table 10.2 is the identifier table for the linear search
algorithm.

Identifier Description
item The integer to be found
myList Array to be searched
upperBound Upper bound of the array
lowerBound Lower bound of the array
index Pointer to current array element
found Flag to show when item has been found
Table 10.2

10.2.4 Using a bubble sort


Lists can be more useful if the items are sorted in a meaningful order. For example, names could
be sorted in alphabetical order, or temperatures could be sorted in ascending or descending order.
There are several sorting algorithms available. One method of sorting is a bubble sort. Each
element of the array is compared with the next element and swapped if the elements are in the
wrong order, starting from the lower bound and finishing with the element next to the upper
bound. The element at the upper bound is now in the correct position. This comparison is
repeated with one less element in the list, until there is only one element left or no swaps are
made.
For example, the bubble sort algorithm to sort the populated 1D array myList could be written in
pseudocode as:
Table 10.3 is the identifier table for the bubble sort algorithm.

Identifier Description
myList Array to be searched
upperBound Upper bound of the array
lowerBound Lower bound of the array
index Pointer to current array element
swap Flag to show when swaps have been made
top Index of last element to compare
temp Temporary storage location during swap
Table 10.3

The following eight tables show the changes to the 1D array myList as the bubble sort is
completed. After each iteration of the FOR … NEXT loop, the highest value in the list is
correctly placed and the lower values of the list are swapped and move towards the start of the
list, until no more swaps are made.
First pass of bubble sort
All nine elements compared and five swaps:

Figure 10.3

Second pass of bubble sort


Eight elements compared and three swaps:
Figure 10.4

Third pass of bubble sort


Seven elements compared and three swaps:

Figure 10.5

Fourth pass of bubble sort


Six elements compared and three swaps:

Figure 10.6

Fifth pass of bubble sort


Five elements compared and three swaps:
Figure 10.7

Sixth pass of bubble sort


Four elements compared and one swap:

Figure 10.8

Seventh pass of bubble sort


Three elements compared and one swap:
Figure 10.9

Eighth pass of bubble sort


Two elements compared and no swaps:

Figure 10.10
10.3 Files
Computer programs store data that will be required again in a file. Every file is identified by its
filename. In this chapter, we are going to look at how to use text files. Text files contain a
sequence of characters. Text files can include an end of line character that enables the file to be
read from and written to as lines of characters.
In pseudocode, text files are handled using the following statements.
To open a file before reading from it or writing to it:

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:

Once the file is opened in WRITE or APPEND mode, it can be written to a line at a time:

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.

When a file is no longer being used it should be closed:

This pseudocode shows how the file myText.txt could be written to and read from:
ACTIVITY 10I
Extend this pseudocode to append further lines to the end of myFile. In your chosen
programming language write a short program to complete this file handling routine.

Identifier name Description


textLn Line of text
myFile File name
Table 10.4
10.4 Abstract data types (ADTs)
An abstract data type (ADT) is a collection of data and a set of operations on that data. For
example, a stack includes the items held on the stack and the operations to add an item to the
stack (push) or remove an item from the stack (pop). In this chapter we are going to look at three
ADTs: stack, queue and linked list.
Table 10.5 lists some of the uses of stacks, queues and linked lists mentioned in this book.

Stacks Queues Linked lists


Memory management Management of files sent to a Using arrays to implement a
(see Section 16.1) printer (see Section 5.1) stack (see Section 19.1)
Expression evaluation Buffers used with keyboards Using arrays to implement a
(see Section 16.3) (see Section 5.1) queue (see Section 19.1)
Backtracking in Scheduling (see Section 16.1) Using arrays to implement a
recursion (see Section binary tree (see Section 19.1)
19.2)
Table 10.5 Uses of stacks, queues and linked lists

• 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.
• 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.
• 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.

Figure 10.11 Stack and queue

startPointer
Figure 10.12 Linked list

Stacks, queues and linked lists all make use of pointers to manage their operations. Items stored
in stacks and queues are always added at the end. Linked lists make use of an ordering algorithm
for the items, often ascending or descending.
A stack uses two pointers: a base pointer points to the first item in the stack and a top pointer
points to the last item in the stack. When they are equal there is only one item in the stack.
A queue uses two pointers: a front pointer points to the first item in the queue and a rear pointer
points to the last item in the queue. When they are equal there is only one item in the queue.
A linked list uses a start pointer that points to the first item in the linked list. Every item in a
linked list is stored together with a pointer to the next item. This is called a node. The last item in
a linked list has a null pointer.
10.4.1 Stack operations
The value of the basePointer always remains the same during stack operations:

Figure 10.13

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.
In pseudocode, stack operations are handled using the following statements. Please note that you
are not expected to be able to write the pseudocode statements included in this section at
Cambridge AS Level. However, you may find them useful to refer back to if you are studying
the full Cambridge A Level syllabus.

To set up a stack

To push an item, stored in item, onto a stack


To pop an item, stored in item, from the stack

ACTIVITY 10J
Look at this stack.

Show the stack and the value of topPointer and basePointer when an item has been popped off
the stack and 67 followed by 92 have been pushed onto the stack.
10.4.2 Queue operations
The value of the frontPointer changes after dequeue but the value of the rearPointer changes after
enqueue:

Figure 10.14

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.

Figure 10.15 Circular queue operation

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.
In pseudocode, queue operations are handled using the following statements.

To set up a queue

To add an item, stored in item, onto a queue

To remove an item from the queue and store in item


ACTIVITY 10K
Look at this queue.

Show the circular queue and the value of the length of the queue, frontPointer and rearPointer
when three items have been removed from the queue and 25 followed by 75 have been added
to the queue.
10.4.3 Linked list operations
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.
The following diagrams demonstrate the operations of linked lists.
The startPointer = –1, as the list has no elements. The heap is set up as a linked list ready for use.

Figure 10.16

The startPointer is set to the element pointed to by the heapPointer where 37 is inserted. The
heapPointer is set to point to the next element in the heap by using the value stored in the
element with the same index in the pointer list. Since this is also the last element in the list the
node pointer for it is reset to –1.
Figure 10.17

The startPointer is changed to the heapPointer and 45 is stored in the element indexed by the
heapPointer. The node pointer for this element is set to the old startPointer. The node pointer for
the heapPointer is reset to point to the next element in the heap by using the value stored in the
element with the same index in the pointer list.

Figure 10.18

The process is repeated when 12 is added to the list.


Figure 10.19

To set up a linked list


The above code sets up a linked list ready for use. Below is the identifier table.

Identifier Description
myLinkedList Linked list to be searched
myLinkedListPointers Pointers for linked list
startPointer Start of the linked list
heapStartPointer Start of the heap
index Pointer to current element in the linked list
Table 10.6

The table below shows an empty linked list and its corresponding pointers.

Table 10.7 Empty myLinkedList and myLinkedListPointers

You will not be expected to write pseudocode to implement and use these structures, but you will
need to be able to show how data can be added to and deleted from these ADTs.

ACTIVITY 10L
Look at this linked list.
Show the linked list and the value of startPointer and heapPointer when 37 has been removed
from the linked list and 18 followed by 75 have been added to the linked list.
11.2 Programming constructs
11.2.1 CASE and IF
The algorithm in Example 11.2 uses a nested IF statement, as there are two different choices to
be made. Where there are several different choices to be made, a CASE statement should be used
for clarity.
Figure 11.1 shows that choices can be made using a condition based on
• the value of the identifier being considered, for example < 10
• a range of values that the identifier can take, for example 1:10
• the exact value that the identifier can take, for example 10.
And a final catch all for an identifier that met none of the conditions given OTHERWISE.
For each criterion there can be one or many statements to execute.
Figure 11.1

For example, choices from a menu can be managed by the use of a CASE statement.
Table 11.7 below shows the case statements in VB and Java. Python does not use this construct.

Table 11.7

ACTIVITY 11D
1 Write an algorithm using pseudocode to either add, subtract, multiply or divide two numbers
and output the answer. The two numbers are to be input with appropriate prompts followed
by +, −, * or /. Any other character is to be rejected.
2 Check that your pseudocode algorithm works by writing a short program in your chosen
programming language from your pseudocode statements using the same names for your
identifiers.
11.2.2 Loops
Loops enable sections of code to be repeated as required. They can be constructed in different
ways to meet the requirements of an algorithm.
1 a count-controlled loop FOR … NEXT
2 a post-condition loop REPEAT … UNTIL
3 a pre-condition loop WHILE … DO … ENDWHILE
In order to program efficiently, it is important to select the appropriate loop structure to
efficiently solve the problem. For example, it is better to use a REPEAT … UNTIL loop rather
than a WHILE … DO … ENDWHILE loop for a validation check. The statements inside the
loop must always be executed at least once and there is no need for a second input statement.
For example, to check that a value is between 0 and 10 inclusive.

Table 11.8 below shows post-condition loops in VB and Java. Python only uses pre-condition
loops.

Table 11.8

Table 11.9 below shows pre-condition loops in each of the three programming languages.

Pre-condition loops Language


Python

VB
Java

Table 11.9

Where the number of repetitions is known, a FOR … NEXT loop is the best choice, as the loop
counter does not have to be managed by the programmer.
1.3 Structured programming
Key terms
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.
11.3.1 Procedures
When writing an algorithm, there are often similar tasks to perform that make use of the same
groups of statements. Instead of repeating these statements every time they are required, many
programming languages make use of subroutines or named procedures. A procedure is defined
once and can be called many times within a program.
Different terminology is used by some programming languages. Procedures are
• void functions in Python
• subroutines in VB
• methods in Java.
To be consistent, we will use the term procedure – you will need to check what to do in your
chosen programming language.
A procedure can be defined in pseudocode, as follows:

The procedure can then be called many times:

For example, a procedure to print a line of stars would be defined as follows:

And used like this:

ACTIVITY 11F
Using the procedure definition and call given for your chosen programming language, write a
short program to define and call a procedure to write a line of stars.

Table 11.10 below shows how to define this procedure in each of the three prescribed
programming languages.

Table 11.10

Table 11.11 shows how it can be used.

Procedure – call Language


stars() Python
stars() VB
stars(); Java
Table 11.11

It is often useful to pass a value to a procedure that can be used to modify the action(s) taken. For
example, to decide how many stars would be output. This is done by passing a parameter when
the procedure is called.
A procedure with parameters can be defined in pseudocode, as follows:

The procedure can then be called many times:

The procedure to print a line with a given number stars would be defined as follows:

And used like this, to print seven stars:

The interface between a procedure and a program must match the procedure definition. When a
procedure is defined with parameters, the parameters in the procedure call must match those in
the procedure definition.
Table 11.12 below shows how to define a procedure with a parameter in each of the three
programming languages.

Table 11.12

ACTIVITY 11G
Extend your short program in your chosen programming language to define and use a
procedure that accepts a parameter to write a line with a given number of stars.

There are two methods of passing a parameter to a procedure: by value and by reference. When
a parameter is passed by value, if a variable is used, the value of that variable cannot be changed
within the procedure. When a parameter is passed by reference the value of the variable passed
as the parameter can be changed by the procedure.
A procedure with parameters passed by reference can be defined in pseudocode as follows:

For example, a procedure to convert a temperature from Fahrenheit to Celsius could be defined
as follows:

And used as follows:

Table 11.13 below shows how to pass parameters in the three programming languages.

Passing parameters Language


Def celsius(temperature): Python
all data is passed by value
Sub celsius(temperature As Decimal) VB
Sub celsius(ByVal temperature As Decimal)
parameter passed implicitly by value
Sub celsius(ByRef temperature As Decimal)
parameter passed by value
parameter passed by reference

static void celsius(double temperature) Java


all data is passed by value
11.3.2 Functions
When writing an algorithm, there are often similar calculations or tasks to perform that make use
of the same groups of statements and always produce an answer. Instead of repeating these
statements every time they are required, many programming languages make use of subroutines
or named functions. A function always returns a value; it is defined once and can be called many
times within a program. Functions can be used on the right-hand side of an expression.
Different terminology is used by some programming languages. Functions are
• fruitful functions in Python
• functions in VB
• methods with returns in Java.
A function without parameters is defined in pseudocode as follows:

A function with parameters is defined in pseudocode as follows:

The keyword RETURN is used as one of the statements in a function to specify the value to be
returned. This is usually the last statement in the function definition. There can be more than one
RETURN used in a function if there are different paths through its statements. This technique
needs to be used with great care. For example, a function to find a substring of a given length
starting at a given place in a string that returns a null string rather than an error could be:
Functions are used as part of an expression. The value returned by the function is used in the
expression.
For example, the procedure used previously to convert a temperature from Fahrenheit to Celsius
could be written as a function:

And used as follows:

The interface between a function and a program must match the function definition. When a
function is defined with parameters, the parameters in the function call must match those in the
function definition.
Table 11.14 below shows how to write this function in each of the three programming languages.

Table 11.14

ACTIVITY 11I
Re-write the algorithm you wrote in Activity 11H as a function, with a parameter, to convert a
temperature from Celsius to Fahrenheit. Test your algorithm by writing a short program in
your chosen programming language to define and use this function. Note the differences in
your programs and state, with reasons, which is the better structure to use for this algorithm: a
procedure or a function.

When procedures and functions are defined, the first statement in the definition is a header,
which contains
• the name of the procedure or function
• any parameters passed to the procedure or function
• the type of the return value for a function.
When procedures or functions are called, the parameters or arguments (the values passed to the
procedure or function) must be in the same order as the parameters in the declaration header and
each argument must be of the same type as the parameter given in the header. Procedure calls are
single stand-alone statements and function calls form part of an expression on the right-hand
side.
12 Software development
In this chapter, you will learn about
• the purpose, types and stages of the program development lifecycle
• how to document program design using structure charts and state-transition diagrams
• avoiding syntax, logic and run-time errors in programs
• different methods of testing programs to identify and correct such errors
• the types of maintenance used as part of the program development lifecycle.
Program development lifecycle
WHAT YOU SHOULD ALREADY KNOW
You may have studied or heard about the systems (or program) development lifecycle.
Try this activity before you read the first part of this chapter. A program development lifecycle
goes through the same stages for a program.
Name and describe the stages of the program/ systems development lifecycle. There are
different development lifecycles used depending upon the system and the type of program
being developed. Identify at least four of these. Work in small groups to research one of these
and share your findings with the other groups.

Key terms
Program development lifecycle – the process of developing a program set out in five stages:
analysis, design, coding, testing and maintenance.
Analysis – part of the program development lifecycle; a process of investigation, leading to the
specification of what a program is required to do.
Design – part of the program development lifecycle; it uses the program specification from the
analysis stage to show how the program should be developed.
Coding – part of the program development lifecycle; the writing of the program or suite of
programs.
Testing – part of the program development lifecycle; the testing of the program to make sure
that it works under all conditions.
Maintenance – part of the program development lifecycle; the process of making sure that the
program continues to work during use.
Waterfall model – a linear sequential program development cycle, in which each stage is
completed before the next is begun.
Iterative model – a type of program development cycle in which a simple subset of the
requirements is developed, then expanded or enhanced, with the development cycle being
repeated until the full system has been developed.
Rapid application development (RAD) – a type of program development cycle in which
different parts of the requirements are developed in parallel, using prototyping to provide early
user involvement in testing.
12.1.1 The purpose of a program development lifecycle
In order to develop a successful program or suite of programs that is going to be used by others
to perform a specific task or solve a given problem, the development needs to be well ordered
and clearly documented, so that it can be understood and used by other developers.
This chapter introduces the formal stages of software (program) development that are set out in
the program development lifecycle.
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.
12.1.2 Stages in the program development lifecycle
The stages of development in the program development lifecycle are shown in this chapter. The
coding, testing and maintenance stages are looked at in depth and include appropriate tools and
techniques to be used at each stage. Therefore, practical activities will be suggested for these
stages to help reinforce the skills being learnt.
Here is a brief overview of the program development lifecycle, divided into the five stages, as
shown in Figure 12.1.

Figure 12.1 The program development lifecyle

Analysis
Before any problem can be solved, it needs to be clearly defined and set out so everyone working
on the solution understands what is needed. This is called the requirements specification. The
analysis stage often starts with a feasibility study, followed by investigation and fact finding to
identify exactly what is required from the program.

Design
The program specification from the analysis stage is used to show how the program should be
developed. When the design stage is complete, the programmer should know what is to be done,
all the tasks that need to be completed, how each task is to be performed and how the tasks work
together. This can be formally documented using structure charts, state-transition diagrams and
pseudocode.

Coding
The program or set of programs is written using a suitable programming language.

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.1.3 Different development lifecycles
Each program development methodology has its own strength. Different models have been
developed based on the lifecycle for developers to use in practice. The models we will consider
will be divided into the five stages set out above: analysis, design, coding, testing and
maintenance.
In this section of the chapter, we will look at three models: The waterfall model, the iterative
model, and rapid application development (RAD).

The waterfall model

Figure 12.2 The waterfall model

This linear sequential development cycle is one of the earliest models used, where each stage is
completed and signed off before the next stage is begun. This model is suitable for smaller
projects with a short timescale, for which the requirements are well known and unlikely to
change.

Principles linear, as each stage is completed before the next is begun


well documented as full documentation is completed at every stage
low customer involvement; only involved at the start and end of the process
Benefits easy to manage, understand and use
stages do not overlap and are completed one at a time
each stage has specific deliverables
works well for smaller programs where requirements are known and understood
Drawbacks difficult to change the requirements at a later stage
not suitable for programs where the requirements could be subject to change
working program is produced late in the lifecycle
not suitable for long, complex projects
Table 12.1 Principles, benefits and drawbacks to the waterfall model

The iterative model

Figure 12.3 The iterative model

This development cycle first develops a simple subset of the requirements, then expands or
enhances the model and runs the development cycle again. These program development cycles
are repeated until the full system has been developed. This model is suitable for projects for
which the major requirements are known but some details are likely to change or evolve with
time.

Principles incremental development as the program development lifecycle is repeated


working programs are produced for part of the system at every iteration
high customer involvement, as part of the system can be shown to the customer
after every iteration
Benefits some working programs developed quickly at an early stage in the lifecycle
easier to test and debug smaller programs
more flexible as easier to alter requirements
customers involved at each iteration therefore no surprises when final system
delivered
Drawbacks whole system needs to be defined at start, so it can be broken down into pieces
to be developed at each iteration
needs good planning overall and for every stage
not suitable for short simple projects
Table 12.2 Principles, benefits and drawbacks to the iterative model

Rapid application development (RAD)


Figure 12.4 Rapid application development (RAD)

This development cycle develops different parts of the requirements in parallel, using
prototyping to provide early user involvement in testing. Program development cycles are run in
parallel for each part of the requirement, using a number of different teams. Prototyping is often
used to show initial versions to customers to obtain early feedback. This model is suitable for
complicated projects that need developing in a short timeframe to meet the evolving needs of a
business.

Principles minimal planning


reuses previously written code where possible, makes use of automated code
generation where possible
high customer involvement, as customers can use the prototypes during
development
Benefits reduced overall development time
rapid frequent customer feedback informs the development
very flexible as requirements evolve from feedback during development
as parts of the system are developed side by side, modification is easier because
each part must work independently
Drawbacks system under development needs to be modular
needs strong teams of skilled developers
not suitable for short simple projects
Program design
WHAT YOU SHOULD ALREADY KNOW
In this chapter, you will need to be able to write more complicated pseudocode, as described by
a structure chart. It is essential that you consolidate your knowledge before you attempt to do
this.
Make sure that you have read and understood Chapter 11 and you are able to write pseudocode
that passes parameters to procedures and functions.

Key terms
Structure chart – a modelling tool used to decompose a problem into a set of sub-tasks. It
shows the hierarchy or structure of the different modules and how they connect and interact
with each other.
Finite state machine (FSM) – a mathematical model of a machine that can be in one state of a
fixed set of possible states; one state is changed to another by an external input; this is known
as a transition.
State-transition diagram – a diagram showing the behaviour of a finite state machine (FSM).
State-transition table – a table showing every state of a finite state machine (FSM), each
possible input and the state after the input.
12.2.1 Purpose and use of 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. Each module is represented by a box and the
parameters passed to and from the modules are shown by arrows pointing towards the module
receiving the parameter. Each level of the structure chart is a refinement of the level above.
Figure 12.5 shows a structure chart for converting a temperature from Fahrenheit to Celsius. The
top level shows the name for the whole task that is refined into three sub-tasks or modules shown
on the next level.

Figure 12.5 A structure chart for converting a temperature from Fahrenheit to Celsius

ACTIVITY 12A
Draw a structure chart to input the height and width of a right-angled triangle, calculate output
and output the length of the hypotenuse.

Structure charts can also show selection. The temperature conversion task above could be
extended to either convert from Fahrenheit to Celsius or Celsius to Fahrenheit using the diamond
shaped box to show a condition that could be true or false, as shown in Figure 12.6.
Figure 12.6

ACTIVITY 12B
Draw a structure chart to input the radius of a sphere, calculate output and output either the
volume or the surface area.

Structure charts can also show repetition. The temperature conversion task above could be
extended to repeat the conversion until the number 999 is input. The repetition is shown by
adding a labelled semi-circular arrow above the modules to be completed (Figure 12.7).
Figure 12.7

Once a structure chart has been completed, it can be used to derive a pseudocode algorithm.

ACTIVITY 12C
Amend your structure chart to input the radius of a sphere, calculate and output either the
volume or the surface area. The algorithm should repeat until a radius of zero is entered.

Figure 12.8 shows a possible structure chart for Activity 12C.

Figure 12.8

To derive the pseudo code first, you will need to create an identifier table.

Identifier name Description


radius Stores radius input
answer Stores result of calculation
pi Constant set to 3.142
Table 12.4

Then declare constants and variables in pseudocode. You can identify two of the variables
required from the parameters shown in the structure diagram.

DECLARE radius : REAL


DECLARE answer : REAL
CONSTANT pi ← 3.142

Provide pseudocode for the modules shown in the structure diagram. As Calculate volume and
Calculate surface area provide the answer to a calculation, these can be defined as functions.

The input and output modules could be defined as procedures.

The pseudocode for the whole algorithm, including the selection and repetition, would be as
follows.
ACTIVITY 12D
Draw a structure chart to extend the temperature conversion algorithm to both convert from
Fahrenheit to Celsius and Celsius to Fahrenheit, and repeat until a temperature of 999 is input.
Use your structure chart to create an identifier table and write the pseudocode for this
algorithm.
12.2.2 Purpose and use of state-transition diagrams to
document algorithms
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 show the conditions needed for an event or events that will cause a
transition to occur, and the outputs or actions carried out as the result of that transition.
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.
The algorithm for unlocking a door using a three-digit entry code can be represented by a state-
transition diagram. If the door is unlocked with a three-digit entry code, the lock can be in four
states
• locked and waiting for the input of the first digit
• waiting for the input of the second digit
• waiting for the input of the third digit
• unlocked.
If an incorrect digit is input, then the door returns to the locked state. The algorithm halts when
the door is unlocked. A state-transition table shows every state, each possible input and the
state after the input. The state-transition table for a door with the entry code 259 is shown below.

Current state Event Next state


locked 2 input waiting for input of 2nd digit
locked not 2 input locked
waiting for input of 2nd digit 5 input waiting for input of 3rd digit
waiting for input of 2nd digit not 5 input locked
waiting for input of 3rd digit 9 input unlocked and stopped
waiting for input of 3rd digit not 9 input locked
Table 12.5 The state-transition table for a door with the entry code 259

The state-transition diagram for a door with the entry code 259 is shown in Figure 12.9.
Figure 12.9 State-transition diagram for a door with the entry code 259

ACTIVITY 12E
Draw a state-transition diagram for the operation of a television with a single on/off button.
The television can be in three states: on, off and standby. If the button is pressed once (single
press) in standby or off, the television switches on; if the button is pressed once (single press)
when the television is on, the television goes to standby; if the button is pressed twice (double
press) when the television is on, the television goes to off. Double presses in standby or off are
ignored.
Copy and complete the state-transition table and draw the state-transition diagram for the
television operation.

Current state Event Next state


Off Single press
Off Double press
Standby Single press
Standby Double press
On Single press
On Double press
12.3 Program testing and maintenance
WHAT YOU SHOULD ALREADY KNOW
You will need to be able to know how to thoroughly test any programs that you write. Have a
go at the activity below.
Take a program that you have written recently and explain to another student how you tested
the program and which data sets you chose for your testing.

Key terms
Trace table – a table showing the process of dry-running a program with columns showing the
values of each variable as it changes.
Run-time error – an error found in a program when it is executed; the program may halt
unexpectedly.
Test strategy – an overview of the testing required to meet the requirements specified for a
particular program; it shows how and when the program is to be tested.
Test plan – a detailed list showing all the stages of testing and every test that will be
performed for a particular program.
Dry run – a method of testing a program that involves working through a program or module
from a program manually.
Walkthrough – a method of testing a program. A formal version of a dry run using pre-
defined test cases.
Normal test data – test data that should be accepted by a program.
Abnormal test data – test data that should be rejected by a program.
Extreme test data – test data that is on the limit of that accepted by a program.
Boundary test data – 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.
White-box testing – a method of testing a program that tests the structure and logic of every
path through a program module.
Black-box testing – a method of testing a program that tests a module’s inputs and outputs.
Integration testing – a method of testing a program that tests combinations of program
modules that work together.
Stub testing – the use of dummy modules for testing purposes.
Alpha testing – the testing of a completed or nearly completed program in-house by the
development team.
Beta testing – the testing of a completed program by a small group of users before it is
released.
Acceptance testing – the testing of a completed program to prove to the customer that it works
as required.
Corrective maintenance – the correction of any errors that appear during use.
Perfective maintenance – the process of making improvements to the performance of a
program.
Adaptive maintenance – the alteration of a program to perform new tasks.
12.3.1 Ways of avoiding and exposing faults in
programs
Most programs written to perform a real task will contain errors, as programmers are human and
do make mistakes. The aim is to avoid making as many mistakes as possible and then find as
many mistakes as possible before the program goes live. Unfortunately, this does not always
happen and many spectacular failures have occurred. More than one large bank has found that its
customers were locked out of their accounts for some time when new software was installed.
Major airlines have had to cancel flights because of programming errors. One prison service
released prisoners many days earlier than required for about 15 years because of a faulty
program.
Faults in an executable program are frequently faults in the design of the program. Fault
avoidance starts with the provision of a comprehensive and rigorous program specification at the
end of the analysis phase of the program development lifecycle, followed by the use of formal
methods such as structure charts, state-transition diagrams and pseudocode at the design stage.
At the coding stage, the use of programming disciplines such as information hiding,
encapsulation and exception handling, as described in Chapter 20, all help to prevent faults.
Faults or bugs in a program are then exposed at the testing stage. Testing will show the presence
of faults to be corrected, but cannot guarantee that large, complex programs are fault free under
all circumstances. Faults can appear during the lifetime of a program and may be exposed during
live running. The faults are then corrected as part of the maintenance stage of the program
lifecycle.
12.3.2 Location, identification and correction of errors
Syntax errors are errors in the grammar of a source program. In the coding phase of the program
development lifecycle, programs are either compiled or interpreted so they can be executed.
During this operation, the syntax of the program is checked, and errors need to be corrected
before the program can be executed. Figure 12.10 shows an example of a syntax error being
found, and the IDE offering a possible reason for the error.

Figure 12.10

Many IDEs will offer suggestions about what syntax errors are and how to correct them.
Logic errors are errors in the logic of a program, meaning the program does not do what it is
supposed to do. These errors are usually found when the program is being tested. For example,
the program in Figure 12.11 will run, but the results will not be as expected.

Figure 12.11

Many IDEs will allow you to single step through a program to find errors (see Chapter 5, Section
5.2.4). You can also manually work through a program to check that it works as it should, using
tools such as a trace table. Trace tables show the process of dry-running a program with
columns showing the values of each variable as it changes.
Run-time errors happen when the program is executed. The program may halt unexpectedly or
go into an infinite loop and need to be stopped by brute force. If a program is being tested in an
IDE, then this type of error may be managed, and a suitable error message given, as shown
below.
If the program has already been released for use and a run-time error occurs, the developer
should be informed so that the program can be updated and re-released or a patch can be sent out
to all customers to solve the problem. A patch is a small program, released by the developers, to
run with an existing program to correct an error or provide extra functionality. The Windows
operating system is frequently patched and the process of downloading patches and updating the
program has been automated.
12.3.3 Program testing
Programs need to be rigorously tested before they are released. Tests begin from the moment
they are written; they should be documented to show that the program is robust and ready for
general use.
There needs to be a test strategy set out in the analysis stage of the program development
lifecycle showing an overview of the testing required to meet the requirements specified. This
shows how and when the program is to be tested.
In order to clarify what tests need to be performed, a test plan is drawn up showing all the stages
of testing and every test that will be performed. As the testing is carried out, the results of the
tests can be added to the plan showing that the program has met its requirements.
There are several formal methods of testing used to ensure that a program is robust and works to
the standard required. Although there is a testing stage in the program development lifecycle,
testing in some form occurs at every stage, from design to maintenance.
During the program design stage, pseudocode is written. This can be tested using a dry run, in
which the developer works through a program or module from a program manually and
documents the results using a trace table.
For example, a procedure to perform a calculation could be tested as follows.

The test data used could include 20 10 +, 20 10 −, 20 10 *, 20 10 /, 20 10 ? and 20 0 /.


The trace table below shows the value of each variable and any output.
Table 12.6

The errors found in the routine by performing the dry run have been highlighted in red. These
can now be corrected before this routine is coded.

ACTIVITY 12F
Correct the pseudocode and perform the dry run again to ensure that your corrections work.

ACTIVITY 12G
Using the pseudocode algorithm for the volume and surface area of a sphere in Section 12.2.1,
devise some test data and a trace table to test the algorithm.
Swap your test data and trace table with another student then perform the dry run and complete
the trace table.
Discuss any differences or problems you find.

A walkthrough is a formalised version of a dry run using pre-defined test cases. This is where
another member of the development team independently dry runs the pseudocode, or the
developer takes the team members through the dry run process. This is often done as a
demonstration.
During the program development and testing, each module is tested as set out in the test plan.
Test plans are often set out as a table; an example for the calculation procedure is shown below.

Table 12.7 An example of a calculation procedure set out as a table

The results from this testing show that the error in the subtraction calculation has not been fixed
and the routine is not trapping any abnormal data in the variables used by the calculation. These
errors will need correcting and then the routine will need to be retested.
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.
• 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.

ACTIVITY 12H
An algorithm is to be written to test whether a password is eight characters or more and 15
characters or less in length. The password must contain at least one digit, at least one capital
letter and no characters other than letters or digits.
Devise a set of test data to be used to test the password checking algorithm.
Discuss any problems there may be in devising a complete set of test data.

EXTENSION ACTIVITY 12D


In the programming language you have chosen to use, write a procedure to check that the
password conforms to the rules in Activity 12H. Use your test data from the previous activity
to write a test plan and test that your procedure works as it should.

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:
• 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.3.4 Program maintenance
Program maintenance is not like maintaining a piece of equipment by replacing worn out parts.
Programs do not wear out, but they might not work correctly in unforeseen circumstances. Logic
or run-time errors that require correction may occur from time to time, or users may want to use
the program in a different way.
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.

ACTIVITY 12I
Analyse the pseudocode algorithm for the volume and surface area of the sphere in Section
12.2.1 and identify at least three improvements you could make to the functionality of this
algorithm.

ACTIVITY 12J
1 Explain, using examples, the difference between syntax and logic errors.
2 A programmer wants to test that a range check for values over 10 and under 100 works.
Identify three types of test data that should be used. Provide an example of each type of test
data and describe how the program should react to the data.
3 Identify three types of program maintenance and describe the role of each type of
maintenance.

End of chapter questions


1 When the guarantee on a computer runs out, the owner can take out insurance to cover
breakdown and repairs.
The price of the insurance is calculated from:
– the model of the computer
– the age of the computer
– the current insurance rates
Following an enquiry to the insurance company, the customer receives a quotation letter
with the price of the insurance. A program is to be produced.
The structure chart below shows the modular design for this process.

You might also like