0% found this document useful (0 votes)
67 views177 pages

Olevel Computer Science Study Notes Made by Ahmed Wael

Uploaded by

Ahmed Wael
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)
67 views177 pages

Olevel Computer Science Study Notes Made by Ahmed Wael

Uploaded by

Ahmed Wael
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/ 177

Chapter 1

Data representation
⑤ Definition of a
computer:
It's device thatreceives input, does
a
processing on

thatinput, and
produces an
output.
* terms:
Used by key
humans -

Analoguedata constantly varying data


used
by data discrete data made of 2 states:O and 3
computers
=-
Digital only
software programs thatcontrol hardware

Hardware
physical components making up computer system

5) Types of data
Audio

vancesimage
->

A.Number
systems (Numbers) value
Value 3x10=30
=

=
A) Denary, Value
2x10
=


200
↑ -value =

8X603
&
2 34+x10 4

= =

·
Base 10 =8000
103 102 10100

· used by humans

·has 30
digits:0, 1, 2, 3, 4, 5, 6, 7, 8, 9
4
1
Value=22
=

Value 2 x1 2 =

value 0XC
=

& value 0x20


B)
Binary: I 0
=

0
=
= =

0118
·
Base 2 2222

and
Only 2 numbers:O
·

understood by computers
·
The
only system
from denary to
·
conversion
binary
subtraction:
by
-

180 denaery)
128 6432 16 ⑧ I 2 I

N · ↑ ↑ o N o o

180 52 20 -44
128 16
-

32
-

-
- >

S2 -

2. List of a
powers
2. PutI under the
largestnumber less than required number
3. subtractthe
largestnumber from required
4.
Repeattill you getzero from subtraction
so fill
empty places with zeros

by division:
180
(denary
Remainder
2 180
2 90 o a
10110100
295 o
2 22 1

21 o 1. Divide by 2
25 I 2- write remainder (even if zers]

3. Repeattilingondivisioneards
n
2 2 I

↓ o

↑ 1
·
conversion from
binary to
denary:
10110100 (binary

128 64 3216 ⑧ 42 1

I o I 2 o I oo

+
120 1. place
powers
of 1 above the values -

32

16 Add the with under


+

2.

4 powers
them.

2) Hexadecimal i Value 10x15


= value 15x160 15
=
=

160
&AF
=

·
Base 76
16160
used
by programmers
·

·
has 16
digits
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, f
A
10

B11

C 12

D13

E 14

F15
·
Each hexadecimal digit
is
represented by 4 bits
from hexadecimal
·
conversion to
binary:
A
fas
⑩ &
81%/910 ·f; (?1,
1010 1 1 11

C
Converteach digitto binary separately and list
them as one number.
·

conversion from hexadecimal to


denary
·
to binary then to denary:
178693216 ↑ 21

2
1 0 10 11/1
128

#
#
32

Convertto binary then to
denary
t
4
+
2

171
-

multiplying by powers of 16..

3840
354167 14436:2200 12
=

>FEC
=

75x763/1096) ⑥S digittimethese
=

61440 77
61448
·Multiplyeach place
#
+
3840
16 116 8616: 256
= =

224
36 4096
7
12
-> =

655/6
·
Add the values
from to hexadecimal:
Conversion
binary
·

OUl10IOLIOl (binary)

S
. ↓ 3
842 8 4 21 8421
⑥ O I I o I 0
I 1 010

3 5 A
·
Divide binary to chunks of bits
3SA each chunk to
·
convert
denary
·
convertas
Listfrom
digits
to letters
lestto
right
·

hexadecimal:
conversion from
denary to
·

867(denary

Convertto binary then to hex

for
Reasons
using
hexadecimal
by programmers instead of
binary
·

1 takes less the


up space on screen

2 -
easier for programmers to identify errors

3. Easier to remember

4 fewer errors are made in data transcription


5- Easier to read and understand.
15. Text:

· Each character
8-bitcode.
in a is
text represented by
·
For each character, there's a
unique number.

·
Numbers are standarised by representation.
ASCII
"." sign indicates thatthe indicating
·

following text is nex

text.
Iwantto getlaid.
5 73j(space) 32;w 115; a
97;n 100; t 16
=
=
= =
=
=

0
11;9 303;e 101;( 108;i 105;d 100
= =
= =
= =

10100100/
·49%28%77%66%67
-00100000
2011 11%74%20%74%67%20%67%65
10 /

a0(100001%74%20%67%66%69-64
1 0 1 1 1 0
n0
10 1110100

-
00100000
1 1 1 0 1 0 0
t 0
0 1 1 0 1 1 I I

00100000
g 0 1 1 0 0 1 1 I

0 1100 10 1
↑ 0 1110100
-00100000
10 1101100
a0110000/
i 0 / 10100 1
d 01100100
=A. Images: -

An is made of pixels.
image
-

·
Each pixel represents a colour

pixel:Atiny illuminating doto n the screen


representing
a colour.
-

Number of pixels Image Resolution


is

·
Bits
representing pixel is colour depth
a

and colour
Image quality depends on resolution depth
Amountof ↓
Amount
details of colour.
Bits

Size of an
image
file
No. of
=

pixels colour
x
depth
↳Bits

EN. Audio:
-
An audio file is represented using a
sample process where
a
sample of the wave form is obtained per unit time.

Sampling rate Numberof samples obtained second


every
-

sampling resolution numberof bits


representing each
sample.
·

sound at
sampling:process of
determining amplitude of
·

differenttime intervals.
Bit
of audio like
->

Size an

sampling rate xLength of track


·
X sampling
resolution
I- ↓ ↓
samples (sec. Sec.
bits
# units:
Memory -

refers
Bit
1. to one
binary digit
0101 1100

·his number takes up 8 bits.


2. Nibble refers to four bits

The above number takes a nibbles


up
3. Byte contains 8 bits

the above number takes


up
1
byte
200
kilobyte bytes

1103(kB)
Megabyte 22
bytes
5 +10

!
103
> x10
(MB)

- Gigabyte 230 bytes

20
x10 (GB]
140
=20
x1p Terabytep)
bytes
↑ to

petabytepp) 260
bytes
5) file compression:
J. Lossless compression:
·

Compression with no loss of data


·
used when it's essential that no data is lost:

·
code file
text
oileile
-

Database

·used file
with
any type
Run-length encoding (RLF): -

·
The
repeated patterns of characters are identified
then they're encoded into a values: ·

& Run count:number of characters


2 -
Run value:the character

Data
dictionary:
·
The
repeated characters are identified
They're then indexed.
·

They're replaced by their index.


The positions of these characters are stored in the
·

table.
·
The number of times the characters appear in the
file is stored in the table.
5.
Lossy Compression: -

·
Method of compression where reductantdetails are
permanen My removed from the file.
·
used when a file does nothave to be the same
as the original:
Images
·

·
Videos
· Audio
·

Quality is affected, butnotsignificantly.


How to
lossyly compress an
image:
used
·
A
compression algorithmis
·
Redundantdetails are
permanently removed from
the file.
·

Image resolution can be reduced.


·
colour
depth can be reduced.
How to
lossyly compress an audio file:
used
·A
compression algorithm is

Redundantdetails removed from


·

the file.
are
permanently
·

Sampling rate can be reduced


·

sampling resolution can be reduced.


·
sounds inaudible to human ears can also be
removed.

Advantages of using lossy over lossless:


reduces the file size more

transmitted storage
file takes less
file can be up more quickly

File takes less bandwidth to be transmitted over internet.


8) Registers:
It's internal fast
an within CPU that
temporarily
memory
holds data while processing.
shows the conditions of something
register
A
controlled by comple
a fer-
thati s

stall are Os, it's


completely switched off.
It all are 15, there's an error.
Chapter 2

Digital logic
stored
5) Why is data as
binary in computer: a

Computers use
logic gates.
Logic gates can
only use the values 0 and

Is Logic gates:
1. Definition:

small
A
physical device that controls flow of
charge in a
predeterminantway.
#1.
Purposes:
·
Perform a
logical operation
·
control flow of electricity in a
logical circuit

·
alter outputfrom given inputs
#.
Typesi-
As NOT gate: Input Output
01
A X
X NOT A 10
0 =

Output Input =

B) AND
gate:
A
X
X AAND =
B
B

Output only 1 i8 A&B are

A B
both
X
1

oo o
01 o
10 o
I I 1
DOR gate:

n)) x X AOR= B

both
OutputO only it
inputs are 0

A B X
o ① o
o I I
I O I

I I 1

d) NAND
gate:
A B
A)
X NAND
ox
=

if both inputs are


output &
only
(Opposite of AND)
A B X

o O ↓

0 1 1

1 01

1 10

e) NOR gate:
A B
1Dox X =
NOR

if
Output] only both iputs are 0

Opposite of 0k) A B X

o o
o I ↓
10
11 ⑧
11 XOR gate:

B() x X AXOR
=

some input -> 0 output


Differentinput - >

I output
B
A x

oo o
01 1
7 ⑤ 7

1 1 o

B) Logic circuits

combination that
A of
function
logic gates carry out
a
particular
1. Draw a truth table for the circuit:

·P

R
D

Q *

1 (Name intermediate
Step gates a R

logic 8
i
(Write statements)
!'

i. ! :
Step 2

P AOR
=


o ↓

Q B =
NAND C

!
0
R P
=
XOR Q
x R
=
OR C

Step 3
1. Write a statementfor
logic the same circuit

Step 3 Write the


logic equations
P AOR
=
B

Q : B NAND C

R PXOR
=

X ROR
= C

Step 2
& write equation of outputin termsare
X
(PXOR
=
a) OR C

↓ &
X ((AOR B)
=
XOR (B NAND ()) OR C

#· Design a
logic gate for this logic statement:

Step 1 X =( BII
CRBSANDND OR (NOC)
-
->g S

Step 2 p

Step 3 pAOR=

B; q = B
AAND j
r
pANDq;
=

S NOTC;X
=

r
=

OR S

step 4

A
·

P
[ r
A
X
B ·
(
Dop
CANDG
S
C Do
# Draw a
truth table for the same statement

1 PA B;
Step OR =

=
AAND B;
g

u pAND q;
=

S NOT
=
C

x =
r0RS

Step 2

Pars
oo o I I

o oo 0 o

100 1 1

10000
1001 I

I 0 oo o
↓ 1 I
i
1

16 O ↓
Ill.
Wording problem:

Step 1

X 1
=
if (S 0
= AND T = 1) OR (S 1 AND
=
W 1)
=
OR (T 0 AND W 1)
= =

Step 2

(N
5)AND 9) W)
IS- Or (NOTT) W
AND AND
x =
OR
-
-

↑ N
A
Step 3

step 4
p NOT =
S

AND F
g p
=

r S
=

AND W

A
g OR
=

M NOT
= T

N M
=
AND W
X AOR
=

step 5
P
S ·
Do.

AND
↑ 7
A
DoM <

AANDS
r
Dors
W &

DNDN
#1.Truth table for the same problem

step 1
S· AM N
T
an pg
W r

p NOT=
S
10 O O 0 o
g p AND F
1000
! I
=

AND W
118,00 !
r S
=

A
g OR
=

00001 0 o
M NOT
= T
00111 I I

N M AND W
000000 o
=

X AOR
=

N 00 1 10 o 1

2
Step
3
Chapter
Inputdevices

Inputdevices:devices used to enter data into a


computer
system
* Analogue and digital data:
Humans use
analogue data
data
Computers can
only process digital
1.
Analogue to digital converter (ADC)
converts from
analogue signals
data
inputdevices to
digital thata computer can
process
#.
Digital to
analogue converter (DAC)
converts digital data from the computer to
analogue
signals
# Mouse:

J. Mechanical mouse:
principle of operation
1 uses a rubber ball under itto detectmovement

2. Ball pushes againsttwo rollers

3. One roller detects up-and down motion and

the other detects side-to-side motion

#
Optical mouse:
principle of operation
1. shines a laser from the bottom onto a surface
2.
Lightis reflected into photoelectric sensor.
3. The has
sensor
allow detection of
a
lens that
magnifies lightto
smaller movements

1. When a button is clicked, a microswitch


is
pressed.
⑬ Microphone:
Device used to input sound to a
computer.
When a
1.
vibrates
up sound,
microphone picks electrical a a
diaphragn
producing an
signal.
2. This analogue signal is converted to digital signal
ADC the sound card.
using in

voice
recognition
-> softwareused
from their voice
to identify a known user

speech recognition -> software that recognises spoken words


# keyboard:principle of operation
& Acircuitboard is atthe base of the
present
key s
2. When a
key
is
pressed, itcompletes the circuit
and the location of the
keypress is calculated.
3. character
A map is searched to find the character
location of
corresponding to the the
keypress.
4. Each character has a
binary ASCI5 value
5. Asignal with the value of the character
pressed is sentto the CPU to be
processed
⑤ conceptkeyboard:
J. Structure in
·
Aboard
grid of buttons
with a

·Each button programmed to do


is a specific task

An overlay sheetwith
functionplaced
·
pictures over the
buttons to indicate their

7.
Advantages over traditional keyboard:
Fewer errors are made because I button is pressed to orderitem.

Faster because fewer buttons are


pressed to make
an order
6) of operation
Digital camera: principle
1.
Image is captured when lightpasses through the
lens-

2. The
lightis captured by a sensor called
charge-coupled device
converts each
3. An
value
ADC pixel into a
binary
4 pixels are stored in a
sequence in
file
meta data also stored the image
simage
file-
is in

G2D scanner; -

used and documents


Device to convert hardcopy images
to a
digital by form used the computer.
across surface of the document
1. Scanner shines light
and light across the
moves document.
2 reflected is
captured and directed to sensors
light and lenses
using mirrors

passed ADC to control


capturedimage
3. is to an

producing digital image.


optical characters OCR:converts textin a scanned documentto file.
text

recognition Application 1:
used
2D scanner is to scan
passports atairports
OCR, textis selected and filled
Using database automatically
in an
existing
Application 2:.
scanned
Image on a
passport is
using
ID scanner.

Person's face is
captured using digital camera.

key parts of the face in the two digital images


are
compared using facial recognition software so
check if
they representthe same face
⑱ 3D
scanner:

Inputdevice thatproduces models


3D of objects.
5 scanner shines light on the surface of the object.
2-
Lightis reflected to sensors.

3. Measurements of object'sdimensions are recorded.

Measurementsareconvertedtodigital see
4. file

#) Barcode reader:
1. What's a barcode:
consists of black and white lines of varying thickness

represents numeric values or characters.

# How does a
reader work:

shines
1. It a red light(illuminator) on the barcode.

Block lines reflectless white lines


2:
lightthan
3- sensors detectreflected light
4. Differentreflections
values.
different
represent binary
5. A
microprocessor interprets the
reading.
data
#
Advantages compared to entering manually:
Quicker to inputdata
Less
entering data
errors in

IV.
Disadvantages compared to entering data
manually:
If a barcode is
damaged, itcan'tbe scanned.
barcode
The
system is more
expensive
⑩ Quick Response (QR) Reader:
1. Whatis QR code:
Matrixof black and white squares that can link to
websites, videos, text, etc..
7. How is it scanned by QR code reader:

1. A
light is shone over the QR code.
2Light is reflected back to sensors.

3.Black squares reflectless lightthan white squares.

↑ Each small converted to a


square is binary value.

itscanned
How
# is
by smartphone:
1. The camera
captures photo of the
a QR code.
2. The three big squares define the alignment.
3. An the
app processes image.
1. Each small square is converted to a
binary value.

#QR US Bari.
21 3D
contain
squares contain vertical lines
more data held
scanned at angle mustbe aligned with reader
any
scanned faster
Used in Used
Advertising "heckouts
obtaining information libraries
by smartphones
⑯ Interactive whiteboards:
5. Uges: -

displays computer screen

input
text digital keyboard
using
Handwriting recognition
·

computer control
#
Principle of operation:
1
computer's screen is
projected onto the board

2. The board is calibrated to make sure sensors contain


it
line
up
with the
image of the screen.

3. Sensors determine which part of the board is touched


and translate the touch into an action.
13 Capicitive touchscreen: 1. principle of operation
8. Electric field is created and spread across the
conductive layer.

#
2. Sensors around the screen monitor the electric
field.

3. When finger
a touches the screen, some charge
transferred to it electric field
is
in thatlocation. changing
coordinates change calculated
of this
↑ The of are

to determine location touch-


7. Benefits & Drawbacks

can'tbe used with standard


Goodvisibilityneed gloves
Durable surface They're not conductive.
Electric field won't change
multi-touch when
they touch the
screen.
19Resistive touchscreen:
J.
Principle of Operations
polyester and
makeuseofan
of
1.
upper layer a botoone

2. When the upperlayer is touched, the two


layers
complete a circuit

3. The coordinates of where the screen is touched


are
calculated
7. Benefits & Drawbacks

cheap to manufacture Poor visibility in


sunlight
used with No multi-touch
fingers,
gloves or
stylus slow time
response
vulnerable to
scratching.
15 Infrared touchscreen: -

5. Principle of operation:
1. Infrared sentfrom all
edges of the seenthe
are
forming arays
2. Sensors receive the
rays.
3. sensors detectwhen the screen is touched through
a break in the beam.

↑ co-ordinates of where the beam is broken are


calculated.

I. Benefits & Drawbacks

Good durability Expensive to manufacture


multi-touch sensitive to dust

Fingers, gloves or
stylus
6
Chapter
Monitoring & control systems
1) Sensor:
Input device usedto measure
physical properties of the
surrounding environment

of compared
1.
Advantages using sensors to humans:

much more accurate


readings than humans

take
readings more
frequently
work
continuously & no breaks

#
Examples of sensors and their uses:

central heating chemical


of
system process
/ Greenhouse Brightness lightintensit
↑ environment in
·peraturewetness level- greenhouse
right-cinutoster one
water levels
industrial
greenhouseture switch cars headlight
in
in an
see
application
Smoisture in paintspray booth
in a or
factory)
Amountof water vapour #red/motion
⑭emidity house
-

green
in air in a
I
count people
Burglar
burglar alarm
Turn
windscreen
on
alarm entering &
leaving a

&
/
pressureI
weigh things wipers on a cat
building
processwheregas
reportant burglar
alarm ④coustic/soundliquid - detect
noise of

&lg.Opollutionlevelin
a

or CO2)
dropping
from a
pipe
/
in
greenhouse
Aciditylalal
CO, leaks
in a
power
station
anti-lock
pH-pollutingth
magneticmagnetic
application where -

detection one brain


field is need players) system in caVS
# Monitoring systems;
5. Consists of in

Sensors

Microprocessor
Outputdevices
A
Monitoring a
patient for vital
signs.
1. Sensors attached to the patientsend vital
keythe signs
Cheart rate, temperature, blood pressure) to
microprocessor.
2. Data from the is converted to
digital ADC.
sensors
using
3. Microprocessor data with stored values
compares

↑offit's outsideacceptable rangeasignal itreason.


5.5) it's within range, values are justshown in
hical form the screen.
grap on

6-whole
monitoring continues till sensors are disconnected
from the patient.
B)
checking temperature levels in a car
engine:
1. sensors send temperature data to the
microprocessor.
2. Data is converted to
digital using
ADC.

3 Data is compared by microprocessor to stored values

4. If it's outside acceptable range, a


microprocessor
sends
to screen signalto abuzzertosoundand a else
sing

5. Ifit's within
range, no action is taken.

whole continuous till off


6-
monitoring process is
engine
is
Monitoring intruders alarm
C) in a
burglar systems
activated password
1. system is
by typing a on a
keypad.
2. Data from sensors sentto
is
microprocessor:
-

·
Infrared sensor detects movement of intruder

Acoustic picks up sound of movement


sensor
·

·
Pressure sensor
picks weightof an intruder
up
entering.
3. Data is converted to digital using ADC.

data to stored values


1. Microprocessor compares this
5. If they're within action taken.
range, no is

If they'reoutsideacceptable rangeinto sound


6.

microprocessor

sound
7.
Flashing & continue till
system is
reset
using
a
password.
55. Main rule!.
from
Data sent sensors to microprocessor

Data converted to digital using ADC


*
Microprocessor compareswith stored values
↓ ↓
if within range, If outside range,
no action taken alarm buzzerletc.

Moni
till
tori n g continues
is shut let.
system
5) Control systems!
To consistof:

sensors
Microprocessor
actuators


Advantages of control systems to humans:

control systems more


accurately
respond to
changes more quickly
don'tneed breaks

are not paid


work in
dangerous conditions

A) Regulating temp. in air


conditioning system:
1. Temp, sensor sends data to
microprocessor
2. Data is converted to digital using ADC.

3.
Microprocessor compares data with
presetvalues.
1.If than pre-setvalue,
higher microprocessor sends
signal to actuator to turn on
cooling unit.

sends
ssIlowerthanalpreset value,microprocesstheir
street
3) controlling lighting: -

1.
Lightsensor
constantly sends data to
microprocessor
2. Data is converted to
digital using ADC

stored value
3.
Microprocessor compares lightdata with

1 if value is less than stored value, microprocessor


sends to actuator
a
signal
street lamp.
an toswitch on the

streetlamp remains on for a


period of time.
5. If value is greater than
sensor
stored value, microprocessor sends
or equal to
actuator to turn off street rampsignalson.
6 The whole
process is a continuous Loop
C) Anti-lock
braking system in cars (ABS):
a
system thatuses magnetic field sensor to avoid
wheels
locking up onthe car of brakes are
applied
too
sharply.
3. Magnetic field sensor
constantly sends data to microprocessor.
2. Data is converted to
digital using
ADC.

3.
Microprocessorchecks
rotation speed of thethemore

↑ 58 one wheel is
microprocessor sends
rotating slower than others,
braking system
a
signal that to the
toreduce the pressure
match other wheels
so
speed increases to

wheel is faster than others,


5.58 one

microprocessor sends
rotating
1
signa to
the
brakingdecreas
thatspeed system
toincreasethepressure
so one

6-whole process repeated till


is breaks are released
16. Main rule!.
from
Data sent sensors to microprocessor

Data converted to digital using ADC


*
Microprocessor compareswith stored values

if within range, range,
58 outside
no action taken action taken

Moni
till
tori n g continues
is shut let.
system
Chapter 1

OutputDevices
Is Liquid Crystal Display (CD) screens:

Principle of operation:
1
Display consists of
pixels thatare arranged in a matrix

Apixel consists of red, green & blue Liquid crystals


2.
Backlightis shone through liquid crystals with 6272s

ALiquid
crystalcanbetransparentoopaquepersed
3.
r
changing
to them.

↑shades of colour achieved red,


can be
by mixing
green and blue

Advantages compared to older monitors and LED:


1. Lower
power consumption
20 runs ata cool temperature
3 No burn
image
-

1.
Higher resolution
image
is
produced
scheaper to
purchase than LED
screen.


Light-emitting diode (LED) screens:

Principle of operations
1. Ascreen consists of pixels arranged in a matrix.
2. Each pixel consists of 3 LEDs (red, green & blue)
3 shades achieved
and
of colour
blue.
are
by mixing red, green
of
Advantages LED over LCD & ((f):

3- LED technology reaches maximum


brightness
almost immediately.
2.
Brighter light is
produced so colour definito one

3. Monitors are thinner.


4. Less
power consumption, so less heat produced.
3. More reliable as LEDs are
long lasting
( can be back itor
edge-lit.)
⑤ Digital lightprojector (DLP):
Principle of operation:
laid
1. A
large number of micromirrors is on a
grid.
2. Each mirror
towards or
represents pixel.
from the
a Itcan tilt
away light source

3. A
brightand
wheel light
then
is shone
falls on
through
the DIP
colour
a

chip
4 The ON and states
Off of the mirrors are
linked to the coloured wheel to produce
coloured
images.
Advantages over LCD
projectors: -

1. Better colour production.


2. Fewer internal components so more portable.
ICD
&
projector:
Principle of operations
white light
1. A produced by
is a bull in the projector
body.
chromatic coated
2 The
mirrors.
lightbeam passes through
3 These reflectlightatdifferentwavelengths to
produce red, blue and green light,
4The three
lightcomponents
red,
pass through
& blue versions of
LCD
the
screens
to
produce green image
5 The three then combined using
images are a

full
special prism to
produce a colour image.
one
6.Theimage passes through a
projector lens of

Advantages of projectors
LCD over DLP:

1
Higher resolution
2 -

Brighter image
3- costof purchase is less

% Less less heatproduced


power
so

3- Run quieter
6.
Longer-lasting lamps.
⑤ Printers -

Preparation of printing: thatcontrols


Program
-

& device
7. Data from document is sentto printer driver.
2 -
Driver ensures data is in a suitable formatfor
the printer
driver checks the printer is available for
3. The
printing
4 Data is sent to
printer and stored in printer
buffer
Temporary memory denrice <-
⑥ Inkjetprinter:
Principle of operations
1. Rollers move a
paper through the printer.
2. Nozzles on
printhead more from side to side ejecting
ink
using
either thermal bubble or
piezoelectric technology

eachfull passofthe print headsthepapersand


3. After
advanced
printed.
This continues till a whole page is

Thermal bubble:Enk is heated and expands into a bubble


The bubble is pushed through the nozzle on

to the paper
Be bubble collapses
piezoelectrici
whielectricalcurrentis applied to a
crytale
vibration forces ink droplets to be ejected
on
paper

⑦ Laser printer:
Principle of operation:
drum
1. A
rotating printing is
given a
positive charge
2. A laser is scanned across the drum to remove the
positive charge in textareas

3. The drum is

to stick
then coated with
to textareas.
positively charged tower

ToAnegatively charged
sheeto f is rolled one
paper overthe

5. The toner sticks to the sheetof


paper

fuser
theisone
6.
The papergoesthrougha
melts
that
all the from
7. A
discharge lampit removes
charge
the drum
making ready to print again.
8 Laser US Inkjet:
Laser Inkjet
Printer Printer

1. better black & white 1.


Higher quality of coloured output
2. Faster 2.
Cheaper to buy than laser printer
3.
Larger paper trays 3. No warm
up
time

9. can
print both sides
on 8. Can use
larger paper sizes

3.
Toners cheaper peroare
5. Smaller
footprint

·3D printer:
Definitions down of objecttoone
· breaking
an

layers
thatuses
produce solid
Device
tomography to 3D objects
powdered one
these arebuilt layer by layer using read

Principle of operation:
for objectis made aided
2.
design
A
design (CAD)
an
software.
using computer

converted into form understood


2 -
The
design 3D
is a
digital
by the printer.
thousands of this one
3 The object
horizontal lays
splitinto
1 The object builtlayer by layer starting from
the bottom
is removed and left to
5 -
The object
few
cure

for a hours,
Advantages of 3D
printers to conventional manufacture:
1 a
faster to
produce customized items

2 -

Designs
file.
can be
easily shared
by a
digital
3. costo f
and other
manufacturing
costs involved
less is
in
than labour costs
conventional manufacture
of conventional
Disadvantageare 3D printers to

to
1-3D printers are
expensive purchase
2:
Dangerous items (weapons) may be printed
3-printed items be less durable.
may
⑩ of each of printer:
Uses
type
Laser printer -
largenumber of high quality flyers &
posters for advertising.
Inkjetprinter Printing photographs
3D printer Prototypes
-

·
customized items prosthetic limbs
surgical equipment
parts for items longer
no

in production
⑪2D cutters:
Machines that manipulate materials in two dimensions
cuttersare
- Blade cutters
E water
jet cutters
# cutters:
3D

Principle of operation:
1. A for
design(CAD) an objectis made using
software
computer-aided
design
2.The design is then converted into a
digital form
understood the cutter.
3D
by
3. Material is loaded to the cutter

↑ 3D cutter uses laser to cutmaterial in x,y&2


axis.

⑬ Speakers & headphones: -

Principle of operations
1. the
computer sends outa digital signal which is converted
to an
analogue voltage using DAC in the sound card.
2. The voltage is then
amplified and fed into loudspeaker a

the
3. The
voltage changes make
sounds.
a come in
speaker
vibrate
producing
#Actuator:
Definition:
a mechanical outputdevice thatproduces movement
Itcan rotate, close, push pull object.
or an

Uses:

controlling robotarm
fan
spinning a
water
pumping
Chapter 5
devices
storage
① Primary memory;
accessedmemoryinside the
Main computer that's directare

RAM;
·Random
Access Memory
used
and one
-
to store
dataprograms pat
operating system
-
volatile
·

can be read from & written to

volatile:
datalost fromthememory seen
the

ROM:
Read. Only
Memory
-

·
stoves start-up instructions

eg.
Basic Input/outputSystem (B505)
-

Non-volatile
-
can
only be read from notwritten to

&
RAM ROM
volatile Non-volatile
Read write Read only
stores stores programs for startup
currentlyprograms
in
use

few bytes several GBs much smaller


capacity
② Primary memory secondary storage
directly accessed Notdirectly accessed
by CPU
by CPU

faster access
speed slower access
speed
Greater
storage
stores boot-up instructions stores files & software
&
programs in use
can be volatile or Nonovolatile
non-volatile
·Non-volatile memory rootdirectly
accessed
by cpu
Secondary storage:(magnetic)
-

They read and write


heads. using electromagnetic read/write

These heads control magnetic dots.

Magnetic dots representbinary.


-

Hard Disk Drive (HDD):


consists of:

1. Platters:disks where
magnetic dots are stored.

2. Tracks & sectors:divisions in


platters
3.
Spindle;platters are attached to itto rotate
4
Elactromagnetic read/write heads
How data is read:
1 Data, in form of magnetic dots, is stored on
platters
in sectors &tracks.

areattached spindle to spansee


platters
2- to

3.
Electromagnetic read/write heads more back
and forth at high speed to access all
sectors and tracks.
read under
↑ Data is
magneticdots
as

electromagnetic read/write
pass
How data is written:

1. Data, in form of magnetic dots, is stored on surface


of platters in sectors and tracks.

2- platters attached
are to
spindle that spins
them high speeds.
at

3 Number of electromagnetic read/write heads


and forth all
move
quickly
sectors and
back
tracks
to access


Electromagnetic
magnetic readoriteheads applysuitableone
secondary storage: (solid-States
of
Data is storedby controlling the movement
-

electrons within NAND chips.

They use flash memory to


·
store data
solid-state drive (SSD): -

·
Non-volatile
·
Flashmemory is used to store data.
NAND/NOR used which made
chips are
-

are
of transistors
How data is stored
1. NAND chips, made of transistors, are used
2. flow of electrons is controlled by transistors
inside NAND chips.

3. Data is stored by flashing it onto NAND chips.


1 Data is stored as Os & isin the transistors.
Now data is read:
* NAND chips, which are made of transistors, are

used.
2. flow of electrons is controlled by transistors
inside NAND chips.

3. Data is stored by flashing it onto NAND chips.


↑- Data is stored as Os &Is in the
transistors.

5 Data is
values read1forsretrieving the binar
one

HDD SSD

cheaper per unit memory

for read write


higher longevity
operations faster data access
speed
dualene
Nomovingpartssomore
less power consumption
run at
much cooler temperature
occupy less physical space

lighter: more suitable for portable


computers
quieter
↓ Noniroltiered from computer
offlmainlyforbackleor Coptical)
data:
recording
1. The disk is
spun
2. Alaser beam is used to make indentations
called pits-

3. The raised areas between the pits are called


lands.
4 Both
pits and lands representthe values
0 and 1.

reading data;
1 Data
on the
is
represented
surface.
using pits and lands
2. The disk is
spun.
3. laser beam
A is shone onto the surface of
the disk.

4 Pits reflect lightdifferently to lands.


5. The optical device can determine the
binary value from light reflection.

Compactdisk (CD): -

uses red laser to read & write


·

single spiral track runs from centre to edge


->
can
only single polycarbonate
use a
layer
Digital versatile Disk (DVD): -

uses red laser with shorter wavelength than CD's


red laser to write & read data
·

single spiral disk


dual
single or
layer
-

higher storage capacity than CDs


- faster data transfer rate than CDs
Blu-Ray disk:

uses a blue laser to write and read data


fastestdata transfer rate among other opticaledia
higheststorage capacity (compared to optical)
be
can
single or dual layer
formats of CDs, DVDs & Bluray disress

ROM:Data stored is already burned onto the disk


by the user orthe manufacturer

ONLY read
R i Write ONCE
only
RW:Read & write repeatedly
DUD-RAN: -

They use a number of concentric tracks

simultaneous read & write


operations
·
Greatread write
longevity - perfectfor archiving
offline storage: solid-State
Removable SSD:

Backup device OR
a
way
of transferring files between computers
USB flash memory A
Pen drive
Memory stick:
connects to a
computer through USB port
small &
lightweight transfer files
-

secure disks (SD)/extreme disks (xD) cards:

same
technology as
memory sticks

transfer photos from camera to computer


offline storage: Magnetic
Removable HDD:

Backup device OR

way
of transferring data

the
>Primary memory:main memoryCPUdirectly accessed

directly
not
·secondary storage:accessed
non-volatile memory
by CPU

be removed
>offline storage:non-volatile memory can

by computer
Chapter 7

Software AND Computer Architecture

① Types of
programming languages:
·

High-level languages:
closer to human
languages
-

Portable ->
can be used on differentplatforms
·

One line of high-level code can perform many


lowlevel operations
Low-level
languages:
·

·
closer computer language
to
·

portable specific to
not - the
computer
Eg.
-
machine
Assembly code
language executed
·

Binary that's
codes
·
uses mnemonic
to create
directly
programs
·
need to be translated
to machine code

Low-level
·

High-level US.

1 -
closer to
· Easier
language
human
& quicker to modify
10 code
Locations
works
directly on
memory

·Easier & quicker to debug


less likely to make errors 2-executed faster than same

Code portable code


2.
·
used
is
on different platforms
in
high level
learn
single language 3-
requires less than
code in memory
·
a

3-Code
4 =
built-in
is more
functions that
compact
save time
same
high-level
translators:
&
Language
Programs thatconvert code to
machine code be executed language
programming the
computer
to
by
A)
Compiler:
highterel -> machine code
&source code is translated all atonce
2. An error
reportis produced the
at end of the
translation.

3. Aftercorrecting the errors, the code is retranslated


1. An executable file is then produced that
runs withoutthe compiler.
B) Interpreter:
high-level Machine code
- >

1 source code is translated line by line

2-Codeis executed line


by line

found and
3.
Interpreter when
stopsafter an error is
fixed.
continues only the error is

2) Assembler;

low level ->


Machine code

1 source code in translated all atonce.

2. the
At end of the translation, an error
report
is
produced.
3. After correcting the errors, code is retranslated
4. An executable
the assembler
file is produced that runs without
Compiler Interpreter

1. code runs withoutthe


compiler
2-
compiled
A executed
faster.
programis

3- source code can't be


accessed so itcan't be
stolen.

4. Executablefile is produced
whichcreates a smaller
file size.
I easier and
quicker to debug
because error displayed
is ason one

2- easier to
modify and develop
the code don't
because
changes to
require the code to be recompiled

Operating system:
thatallows
Program the user to communicate with
the computer hardware to perform many
basic tasks

Functions:
·

Managing interrupts
·
Provides an interface
·

Multitasking
Memory management process
·

Processor of blocks
assigning
managementsent
& Assigning
·

Hardware of memory 10
running
·

programs
times
to
processing
run
programs

Interrupts:
·

Signal sent from the software or a device that


informs the CPU that its attention is required

differentpriorities.
They have
·

Purpose:
Informs CPU thatits attention is required
Pauses the currentoperation until the interrupt is
serviced

the
by processor.
Allows vital tasks to be dealtwith
based on their priorities
immediately
enables
multi-tasking
Ego
A
key on the keyboard is pressed
Amouse button is clicked
device
A is connected/disconnected
Printer runs outo f ink
Role of interrupt:when paper has jammed in
printers
1. Printer generates an
interrupt.
2.
Interruptis given a priority
3. Interruptis queued

4.
Interrupt stops CPU
current task.
from processing the

5 CPU services the


the
interrupt by
that
generating
amessageon
screen
pageone
#
Von Neumann Architecture (AKAstored Program concept)
I Programs are stored on a
secondary storage
device.
2= Data& instructions are moved onto the
RAM and stored in it.
3. Instructions are fetched and executed
one after another.
CO (control unit) RAM
PC Address Content
MAR
CIR
Secondary
ALU
storage
I MDR

fatch-execute cycle:
1. PC contains the address of the memory location of
the nextinstructionto be fetched

2. The address is copied from the PC to the


MAR address bus.
using
3. Thecontento f the
memory
location with the
address in MAR is copied
on the MDR
1 The
a
instruction
data bus
in MDR is
copied to CR
using
5. The value of PC is incremented by 1 to point
to the next instruction to be fetched

②CPU interprets and decodes the instruction

7. COU executes the instruction:


·
sends a signal to differentcomputer components using
control buses
·
Results of
any arithmetic operations are stored in
the accumulator.
⑤ Components related to Von Neumann architecture
and fetch execute cycle:
1.
Secondary Storage:
stores all data & that be used
programs can

2. RAM

made of partitious. Each partition has an address


and contents.

stores data and instructions processed by the


COU

3. Immediate Access Store (AS)

memory that holds data before the CPU


and after loaded
being by the RAM.
4. Central
Processing Unit(CPU)
contains arithmetic & logic and control unit
unit

50 control unit
controls flow of data through CPU

controls interactions between different parts


of the CPU

Responsible for decoding instructions

6. Arithmetic and Logic Unit

carries out
arithmetic calculations
carries
logical operations
out
Holds
temporary values
during calculations
called accumulator
in a
register
7.
Registers:
small
store
memory
last
data and
locations in
instructions
the CPU that

Program Counter (PC):


Holds the address of the next instruction to
be fetched
CurrentInstruction Register (C5R):
Holds the instruction
current
during processing
Accumulator (ACC):
Holds data
currently used in calculation
in ALU

Memory Address Register (MAR):


Holds address of instruction to be fetched

Memory Data Register (MPR):


stores instructions in use from address in
MAR-

8. Buses:

Pathways startransportdata,addresses and conforme


signals
Address bus:
transports signals relating to addresses
Unidirectional
Data bus.

transports data between CPU, memory and 510 devices


Didirectional
Control bus:
and
transports signalsrelating
co-ordination tocontosee the
computer
Unidirectional / Bidirectional
chapter 8
Data Transmission

Data transmission:the transfer of data between two


devices or electronic components
Data transmission classified by 2 factors

is, *
Method Type
Serial
parallel simplex
Half-duplex
Duplex
① Method:
A) Serial:
Data is sent bitata time over a
single wire.

Advantages compared to parallel:

3
Less chance of interference
affect *

As singleneed
wires
* a
each other
and cheaper to install
change
values
reliable distances
More over
long
Data is received in order (less chance of data
being skewed)
-
because data is sent a bita t
time
swapping a

values ④

Disadvantages:
-

Slower data transmission rate

Applications:
Wif,
Universal Serial Bus (USB)
B) Parallel:
Data is sent as
multiple bits simultaneously over

multiple wires

Advantages compared to serial transmission:

Faster transmission rate

Disadvantages compared to serial transmission:

Data to be skewed due


is more
likely to
bits
being sent
simultaneously.
More chance of interference as multiple wires are

used
Move to install it multiple
wires.
expensive as
requires

Applications:
used in RAM

used in
Integrated Circuits/Buses (exceptUSB)

② Type I direction:

Simplex Data flows in a direction


only
sending data to a device from CPU

Receiving data from a device by CPU

Half-duplex Data flows in a directions not simultaneously


Telephone
allowed
calls where
only 1 person is
to speak
Duplex Data flows directions
in a
simultaneously
Regular telephone calls
Instant
messaging
⑤ USB:
stands for Universal Serial Bus

Data transmission method that uses serial transmission


to transfer data between computer and number
of devices,

A) steps after a device is


plugged in the USB:

8. Computer detects that a device is present.


2. Device is
automatically
device driver
recognized and
loaded.
the
appropriate is

3.58 the device is


new, the computer looks for
driver
an

to
appropriate
download one-
device asks
or the user

B) Advantages of
using USR:
Devices are detected and
automatically configured when
initially
attached.
Impossible to connectdevice incorrectly as
plug fits
one
way only.
faster transmission compared to wireless

Later versions are backward compatible with older


versions

Allows power to be drawn to


charge portable devices

6 Has become industry standard


Data is less
likely to be skewed compared to parallel
Less chance of interference
as ituses serial *
transmission
④ Integrated Circuit(5c)
used to transfer data between computer internal
components
uses parallel transmission

⑤ Error checking following data transmission:


After data is transmitted, the receiver has to check
thatdata is transmitted as is and no error

has occurred.
A) check:
Parity
An thatrelies
the
error
checking
number of
method
each of
on
counting
data
received and
IS in
byte
comparing
to
it an
agreed parity.
Parity can be even or odd
Stepsi
1. Aparity bitis added to each
byte of data
before transmission

2. This
of
bitis
15
assigned so thatthe total
odd (according
number
in the byte is even to
the
parity).
3 When data is received, the number of 15
counted and checked if it's even lodd
4. 58 the
parity is incorrect, an error is detected
conditions check ineffective:
when
parity is

1.
Transposition errors
(swapped bits)

2 -

several
parity.
bits
changed without affecting the

· It's impossible to know the location of


an error in
parity check.
Parity Block:

A
parity
data. byte is sent
along with the block of

The numberof IS is checked


horizontally and
vertically
the
againstan agreed parity to locate
error

is
Even
Now a
corrupted bit located:
**
parity column # has an odd
number of s
Row * has an odd number of 15
The intersection locates the incorrect bit.

several bits are incorrect ->


Impossible to locate
the error-
2) checksumi
Steps:
1. Avalue, called checksum, is calculated from the
block of data using an algorithm
2. The checksum is transmitted with the block
of data

3. The receiver recalculates the checksum from


the datablock received using the same

algorithm
4. The
original
calculated one.
checksum is compared with the

5. If they're different, an error is detected and


a is sentfor data to be sent
request
again
D) Automatic Repeatrequest (ARQ):
· An error control protocol
-
uses acknowledgementand timeout

Steps:
1.
Request is sentwith data, requiring
acknowledgement.
2- check is performed on databy the receiver
checksum.
by parity check or

3-No errors ④
Acknowledgementis sentto sender
thatdata is
correctly received
4. Error sent sender to
-
Request
is
resend data.
to

sent by
5.
Nothing
frame (timeout elapsed
within
is
receiver certain time

↳Data by the sender.


is
automatically resent

6 Datais the sender till


repeatedly by
resent
data is received FRQ limit
correctly or

is reached

Acknowledgement:Message
indicating sentbya receiveseed
correctly
Timeout;the time allowed to
elapse before
an
acknowledgementisto be received
Chapter I

[Part1] Internet
* I MAC Address:Media Access Control

Unique number thatidentifies a device connected to the


internet
-
Allocated by the manufacturer

Doesn't
change (static
·

61 12 B3 47
- -
-
- 25 -

FE

Manufacturer * serial number


IN
of the device

6 pairs of hexadecimal numbers

↑ JP address: - InternetProtocol
-

specifies the location of a device on the internet


·

Allocated by the jsp for an internet session

can be static

or
dynamic

No
change connect
each
Changes
connect
each time
the
time you you 10
to internet internet

192.308.158.]
4 denary numbers separated by dots
* B InternetService Provider:JSP
Company thatprovides a connection to access the internet
for a
monthly see
Role:

Access to the internet for a


monthly fee
monitors internetusage

Gives users an IP address

Determines bandwidth
Provides security services

Provides access to Email


Provides online data storage
Provides

queb-hosting facilities

④ Webpage.
Web documentwritten in HTML

⑤ Website i

Acollection of related webpages


# HyperTextMarkup Language: AOML

A markup used to create webpages


language
to formatcontent
uses
tags
consists of structure and presentation
structure:

layoutof the webpage -

defined using bugs]


the
Eg. placementof a
paragraph on
webpage
Presentations
of
Formatting webpage the
defined using tags) -

Eg. textcolour/fontstyle/image size


Similarities between structure & presentation:
Both defined
are
using lags
Both used to dictate the of
webpage
appearance
a
are

Web
⑦ server:

Computer that contains


webpages
It has an address
IP and domain
⑧ Domain Name Server: DNS

Aserver that stores URLs and their matching IP


addresses

* Uniform Resource Locator: URL

text-based unique address


for a resource located on the internet.
user-friendly version of IP address.
httpsipocie.org.uk exth

one
* sename
Protocol webserver name

https/http *
www Domain name Domain type country code
of oulous...
compong
name
website
...

* Protocol:
setof
is
rules
transferred
agreed
between
on
by
devices
the sender and recipientwhen dald

Hyper TextTransfer Protocol:http

Main protocol controlling transmission of data to from webserver


Hyper TextTransfer Protocol secure: https
uses an
encryption
SSL/FLS
It's
data
slower than
transferred
http, so
only used when sensitive
is

* ( Web browser:
thatallows
Program the user to view
webpages
functions:

sends URL of website to DNS to find its IP address

connects to webserver

translates HTML

manages SSL/TLS certificate process


stores cookies

identifies protocols
stores user's favourite websites

of websites visited
⑧ keeps a
history by the user

of website;
steps opening a

1 URL is
typed into a browser.

2 Web browser sends URL to DNS

3 DNS searches the URL to obtain IP address of webserver


4) IP address is sentback to browser

5 Web browser sends requestto webserver

6 Web server sends


webpage's HTML code back to
web browser

7. Web browser translates HTML to


display webpage.
-
f
·
--- to
not
N
&
⑧ oI E
n
/ecozore ⑦
* cookies:

Data stored in a textfile that's created and sent


webserver and stored user's computer
by web a

browser.
on a
by
a

Role:

stores user's
preferences to customize the experience

store
login details to
speed up login process
store details
payment
outtrangeted advertising
carry
store items thathave been added to online shopping cart
internet
save
surfing habits

7 store in online quizzes/games


progress
automatically
entering paymentdetails:
of
steps using cookies in

1. Webserver sends cookie file to user's browser

2 User's
2.le.
paymentdetails are stored in an
encrypted text

file stored the browser


3 cookie is
by on HDDISSD

↑ When user revisits website, webserver requests cookie


file

s web browser sends the cookie file back to server to


automatically enter the details.
of sensitive data:
Risks
using cookies with entering
cookies mightcollectdata thatuser doesn'tknow abouts o user

may
feel their
privacy is affected.
sensitive information in cookies
may
be intercepted during transmission

computer couldbe backed to obtain data in cookies leading to


paymentinformation being stolen

profile
A could be builtaboutthe user based on cookie data leading
to identify theft.
Chapter 9

[Part2] security
Risks affectdata
that

patatloss Data

Nelt

Accidental
lacking vires cracking
spy are
Hacking phitting harming
damage
Malware is
-
A
program
unauthorised
thatdamages, disrupts or
gains
access to
computer.
Now is itintroduced to network:
· Ahacker hacked the network and
uploaded the malware
·

clicking on email attachmentthatcontains malware


*

using infected software package causing malware


to be downloaded
infected storage device.
Using portable
·

·
Firewall is turned off, so malware was not detected
network.
entering the

·
Anti-malware is turned off,so malware was not
detected being downloaded.
# Data lossi
A) Accidental damage:
Accidental deleting overwriting data
·

Use back-up
·
Use password to allow access to authorised users

only
Hardware Failure
·
Use backup
·
Use UPS (Uninterrupted Power supply) to prevent
sudden cut hardware failure
power causing
Physical damage (fire/flood
·
Use backup
Power Surge
·
Use back up

protector
·
Use
surge
Software crashing
·
Use back-up
·
Save data on
regular basis in case software
crashes
B) Virusi

A that
Def
inition program
delete
replicates itself. It's designed to
malfunction
or
corruptfiles, cause computer to
or become unresponsive, fill the hard disk (RAM
and cause software errors.

Protection:
Scan Email links
Scen external devices connected to computer
Use firewall
use up-to-date anti-virus
Don't use software from unknown sources
Anti-virus software:

Detecting a virusi

1. Antivirus software compares files with database


of known viruses

2.
5tafileis infected,twooptions appear;deone

3. It quarantine is selected, antivirus attempts to


cleanse the infected file.
Features of antivirusi

constantly runs in
background
can run a scheduled scan

Notifies the user of a possible virus

can
quarantine the virus

can delete the virus

NBBackups don'tprotect
against viruses
attached itself backedup
since
files.
it
may have already to

2)
Hacking:
of
Def
inition
The process gaining illegal access to a
computer
system without the owner's permission.
Possible effects:
Misuse of personal information
Data deleted corrupted
Data changed
Data stolen/copied from the
system
Protection:
Firewall

Proxy server

strong passwords
Biometric devices

physical security
Two factor authentication

NB. of file doesn'tprevent


Encryption a
hacking
P)
Cracking:
peen code for malicious
Editing a
program's source
purpose

Protection:
Use strong passwords
Use
encryption
NB.
Hackingin depot harmen but
cracking
set
② Data Thefti
A) spyware: ABA:key-logging software

bes software thatrecords


key presses on user's keyboard
inition
Data is sent to the creator of the software.

Possible effects: -

Gives the creator access to all data entered by


keyboard, including sensitive data.
Protection:

Up-to-data anti-spyware +drop-down boxes

instead of
Pointing device / touch screen
typing
How is itused to obtain a
password -

1 link
A on an untrusted website can be clicked by
theuserresulting
in
downloading the
spyree

2 records
It all from the user's keyboard.
key presses
3 The recorded keypresses are to
sent the originator
Tey're and pattern used

analyzed common
the password.
a is
to
identify
B)
Hacking

P72
C)
Phishing:
The creator sends outa legitimate looking email
-

peon thatcontains a link to a take website designed


to obtain sensitive data.

Possible effects:
Creator data
can
getsensitive
Creditcard fraud
Protection: -

Use
spam filters
Don'tclick links from unknown sources

Never reveal personal details via email.


D) Pharming:
A malicious code is installed on user's ter
compl
Def
inition thatredirects the user to a take website
designed to obtain sensitive data

Possible effects:
The creator steals sensitive data
creditcard fraud
Protection:

check of the URL of website


spelling any
Check URL contains https or padlock sign
Use up-to-date anti-malware software
Denial of Service (DOS): -

Def sending large number of requests to a server


inition all at
the same time
to
prevent from to website
users
gaining access
server
and
will
fails as
be
a
unable
result.
to
respond to all requests

Possible effects:
from
Preventing
emails
users
accessing
websites
Online services

Protection:
Firewall to restricttraffic to & from server

Proxy server
Protection against
data risks

↓ & & * & #


Authentication firewall Proxy Security
Physical Methods Server Encryption
Protocols
Security
⑮) physical security:
Been Type security prevents
that physical access

computer
Examples.
Locks
CCTV cameras

security guards
② Authentication methods:
Techniques that data from
Def
inition trusted source
verify comes a

A) strong passwords:
in secret text by set users to verify users in a
computer
system.
Properties'
Mixture of
uppercase letters, lower case letters, numbers
and special symbols
B) Biometric Devices:
iii Devices that
rely on
unique physical features of humans
to identify a siser.

Eg. -
Fingerprint, Retina, face, Voice
2) Password v5 Biometric
texttyped by Measurements scanned by device
keyboard
Easier to back

can be shared Unique to


person
can be
forgotten
⑤ firewalls in

Dee Device/ software


sits between user's computer and network
and filters and
outgoing traffic
based
incomingcriteria
on
given
Tasks: -

Checks whether incoming


&
outgoing traffic he end

DoS Blocks traffic thatdoesn'tmeetthe criteria

and prevents
Hacking
Warns unauthorized access to the
system
virus
S May preventviruses being transmitted to the network

Blocks access to undesirable websites


all
Logs incoming & outgoing traffic
situations when firewalls are ineffective: -

Disabling firewall

Incorrect of firewall
configuration
How firewall blocks access to undesired websites: -

1 -

Undesired websites are listed as blocked by company


2 The firewall checks traffic leaving the network
3. If detects traffic
it
requesting blocked website, it blocks access

to access blocked websites


4. It keeps a
log of all attempts
How firewall blocks unauthorised access to network:

criteria for the traffic


1.
User/company sets

traffic
2 -

firewall checks
any entering the network

3. If the traffic doesn'tmeet the criteria, it's blocked.


to firewall warns the user of unau thorized access

3
undesiredonauthorise
*

one

Virusesare
computer
·

Personal

Firewall
Proxy Servers
#
Def server thatacts as an intermediate between PC
inition
and web server.

Fasks for webserver: -

Prevents direct access to the server

Filters internettraffic and directs invalid traffic


away
attacks
preventbacking and
Can help DOS on

the webserver

can block requests from certain JP addresses


Protectserver from malware malware
checker
using

Tasks for userS: -

the user's IP address secret which


keeping
improves security
can block access to website
has cache feature which access to data from websites

Encryption:
Def
process ofscramblingcharactersofamessagerest
inition

unauthorized users.

Steps:
used to scramble the dat
1. An
encryption algorithm is

2. The
original data is called the plain text

algorithmuses
red
encryptplaint
3. The to
40
key

4. The
key is transmitted separately from cypher
text

5.
Thekeytexts then usedtodecrytheone
of information required and
key: A
piece
to
encrypt
decrypta message
Cyphery:Output
of the
encryption algorithm
key length:
Longer key length
=

More possible combinations of


numbers

Harderfor a hacker to
force
guess the key (brute
attack)
A) Symmetric Encryption:

Atype encryption
of that some my
end
asin.
uses

key distribution problem key could be intercepted when


sender sends key to recipient
B) Asymmetric Encryptions
differentbegsneed
dtypeofencryption
uses
that

Uses two
keys:
Public:made available for
everyone
Private: the
Only known by user

⑥ Security protocolsi
A) Secure SocketLayer: (SSL)
is
security protocol uses
encryption to allow data to be
exchanged securely between two devices on internet

Steps:
1 Web browser
itself
requests web server to identify
2 Web sends web browser of
server
copy
a

its digital certificate

3 Browser authenticates the certificate


1) Authentic -> Browser sends a
message
back to
server to establish connection

S Data is
asymetrically encrypted
B) TransportLayer secure: (815)

bes
security protocol thatencrypts data over the
inition
internet,
Updated version of SSL.
Consists of 2 layers:Handshake & Record
Roles of handshake:
carries outauthentication of client & server

handles encryption algorithms & keys


Roles of record:
Handles transmission of data
Advantages over SSL:.

from the record


separates handshaking
boostoverall performance
uses session
caching to

possible
methods
to extend FLS by addingueauthentication
Session
existing instead of creating
i resuming an session

caching a new one.

steps:
itself
1 Browser requests server to
identify
sends its certificate browser
2 server
digital to

3 Browser authenticates the the digital certificate


& Authentic Browser -> sends a
requestto establish
a connection

5 session
caching can be used
6
Asymmetrical encryption is used for all data

Applications using FLS/SSL


Online (Banking, shopping, booking)
Email
Instant
messaging
Cloud based storage
Video conference

Extras: -

A) Use of 12 digitpassword
More
possible combinations
Password harder to crack
13) Inputrandom numbers from the PIN/password
More difficultfor backer to find order of the
characters

Hacker needs to hack the system several times


to obtain whole password
2) InputPSN/password
using drop-down boxes

preventspyware from obtaining password


D) number
set of password attempts
Lock the accountit hacker
attempts to guess
the password
7) for personal details as lastlogin date, phone
Asking amounto f balance in the account, etc...
number,
Harder for the backer to access the system
need information
they
as to know
personal
7) Two factor authentication:
Harder for hacker:adds extra level to back
method
code is to
sent a device presetby the
user

system requires the user to enter this code.

Method
3ys
Intern requires userto inputlogin decalsare
Chapter 10
Ethics ExtraS+

* Uses of hexadecimal: -

1- HTML color codes


White ->Affffff
Eg.
2- Error
messages
Eg. Notfound404
3MAC addresses
61 17 35 67-8) AB
Eg.
- -
-
-

7 ASCII codes
004]
Eg. A
-

5
memory dump
-Locations in
memory
code
8.
Assembly language & machine

&-
Debugging
(2) File formatsi
A) MP3:
of sound
stores
digital recordings
·

uses
lossy compression (compressed file formal
to reduce of the
uses
perceptual music
shaping size
-

file without
affecting the quality too much-
used sound
when
distributing files
·

Perceptual music
shaping:one process ofremovingsonsare
distinguish
B) MP1: -

-
file format used to store multimedia files (music,
videos, photos & animation)
Uses
lossy compression
-

dJPE6:
·
stores images
uses
lossy compression
·

Removes details from the to reduce its file


image
-

size

⑪) 25P:.
-
uses lossless compression
->

for almostany file type


E) M5DJ: Musical instrument digital interface
·

stores a of commands
set thatinstructdigital
instruments when to produce a particular sound
-

Doesn'tstore actual sounds


·

specifies data aboutnotes such as:

·
pitch of the note
·
When each note
plays and when itstops
·
Duration of the note
·
Volume of the note
Type of instrument used
·

·
can be
compressed using lossless compression.
- Used when composing music
⑤ Ethics is

They are seto f principles set out to regulate use


of computers.

They cover:
-

Intellectual property rights (eg. copying software


·

without permission
backing)
Privacy issues (eg. Hacking
·

Impactof computer society (eg. job loss


·

on

Their importance:
-

Use of computers needs to be governed


for
Provides
using computers
-
rules

Help stop plagiarism


Help keep users safer when computers.
using
·

Help stop cracking programs


-

Help stop sending malware to


damage other computer
systems.
plagiarism:The action
and
of stealing
it
another person's ideas/
work
claiming as
your own.

Copyright:Alaw to claim legal ownership thatrequires


permission to use other people's work.

Types of software licensesi-

1. Free Software: -

May include a cost

User has access to source code


·

subject to some
copyrightlaws
-

User is allowed to study & edit the code


They're also allowed to share and redistribute the
code-
-
If it's free to purchase, it's called open source.
55. Freeware:
-
Free of charge
-

User has no access to source code.

·Fully protected with copyrightlaws, which means:

legally study
can't or
modify code
·

Can'tshare or resell code


#I. Shareware: -

-
User is allowed a free trial period 1

and
they're charged after the period
-

User has no access to source code


-

fully protected with copyrightlaws, which means:

· Can'tlegally study or
modify code
·
Can'tshare or resell code
⑭ Automatic stock control;

steps:
1. ProductIP from scanned barcode is searched
in the database

2- stock level is subtracted by the quantity sold to


the customer.

3. The new stock level is checked if it's below


a certain level.

4. 5e it's below that level, the system


automatically recorders stock from the suppliers
5 The new stock level is updated in the database
5) check digit:·
digitcalculated from other entered digits
A
pop. and
then appended to the entered number.
It's used to check thatdata entered to the
system is correct.

Steps:
1 Datais inputwith the check digitappended
2. Acalculation is performed on the input data

3.
Theinput check digitis compared withthese

1 of match, data correct. Otherwise, it's incorrect.


they is
Programming
Reory
-
concepts
1 Proram
I
list
A of instructions thatdoes a
specific task

be high-level low-level
can written in or
language
2 Algorithm
Astep-by-step solution to a
given problem
3 Pseudocode
mathematical design
she program
words notations
uses to
the

4) Flowchart
of
·igam,haters ofto standardirection symbolsww-
to
design steps a
program.
5 constant
Anamed memory location thatstores a value that
execution of
doesn't
change during the a
program
6 variable
Anamed
memory
location thatstores a value that
the execution of
can
change during a
program

a sequential statements
statements
their
executed
order
one after another
according to
& Conditional selection statements

Selective statements executed depending on


meeting certain
criteria

Purpose:
allow differentpaths
certain criterial
through a
program depending on
meeting

9 IF.. THEN.. ELSE.. ENDI

Aconditional structure with differentoutcomes for true and


false
Purpose:
Allows for different conditions
checking
10 CASE OF. OTHERWISE.. ENDCASE

Aconditional structure that allows selection to be made


& based on a value of a variable

Purpose:
used to test for
large number of discrete values.

11 Iterative / Repetition statements

Oneormore statementsarerepeated till


testconditoone
a

Purpose is

to repeat same or similar code a number of times


which allows for shorter code
12 fOR.. T0.. NEXT

loop
A structure iterates
that a set number of times
13 WHILE..DO. ENDWHILE
-
A
loop that
true.
iterates whilsta specified condition is

Criteria is pretested
may
It never run.
-

14 REPEAT.. UNTIL
-

A loop that iterates until a condition is true.

-Criteria is post-tested
·

iliterates atleast once.

15 REPEAT. ONTL US WHILE..DO. ENDUHSLE


Criteria post-tested criteria pre-tested
Runs atleast once
May never run

Runs until a condition Runs while a condition


is true is true

16 Totalling
The process of list of numbers
summing a

Sum - Sum Num


+

17
Counting
· The list
process of
finding how
many
items are in a

Count -
Count +
1

18
Array
holds number of elementsto see
Datastructure that a

Purpose:
·

stove multiple values under the same identifier making


the code shorter
Allows simpler programming
·
Index:
Position of element
array
an in an

Dimensions

Number of indices required to access an element


in an
array
Code errors

Loop counters
Initial value of the counter
starting
->

Final Number of reptitions for the


loop
->

Required Numberthat's
->

put in the loop

Required =
Initial final

I
REPEAT WHILE
UNTFL DO
·
value is checked once incremented Value is checked after incrementation
* 19 1 20

=
+

You're allowed to reach the final


value 20 20-stop=

Onemoreloopwillbedoveseed
once incremented, the
loop ends Conce final is incremented,
* the loop goes once more
UNTL counter=[Final] *

tonmiregnolal owedto
see
WHILELoop problem

If the condition involves the


inputvariable, INPUT
mustbe carried out
*
Oncebefore Once at the
the loop end of the
loop

Eg.
Negative ends the
Program inputs age counts +
the 38
process
DECLAREAge. Count:INTEGER Count -
To initialise
INPUT
Age
->
The
variable
WHILEAge s = 0 DO

=18
Age
If THEN
count count 1
+

ENDIF
To repeat INPUT
input
->
Age
(mustbe ENDWHILE
the
at
and of the
loop)
Databases
databases)
⑤ Data types: (in
Number 12,4,12741 (contain numbers thatcan be put
in mathematical operations)
Currency = 12.45

Text
DOG, Ahmedwoel 4499
IFALSEand
Boolean TRUE YESINO
only
Dote 251501200712 mar 2008

② Database:
Astructured of data thatallows
collection
people to extractinformation in
way a

thatmeets their needs.


useful
Very in
preventing data problems:
stored data duplication
Data is
only once no
-

done
changes
data is
have
consistent.
to be
only once -

same data is used by everyone.


⑤ structure of the database:

)3
Field name
* Title given to each field

Record -
Fable;
A
row
containing
data about collection
# field
item
a
single of related
acolumnthatare
of information with records
I data
type


Afield that contains unique data
Primary
for each record and can'thave
key
duplicates.
Query by example:
*

In order to search the database, we use


queries
Query by example grid:
we enter the
name of the
field involved

·
in the search



We select
the table

whether
*
We
we
state sorting
We tick (ascending/descending)
the fields↓
wan
in
specific field
a

we

to show

we write the search


criteria

: "Leather's
<5
7 45
=

> 4
5
=
<5

Like"Save**
Like "Save **
Like "* sove"
⑤ Validation:

automatic of the
program that data
The
entered is sensible. checking a

Types of validation checks:

Presence

Type
Lookup

Range
Length
character

format

Uniqueness
check digit
J.
Type check:
checks thatthe data entered has the
data appropriate
type.
number nottext.
eg. Age should
be

for fields numbers (number &


works
containing currency)
7. Presence check:
checks thatany data has been entered

works for all fields


check:
II.
Lookup
checks that the value enteredis available in a set of items

Eg. In a "month" field, only months are accepted


check:
IV.
Range
checks
are
thatnumbers
accepted
within a
specific range

Exam marks should be between 0 & 100


eg. inclusive.

v.
Length check:

checks thatdata contains an exactnumber


of characters

2g.
A
password with
exactly 8 characters. If
more or less than 8, it's rejected
vs. Character check:
checks thata string of characters does not contain
invalid characters
any
eg. name wouldn't
A contain "y"

VII. Formatcheck:
checks that characters entered conform to
a
predefined pattern.
A
company with IDs thatstartwith MS
then 3 numbers would have the pattern
MSHA# OR Dates

check:
VII.
Uniqueness
entered in
duplicate values
makessureno
are

perfect
primary key fields
for
5X. Check Digit:
A
digitcalculated from all other digits and
then appended to a number.

checks whether data is correct when entered


to a
system
Steps:
1. Data is
input with the check digit.
2. calculation
A is formed on the
inputdata
3 Thecalculated digit is
compared to the
check digit.
4. 59 they match, data entered is correct
58 don'tmatch, data entered
5.
they
incorrect.
is

Primary key Format Uniqueness length (if uniform length)


character

Price Currency) Range Type


format
Date
Type Range
Typelsizel location Look up

IDDPredefi
valuesned
1

Quantity
Number
Type Range

# Presence
⑥ Verification:
-checking thatdata did notchange during the
input
to computer or transfer between computer S

Ensures the of transcription.


accuracy
·

Methods include:
·
Screen / visual

Double
entry
·

Screen/visual check

Data is compared visually with the source

If they don'tmatch, data is recentered


Double data entry:
Data is entered twice.

Computer checks both entries are equal.


Extras

Top Down
-

design
The
breaking down of computer system to a

subsystems that broken to further subsystems


are

until each
subsystem performs single action a

Example : -

structure chart : -

Diagram that
hierarchal
shows the design of
with each
a
computer system
level
in
detailed
a
wayof giving a more

breakdown the
system .

Library Routine : -

List of instructions that is


programming

←•
ftp.re-tested

Already
given a

name available for use

Advantages : -

and faster code


Make
writing easier is
-

programs as
already written
-
Make testing program easier as it's already tested and
debugged
subroutine is

Subprogram
used used
to
perform a
frequently operation in a
program
Given a name called when needed
can be reused in another program or another programmer
written in
high-level language
Function;
Asubroutine thatalways returns a value

Procedure:
Asubroutine that never returns a value

testing data:
see
Dataused tocheckthat acomputer
reson

Types of testdata:

Normal data correctdata Months


- 1 =
12
should be accepted
Abnormal data Data outside limits Months ->
Negative
of acceptability/ >12

wrong,typeare accepted
Letters
Decimals

Extreme data Data atthe limits Months -> 1 & 12


should be accepted
Boundary rejectedin Rejected data
boundaries
on Months ->
0 & 13
the
Task 2 in that colour

Pre-release Materials

Ary6 -
Booking Names (1:280]
-
BookingDay (3:280]
Parking Space (1:34)
start
BookingSpace(1:280]
BookingLisence Nums(1:280)
ParkingEndSpace (1:37)
Variables
S - B
statistics

Booking count CountAccessible Day


·

Continue
IsAccessible Day CountGeneralDay
count
AllDay
CountAccessibleWhole
Count GeneralWhole
countAllWhole
UserChoice
Algorithm initialise ParkingstartSpace, Parking EndSpace,
Booking Count
*
Ask what day Day
Ask accessible not is Accessible
As <-
- *
validate Validate
Day 14, Day21, startspace andspace, Day 14, Day21, startspace andspace,

Endspace (Day]<6
Assign the end space of
next Assign the nextstartspace
that
day to
that the
space day to BookingspaceBooking
of thatcount count]

DetrementEndSpace Incrementstartspace
-
Assign Day to
BookingDay BookingCount]
*
OutputDay and space of this count
*
Ask for Name Booking Names
Ask forlicense number Booking Licensedums
*
Ask to continue or not continue

continue:"N"or"n"
the
stop if
loop or
BookingCount 280
=

↓ -1
intialise Parkingstartspace, Parkingandspace"
count
↓ Booking 30

Numsy-"
"

Intialise Booking Names


Booking License

BOOKingDaY0
BookingCount ->
0
Statistics Algorithm

desired day
Ask for

validate
Day 16, Day > 1

*
Initialise Count Accessible Day
O
CountGeneral Day
=

*
For I to
booking count
if Booking Day:Booking Count
if
BookingSpace c 5
=

Count Accessible Day +]


else (Bookingspace>S)
CountGeneral
Day +]

*
CountAll
Day -
Count Accessible
Day CountGeneral Day
*
Output CountAccessibleDay, CountGeneral Day,
Count All Day
*
intialise CountAccessiblewhole 0
General whole
=

Count
*
For 1 to Booking Count
if
BookingSpacesthewhole 1
Else
CountGeneralwhole 1
*
Count Allwhole & CountAccessible whole CountGeneralwhole

OutputCountAccessiblewhole, CountGeneralwholes
Count All whole
Pseudocode
DECLARE
Parkingstartspace (1.377, Parking Endspace [1:14):NTEGER
DECLARE
Bookingspace (.280], BookingDay 11:280]:SNTEGER
Booking Names 1:280], Booking LicenseNums (1:280]:STRING
DECLARE

DECLARE Day, BookingCount:INTEGER


IsAccessible, Continue;char
DECLARE

DECLARGCount AccessibleDay, Count GeneralDay, Count AllDay:INTEGER

DECLARECountAccessibleWhole, CountGeneralWholes Count Allwhole:INTEGER


DECLARE UserChoice:SNTEGER
F0Rik - 17014

Parkingstartspacein
NEXT

Booking Count &

REPEAT
Booking Count BookingCount
OUTPOT "Whatday would you
like to book in (7-14?"
INPUT
Day
OUTPUT "Would accessible
you like
parking space?(IN)"
INPUT IS Accessible

IfIs Accessible "x OR JsAccessible: "y"


-> THEN

Day <1
WHILE OR
Day>1 OR

ParkingstartSpace [Day] Parking Endspace [Day]


c Do

OUTPUT "Invalid day. Try again"


INPUT
Day
ENDWHTLZ
Booking Space (Booking County Parkingstartspace [Day]
ParkingstartSpace(Day] <Parkingstartspace(ay] 1
+

ELSE
WHILEDay<] or
Day >I4OR

ParkingstartSpace Day Parking EndSpace [Day] oR

Parking End Space(Day] <6 DO


output "Invalid day. Try another"
INPUT
Day
ENDWHILE

Space Booking County ParkingEndSpace [Day)


Parking EndspaceDayBooking
->
Parkingadspace
[Day] 1
-
Parking startspace
[Day] <

Parking Startspace(Day] + 1

INDIF

BookingDay(BookingCount] Day <

OUTPUT"You booked day", BookingDay Booking count]


on

outPUT "your allocated space is", Bookingspace BookingCount]


OUTPUT
"Enter your name
"

SNPUT BookingNames(Booking Count]


OUTPUT "Enter your license number"

SAPUT
Booking License Nums (BookingCount]
OUTPUT "Would you like to make another booking?"
INPUT Continue

UNTIL Continue "n" OR


= continue:"N" or
Booking Count = 280

OUTPUT "Enter the


day would like to statistics
for "
you view

INPUTUser Choice

WAS UserChoice <1 OR User Choice > 64 DO

OUTPUT "Invalid day. Try again"


SNDUT User Choice
ENDWHTLE
Count AccessibleDay &
Count General Day =0
For i <-1 0
BookingCount
5F
BookingDay(i) UserChoice THEN:

If
BookingSpace [] =5 THEN
CountAccessibleDay Count Accessible
Day 1
-

ELSE
CountGeneral
Day & Count General
Day
ENDIF

ENDI

NEXT

CountAIIDay Accessible CountGeneral Day


& Count
Day &

OUTPUT "Number of accessible spaces booked on


day",
Userchoice," " Count Accessible Day
=

output" Number of general spaces booked on


day", Userchoice,
General
Count Day
11 =
"

OUTPUT "Number of spaces booked on


day", UserChoice," =",
CountAII
Day
Count Accessiblewhole 20
countGeneral whole a -

FOR i <1 T0
Booking Count
57
BookingSpace[i] < 5 THEN
=

Count Accessible whole - Count AccessibleWhole 1 +

ELSE
countGeneral whole a CountGeneral whole +1
ENDIF
AccessibleWhole Count Accessible whole +1
NEXT
-> Count
OUTPUT "Number of accessible spaces booked in whole itday period
Accessible whole
Count
outPUT
"Numberofgeneral spaces booked in whole stday period,the
OUTPUT "Number of spaces booked in whole 5-day period:",
Count Allwhole
FORi <1 To
BookingCount
BookingNames [i]
<""

Booking LicenseNums()""
Booking Space O
BookingDay O
NEXT

Booking Count <--

70R i81405

ParkingstartSpace [i] <- 1

Parking End Space[i] -20


NEXT
Programming
Exercises
0.50 [sutro to programming book
1. DECLAREnumb, numb, product:REAL
OUTPUT "Enter firstnumber"
INPUT numb

OUTPUT "Enter second number"


INPUF num2

product num] nume


*
-

OUTPUT "Productis ",


product/
start

OUAPnumber"
&

noretum,
and
-put
nunz
producta numb

&
OUTPU
"Productis "product

& END
2. DECLARCside, area: REAL

OUTPUT"Enter length of the side'


INPUF side
side side

area
<-
area

OUTPUT
"Area is
if

Start

·UFOUength of side.
"

SU / -

area <-
sideide
*

w
OUTOF
"Area is "
area


3. DECLAREside, perimeter:REAL
OUTPUT "Enter the
length of the side "
INPU side
perimeter <- side *
OUTPUT"Perimeter is ", perimete/
Start

&perPlength
an

↑po
-
·
se
↑perimeter *↑

*
OUPUF

pe
"Perimeter is " under



4. DECLAREnumb, num2, division:REAL
OUTPUT "Enter firstnumber"

INPUT numb
OUTPUT "Enter second number"
JNPUR numb
division a numb

vision
<- nem]

OZAPOT The resultof their divisionis

start

*
-
OOTPUF
"Enter first number"

-
#
INPUF
numb

#
OUTPUT
"Enter second number"
*
INPUF
num2

*
division numb/numz
-

#
Fe, result
on
OUTPVA
on

*
⑫d
5. DECLAREnumb, numb, numb, product, sum, average
REAL

numbers"
OUTPUT Enter a

INPUT numb, num2, numb


product
a hums numb numb,
in
simc nums numb
-

average
c -

sum/3
"Productis", product,
and
OUTPUT is "
average
average

Start

OUTPUT "Enter 3 numbers

>


numb, nums, nums /

product -
numsnum2*nums
*
sum <-
numb numb numb

average - sum/3
#
product,"and average
-potproduct
I

is
and


6.
DECLARE num1, num2, num3, num4, num5, sum, average : REAL
OUTPUT "Enter 5 numbers"
INPUT num1, num2, num3, num4, num5


sum <- num1 + num2 + num3 + num4 + num5
average <- sum/5
OUTPUT “Average = “, average

Start
pbOZbers"

↑po numy, name, namb, numb, numπ

·
Sum <- num+num2+num3+
numttnums

#
Average sumk
<-


OUTPUT

"Average "average
=


#

7.
DECLARE pi, radius, area : REAL
pi <- 22/7
OUTPUT “Enter the radius”
INPUT radius
area <- pi * radius * radius
OUTPUT “Area is “, area
-
Start

pix 22/7


OUTPU "Enter the
radius"

INPUF radius

radius radius
*
*
area <-
pi

/OUTPUT"area=", area
/
d
and
8. DECLARE length, width, height, volume : REAL
OUTPUT “Enter the dimensions of the pool” (in order)
INPUT length, width, height any
volume <- length*width*height
OUTPUT “The volume of the pool is “, volume

Start

OUTPUT
"Enter dimensions of the pool in
any
order"

INPUT
length, width, depth

volume a
length widthdepth

volume
outPUT"volume:
9.
DECLARE length, width, height, volume, price: REAL
OUTPUT “Enter the dimensions of the pool in cm”
INPUT length, width, height
volume <- length*width*height

/
price <- volume/100
OUTPUT “The price of the pool is “, price

start


OUTPUT "Enter the pool dimensions "


INPUT length, width, depth

volume
length widthdepth
*
to


price
volume/300
output of the pool:",price

"Pie
10.
DECLARE cmHeight, inHeight, sWeight, kgWeight: REAL
OUTPUT “Enter the height in inches”
INPUT inHeight
OUTPUT “Enter the weight in stones”
INPUT sWeight
cmHeight <- inHeight * 2.54
kgWeight <- sWeight * 6.364


OUTPUT “The height in cm = “, cmHeight, “ and the weight in kg = “, kgWeight

start


OUTPUT "Enter height
in inchest

INPUT inHeight

OUTPUT "Enter weightin stones"


INPUT sWeight

emHeight inHeight
2.54
-
kg Weight
6.364
sWeight
*
<-

OUTPUT"The

a
andthe

heightin
weight
cm="

amite
here,
iny,
11.
DECLARE sMark, eMark, percent : REAL
OUTPUT “Enter your mark”
INPUT sMark
OUTPUT “Enter the exam full mark”
INPUT eMark
percent <- (sMark/eMark) * 100
outpUT
"Percentage:", percent
·t

OUTPVY "Enter your mark"


INPUTsMark

OUTPUT "Enter exam full mark"



INPUT eMark

percent<- (sMarkleMark)

percentage:
"paid
OUTPUF


12.
DECLARE pi, radius, diameter, circumference, area : REAL
pi <- 22/7
OUTPUT “Enter the radius of the circle “
INPUT radius
diameter <- radius * 2
circumference <- 2 * pi * radius
area <- pi * radius * radius
OUTPUT “Diameter = “, diameter
OUTPUT “circumference = “, circumference
OUTPUT “area = “, area

Start


pi<22/7


OUTPUT "Enter the radius"

INPUT radius

diameterradius 2

circumference z-2*pi*radius

area <-
pi* radius*radius

OUTPUT "diameter:", diameter

OUTPUT "Circumference:" circumference

/ OUTPUT "Area- ", /
area


End
13.
DECLARE hours, minutes, seconds, sHours, sMinutes, total : REAL
OUTPUT “Enter hours, minutes and seconds”
INPUT hours, minutes, seconds
sHours <- hours * 3600
sMinutes <- minutes * 60
total <- seconds + sHours + sMinutes OR
OUTPUT “Total duration in seconds is “, total
total <-seconds +
131600 hours)
x +

160 minutes)
*

Start

OUTP O I
"Enter hours, minutes and seconds
"


INPUT hours, minutes, seconds

stours <-
3600 hours

sminutes 60 minutes
total<- Hours - Minutes seconds
+

/ if
orPUT"Total duration in seconds
11

total



conditional
Programming [ P16
5 in books
*

numb, num2: REAL


DECLARE

OUTPUT"Enter 2 numbers
"

INPUT num], num2


57 num]> num2 FHEN

OUTPUT number is", numb


"Bigger
ELSE

2
ENDIF
OuPUN"
Bigger
numberis
numb
DECLARGheight:REAL

OUTPUT "Enter height"


JUPUTheight

THEN
height
55 == 175

OUTPUT "Tall"

ELSE

ENDSF
OUTPUT
"short" INTEGER
3 h
REAL
-
DECLARE scored, scored, as :

output "Enter the two scores"

INPUT scored, score?


<-
(scores score 2) /2
avg
It
avg
>= 50 THEN

E15E
outpUT
OUTPUT
"passed"
"Failed" END5S

DECLAREside, area: REAL

OUTPUT "Enter the side


length of the
square
"

INPUT side
Ifside < 0 THEN
OUTPUT "Invalid side length"
ELSE
area <- side *
side

5
ENDIF OUTPUT The area =", area

DECLAREradius, circumference, pi:REAL

pic -

22/7

OUTPUT "Enter the radius" #


INPUF radius
Ifradius GO THEN
OUTPUT "Invalid length"
ELSE
circumference z-2*pi*radius
OUTPUT "Circumference:" circumference
ENDIF
6

DECLARE
age:INTEGER
DECLARS name: STRING

OUTPUT "Enter the age"


INPUT age
"Enter the
"

OUTPUT name

INPUT name

If <0 THEN
age
OUTPUT"Invalid
age"
ELSE
OUTPUT "Hello!My name
is", name

years old
"

OUTPUT "I'm", age,


"

ENDI

7

DECLARE
num, square:REAL

OUTPUT "Enter a number"


-
1
INPUT num

IF
numc = 0 THEN
OUTPUT "Math error"

ELSE

Square
<-
sprt (num)
[C
OUTPUT square Square root is "...
ENDSF
conditional I [P22 Book]
programming in

DECLAREnum:REAL
OUTPUT "Enter number"

INPUT num

IFnum =0 THEN

OUTPUT
"negative"
ELSE

IFnum>0 THEN

OUTPUT"positive"


ELSE
OUTPUT "zero"
ENDIF
ENDS F
2

DECLAREnumb, num2:REAL
"

OUTPUT "Enter 2 numbers

INPUT numb, num2

IFnum]= num2 THEN

OUTPUT"Equal"
ELSE
IFnum] > num2 THEN

OUTPUT "Greater number is", numb


ELSE
OUTPUT"Greater number is ", numb

w
ENDIF

ENDIF
3.

Done on website
4.

Done on website

5. Done on website
6. Pseudocode: -

DECLARE
dayNumber:INTEGER
number"
OUTPUT "Enter
day
INPUT day Number
IfdayNumber 1 or dayNumber 27
THEN

OUTPUT "Invalid"
ELSE

dayNumber =1 THEN
If

OUTPUT
"Sunday"
ELSE
If dayNumber = 2 THEN

OUTPUT "Monday"
ELSE

If dayNumber 3
=
THEN

OUTPUT
"Tuesday"
ELSE
IfdayNumber =4 THEN

OUTPUT "Wednesday
ELSE
If daylumber =

5 THEN
-

1
OUTPUT
"Thursday"
ELSE
IF
dayNumber 6 = THEN

OUTPUT "Friday"

ELSE
7 END5.)
x OUTPUT "Saturday"
ENDIF
ENDIF
ENDIF

i. ENDIENDSF
flowchart
start

OUTPUT "Enter a
day number"

JNPUT
dayNumber
↓ &

35

NO
day Numbers 7 Yes
/output "Invalid"
v
ORy Number c =
0
Is 7
daynumber yes
! > OUTPUT "Sunday" s

NO

Js
yes
dayNumber OUTPUT "Monday" >
2 =

?
NO

OUTPUT "Tuesday" >


# a

55 NO 36 yes
day number L dayNumber
h =4
iS NO S
=

dayNumer
G
Yes... opUday
-

Yes " >

NO

I OUTPUT"Thursday" >
j5
dayNumber I
Yes
> outPUT "Friday"
= 6 7

NO

OUTPUT "Saturday" / S

N
a
7,8
num:REAL
DECLARE

OUTPUT"Enter a number"

INPUT num

Ifnum >30 AND num =50 ↑HEN

OUTPUT "correctrange"
E-L8Z
5=
Ifnum $50 THEN

outPOF"above
range"
ELSE
-

2
OUTPUT"Below range"
ENDI

ENDIF

9. Same as (2)
10 DECLARE num: INTEGER
OUTPUT"Enter a
binary digit"
INPOT num

If
num 0
=

THEN

OUTPUT "Off"
ELSE
num 1
IF =
THEN

OUTPUT "ON"
ELSE

OUTPUT "Invalid"

ENDIF
ENDIF
n
11 Done on website
Pseudocode
12,13 DECLARES6, S2,53:ANTEGER

arg:RAAL
DECLARE
outPHT "Enter 3 salaries"

INPUTs6,S2,s3

avg
< -

(51 s2 15B/3
+ +

THEN
If
avg<OOR arg >50000
"Invalid"
OUTPUT

ELSE
If > 30000 THEN
avg
OUTPUT "Rich"

ELSE5Jaug T = 2000 c10000 THEN


AND =

"Moderate
OUTPUT
ELSE
OUTPUT"poor"

ENDIF

ENDIF

ENDSF
flow chart
Start

OUTPUT "Enter 3 salaries"



INPUT S3,52,53

(S] 52 53)/3
aug
7
+
- +


Is
NO 20 OR Yes
ang
(50000
ang
?

v
oups "Invalid"
j5
110000 Yes
NO arg
v ? ->
I5

avg
= 2000 OUTPUT"Rich"
OUTPUT"Moderate"
AND yes
>
<= 10000
avg
?

NO
· OUTPUT"poor"
Pseudocode
14 DECLAREnumb, numb, num3: REAL

OUTPUT"Enter
"
3 numbers

INPUT numb, numd, numb


If
numb numb
=

OR num2:num3 oR num3:mum3
↑HEN

OUTPUT "Similar numbers (invalid)"


ELSE

numb
If -
num2 AND num]< num3 THEN
OUTPUT numb, "is the minimum"

ELSE
Ifnum2 < num3 THEN

OUTPUTnumb, "is the minimum"


ELSE

OUTPUT numb, "is the minimum"

ENDIF

ENDIF

ENDIF -
Flow chart

Start

OUTPUT"Enter 3 numbers"

JNPOT numb, num2, nums

1S
num] num2oR
=
yes
numb=num3 sR -> OUTPUT "Invalid"
mem2 numb =

?
NO

IS
num] <numb yes
OUTPUT
AND ->

No
numb, "is
~ num] numb
< minimum

7
S
numchums S OUTPUT numb, "is the minimum"

f
No?

OUTPUT numb, "is the minimum"


15 DECLAREweightInitial, weightfinal:Real
OUTPUT "Enter initial weight"
INPUT weight initial
OUTPUT"Enter final weight"
Inputweightfinal
57
weight initial weightfinal THEN
OUTPUT "Lostweight"
ELSE
If
weightinitial weightfinal THEN

OUTPUT "Gained weight"

ELSE

OUTPUT "No
change in
weight"
ENDJ ⑥
ENDIF
16
DECLARE X, Y : INTEGER
OUTPUT "Enter the X-coordinate of the point"
INPUT X
OUTPUT "Enter the Y-coordinate of the point"
INPUT Y
IF X = 0 AND Y = 0 THEN
OUTPUT "Origin"
Notnecessary
ELSE
o
IF X = 0 AND Y <> 0 THEN
OUTPUT "Y-Axis"
ELSE Notnecessary
Δ
IF X <> 0 AND Y = 0 THEN
OUTPUT "X-Axis"
ELSE
IF X > 0 AND Y > 0 THEN
OUTPUT "Q1"
ELSE
IF X < 0 AND Y < 0 THEN
OUTPUT "Q3"
ELSE

-
IF X > 0 AND Y < 0 THEN
OUTPUT "Q4"
ELSE
OUTPUT "Q2"
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
P24 in book Q17
DECLARE num1, num2, num3, first, second, third, x, y : REAL
OUTPUT "Enter 3 numbers"
INPUT num1, num2, num3
IF num1 > num2 AND num1 > num3 THEN
first <- num1 could find the
You
ELSE
IF num2 > num3 THEN
first <- num2 largestnumber, then
second
ELSE
first <- num3
the
largest. and
SO ON.
ENDIF
ENDIF
IF first = num1 THEN
IF (num1 - num2) < (num1 - num3) THEN
If numbnum) AND nuem]s
second <- num2 mumb THEN
third <- num3 IFnum2> num3 THEN
ELSE
IF (num1 - num2) > (num1 - num3) THEN
second <- num3 OUTPUT numb, num2,numb
third <- num2
ENDIF
ENDIF ...
and so on...
ENDIF
IF first = num2 THEN
IF (num2 - num1) < (num2 - num3) THEN
second <- num1
third <- num3
ELSE
IF (num2 - num1) > (num2 - num3) THEN
second <- num3
third <- num1
ENDIF
ENDIF
ENDIF
IF first = num3 THEN
IF (num3 - num1) < (num3 - num2) THEN
second <- num1
third <- num2
ELSE
IF (num3 - num1) > (num3 - num2) THEN
second <- num2
third <- num1
ENDIF
ENDIF
ENDIF
OUTPUT "The numbers in descending order: ", first, ", ", second, ", ", third
P 28
1
DECLARE classYear: INTEGER
OUTPUT "Enter class year"
INPUT classYear
CASE OF classYear
10 : OUTPUT "Freshman"
11 : OUTPUT "Junior"
12 : OUTPUT "Senior"

-
OTHERWISE OUTPUT "Invalid class year"
ENDCASE

2
DECLARE carCode : INTEGER
OUTPUT "Enter car code"
INPUT carCode
CASE OF carCode
1 : OUTPUT "Mercedes"
2 : OUTPUT "Ferrari"
3 : OUTPUT "McLaren"


OTHERWISE OUTPUT "Invalid car code"
ENDCASE

3
PSEUDOCODE

DECLARE dayNumber: INTEGER


OUTPUT "Enter day number"
INPUT dayNumber
CASE OF dayNumber
1 : OUTPUT "Sunday"
2 : OUTPUT "Monday"
3 : OUTPUT "Tuesday"
4 : OUTPUT "Wednesday"
5 : OUTPUT "Thursday"
6 : OUTPUT "Friday"
7 : OUTPUT "Saturday"
OTHERWISE OUTPUT "Invalid day number"
ENDCASE

FLOWCHART IS REPEATED
w
4

DECLARE mealCode: INTEGER


OUTPUT "Enter a meal code"
INPUT mealCode
CASE OF mealCode
1 : OUTPUT "Meal description is Nescafe Gold and calorie count is 80"
2 : OUTPUT "Meal description is Chicken MACDO and calorie count is 350"


3 : OUTPUT "Meal description is Coca Cola Can and calorie count is 160"
OTHERWISE OUTPUT "Invalid meal code"
ENDCASE

P29
1

DECLARE salary : INTEGER


DECLARE final : REAL
Salaries are REAL
OUTPUT "Enter your salary"
INPUT salary
numbers
IF salary < 0 OR salary > 50000 THEN
OUTPUT "Invalid salary"
ELSE
IF salary > 10000 THEN
final <- salary - (0.5 * salary)
OUTPUT "Updated amount = ", final
Not
ELSE necessary
IF salary >= 2000 AND- salary <= 10000 THEN
final <- salary - (0.25 * salary)
OUTPUT "Updated amount = ", final
ELSE
OUTPUT "No tax is applied"


OUTPUT "Updated amount = ", salary
ENDIF
ENDIF
ENDIF
2
DECLARE saving : INTEGER
DECLARE final : REAL
OUTPUT "Enter your savings"
INPUT saving
IF saving < 0 THEN
OUTPUT "Invalid saving"
ELSE
IF saving > 500000 THEN
final <- saving + (0.1 * saving)
OUTPUT "Updated amount = ", final
ELSE
IF saving > 250000 THEN
final <- saving + (0.05 * saving)
OUTPUT "Updated amount = ", final
ELSE
IF saving > 50000 THEN
final <- saving + (0.025 * saving)
OUTPUT "Updated amount = ", final
ELSE


OUTPUT "Updated amount = ", salary
ENDIF
ENDIF
ENDIF
ENDIF

3
Validation required
DECLARE receiptAmount, final: REAL
OUTPUT "Enter receipt amount" 5)didn't mention validation
INPUT receiptAmount
IF receiptAmount > 3000 THEN
THENudate
final <- receiptAmount - (0.25 * receiptAmount)
OUTPUT "Price after discount = ", final
ELSE Notnecessary
IF receiptAmount >= 2000 AND * receiptAmount <= 3000 THEN
final <- receiptAmount - (0.15 * receiptAmount)
OUTPUT "Price after discount = ", final
ELSE Notnecessary
*
IF receiptAmount >= 1000 AND receiptAmount <= 1999 THEN
final <- receiptAmount - (0.05 * receiptAmount)
OUTPUT "Price after discount = ", final
ELSE
OUTPUT "No discount"
OUTPUT "Price after discount = ", receiptAmount
ENDIF
ENDIF
ENDIF
4

DECLARE classYear: INTEGER


OUTPUT "Enter the class year"
INPUT classYear
IF classYear = 8 THEN
OUTPUT "Checkpoint"
ELSE
IF classYear = 9 THEN
OUTPUT "Pre-IG"
ELSE
IF classYear = 10 THEN
OUTPUT "IGCSE"

~
ELSE
OUTPUT "Invalid class year"
ENDIF
ENDIF
ENDIF

DECLARE Code : INTEGER


OUTPUT "Enter the program code"
INPUT Code
CASE OF Code
1 : OUTPUT "First"
2 : OUTPUT "Second"
OTHERWISE OUTPUT "Invalid code"

~
ENDCASE
6

DECLARE objectCode : INTEGER


DECLARE object : STRING
OUTPUT "Enter the object code"
INPUT objectCode
CASE OF objectCode

FEin
1 : object <- "Cube"

*
2 : object <- "Cuboid"
3 : object <- "Cylinder"
OTHERWISE OUTPUT "Invalid object code"
ENDCASE
DECLARE length, width, depth, radius, volume : REAL
IF object = "Cube" THEN


OUTPUT "Enter the length of the cube"
INPUT length
volume <- length*length*length
OUTPUT "Volume = ", volume
ELSE
IF object = "Cuboid" THEN


OUTPUT "Enter the length, width and depth"
INPUT length, width, depth
volume <- length * width * depth
OUTPUT "Volume = ", volume
ELSE


OUTPUT "Enter the radius then the depth"
INPUT radius, depth
volume <- (22/7) * radius * radius * depth
OUTPUT "Volume = ", volume
ENDIF
ENDIF

Validation
Required
While loop
P 34

1.
DECLARE height : REAL
OUTPUT "Enter the height"
INPUT height
WHILE height <= 0 DO
OUTPUT "Invalid height. Try again."
INPUT height
ENDWHILE
IF height >= 175 THEN
OUTPUT "Tall"
ELSE ~
OUTPUT "Short"
ENDIF

2.
DECLARE height : REAL
OUTPUT "Enter the height"
INPUT height
WHILE height <= 0 OR height > 300 DO
OUTPUT "Invalid height. Try again."
INPUT height
ENDWHILE
IF height >= 175 THEN
OUTPUT "Tall"
ELSE
OUTPUT "Short" ~
ENDIF

3.
DECLARE num1, num2, division : REAL
DECLARE count : INTEGER
count <- 0
OUTPUT "Enter two numbers to get their divisions"
INPUT num1, num2
WHILE num2 = 0 DO
count <- count +1
OUTPUT "Math error (can't divide by 0). Try again."
INPUT num1, num2
ENDWHILE

-
division <- num1/num2
OUTPUT "The result of the division = ", division
OUTPUT "Number of invalid entries = ", count
IF mark > 50 THEN
OUTPUT "Passed"
ELSE
OUTPUT "Failed"
ENDIF
OUTPUT "Number of invalid entries = ", count

5.
DECLARE score1, score2 : INTEGER
DECLARE avg : REAL
OUTPUT "Enter 2 exam scores"
INPUT score1, score2
WHILE score1 < 0 OR score1 > 100 DO
OUTPUT "Invalid first exam mark. Try again."
INPUT score1
ENDWHILE
WHILE score2 < 0 OR score2 > 50 DO

INPUT score2
ENDWHILE
-
OUTPUT "Invalid second exam mark. Try again."

avg <- (score1 + score2) / 2


OUTPUT "Average = ", avg
6.
DECLARE length, width, area : REAL
OUTPUT "Enter the dimensions of the rectangle"
INPUT length, width
WHILE length <=0 OR width <= 0 DO
OUTPUT "Invalid dimensions. Try again"
INPUT length, width
ENDWHILE
area <- length * width
OUTPUT "Area = ", area
validate value
by
value
7.
DECLARE courseNumber : INTEGER
OUTPUT "Enter courseNumber"
INPUT courseNumber
WHILE courseNumber < 1 OR courseNumber > 4 DO
OUTPUT "Invalid course number. Try again"
INPUT courseNumber
ENDWHILE
CASE OF courseNumber
1 : OUTPUT "Computer Science"
2 : OUTPUT "ICT"
3 : OUTPUT "Math"
OTHERWISE

-
OUTPUT "Bio"
ENDCASE
8.
DECLARE salary : REAL
DECLARE count : INTEGER
count <- 0
OUTPUT "Enter the salary"
INPUT salary
WHILE salary < 500 OR salary > 100000 DO
OUTPUT "Invalid salary. Try again."
INPUT salary counts countri
->

ENDWHILE
IF salary > 16000 THEN
OUTPUT "Rich"
ELSE
IF salary < 6000 THEN
OUTPUT "Poor"
ELSE
-
3
OUTPUT "Moderate"
ENDIF
ENDIF
9.
DECLARE price : MeINTEGER REAL
OUTPUT "Enter the price of the PS5"
INPUT price
WHILE price < 6000 OR price > 50000 DO
OUTPUT "Invalid price. Try again"
INPUT price
ENDWHILE
IF price <= 10000 THEN
OUTPUT "Reasonable price"
ELSE
IF price <= 15000 THEN
OUTPUT "Slightly overpriced"
ELSE
OUTPUT "Very expensive"
ENDIF
ENDIF ~
10. DECLARE num, sum, avg, count: REAL
d
count <- 0 INTEGER
sum <- 0
OUTPUT "Enter a number"
INPUT num
WHILE num > 0 DO
count <- count + 1
sum <- num + sum
OUTPUT "Enter a number"
INPUT num
ENDWHILE If count:0 THEN
as
avg <- sum/count OUTPUT "No average,
count:O
OUTPUT "Average = ", avg

MS -
11.
DECLARE age, countA, countR : INTEGER
countA <- 0
countR <- 0
OUTPUT "Enter the age"
INPUT age
than
WHILE age >-until
0 DO
user

OUTPUT "Enter another age"


enterage
INPUT age
IF age > 12 THEN
countA <- countA + 1
ELSE
countR <- countR + 1
ENDIF
ENDWHILE
OUTPUT "Number of people accepted = ", countA
OUTPUT "Number of people rejected = ", countR


REPEAT. UNL Loop
Loops P2 Page 38
1. + 2.
DECLARE height : REAL
REPEAT
OUTPUT "Enter the height:"
INPUT height
IF height <= 0 OR height > 300 THEN
OUTPUT "Invalid height. Try again."
ENDIF
UNTIL height > 0 AND height <= 300
IF height >= 175 THEN
OUTPUT "Tall"

a
ELSE
OUTPUT "Short"
ENDIF

3.
DECLARE mark, count : INTEGER
count <- 0
REPEAT
OUTPUT "Enter the mark: "
INPUT mark
IF mark < 0 OR mark > 100 THEN
count <- count + 1
OUTPUT "Invalid mark. Try again"
ENDIF
UNTIL mark < 100 AND mark > 0
= =

OUTPUT "The number of invalid entries = ", count


Ifmark = 50
=
THEN

OUTPUT "Passed"
ELSE
OUTPUT "failed" -

3
ENDI
4.
DECLARE mark1, mark2 : INTEGER
DECLARE avg : REAL
REPEAT
OUTPUT "Enter the 2 marks"
INPUT mark1, mark2
IF mark1 > 100 OR mark2 > 50 OR mark1 < 0 OR mark1
2 < 0 THEN
OUTPUT "Invalid marks. Try again"
ENDIF


UNTIL mark1 <= 100 AND mark2 <= 50 AND mark1 >= 0 AND mark2 >=0
avg <- (mark1 + mark2)/2
OUTPUT "The average of 2 marks = ", avg

5.
DECLARE length, width, area : REAL
REPEAT
OUTPUT "Enter the dimensions of the rectangle: "
INPUT length, width
IF length < 0 OR width < 0 THEN
1
= =

OUTPUT "Invalid input." -

ENDIF
UNTIL length >= M 0 AND width >=
W0
area <- length * width
OUTPUT "Area = ", area
6.
DECLARE price : REAL
REPEAT
OUTPUT "Enter the PS5 price:" ol
INPUT price
count no.
entries
IF price < 6000 or price > 50000 THEN
OUTPUT "Invalid input." invalid
-
ENDIF
UNTIL price >= 6000 AND price <= 50000
IF price <= 10000 THEN
OUTPUT "Reasonable d
Y price"
ELSE
IF price <= 15000 THEN
OUTPUT "Slightly overpriced"
-
2
ELSE
OUTPUT "Very expensive"
ENDIF
ENDIF

7.

DECLARE num, sum : REAL


sum <- 0

s
REPEAT
OUTPUT "Enter number: "
INPUT num
IF num > 0 THEN
sum <- sum + num
ENDIF
UNTIL num = -1
OUTPUT "The sum of the positive numbers = ", sum
Loops p3 P43

1.
DECLARE number, total, an avg : REAL
DECLARE count : INTEGER
Total
*
count <- 0
total <- 0
required:
REPEAT
OUTPUT "Enter a number"
INPUT number
count
muma <- count + 1
total <- total + number
UNTIL number < 0
avg <- total / count total
#my
OUTPUT "Average = ", avg
OUTPUT"Sum:"

2.
DECLARE number, total : REAL
total <- 0
FOR i <- 1 to 100
OUTPUT "Enter a number"
INPUT number
total <- total + number
NEXT ⑤
OUTPUT "Total = ", total
3.
DECLARE num : REAL
DECLARE count : INTEGER
count <- 0
FOR i <- 1 TO 100
OUTPUT "Enter a number"
INPUT num
IF num >= 35 AND num <= 100 THEN
count <- count + 1
ENDIF

-
NEXT
OUTPUT "There are ", count, " numbers between 35 and 100 (inclusive).

4.
DECLARE number, Tpositive, Tnegative: REAL
Tpositive <- 0
Tnegative <- 0
FOR i <- 1 TO -300
5
OUTPUT "Enter a number" ⑯
INPUT number
IF number < 0 THEN
Tnegative <- Tnegative + number
ENDIF ELSE
or
IF number > 0 THEN
Tpositive <- Tpositive + number
ENDIF
NEXT
OUTPUT "The sum of positive numbers = ", Tpositive
OUTPUT "The sum of negative numbers = ", Tnegative
5.
DECLARE number, Tpositive: REAL
Tpositive <- 0
FOR i <- 1 TO -300
5
OUTPUT "Enter a number"
INPUT number
IF number > 0 THEN
Tpositive <- Tpositive + number

ENDIF
NEXT
OUTPUT "The sum of positive numbers = ", Tpositive

6. &
INTEGER
DECLARE number, Cnegative: REAL
Cnegative <- 0
FOR i <- 1 TO =300
5
OUTPUT "Enter a number" -
INPUT number
IF number < 0 THEN
Cnegative <- Cnegative + 1

-
ENDIF
NEXT
OUTPUT "The sum of negative numbers = ", Cnegative
7.
DECLARE number: REAL
DECLARE count_positive, count_negative, count_zero : INTEGER
count_zero <- 0
count_negative <- 0
count_positive <- 0
FOR i <- 1 TO -100
5
-

1
OUTPUT "Enter a number"
INPUT number
IF number < 0 THEN
count_negative <- count_negative + 1
ELSE
IF number > 0 THEN
count_positive <- count_positive + 1
ELSE
count_zero <- count_zero + 1
ENDIF
ENDIF
NEXT
OUTPUT "The count of positive numbers = ", count_positive


OUTPUT "The count of negative numbers = ", count_negative
OUTPUT "The count of zeros = ", count_zero
8. SAME AS [6]
9.
DECLARE num, avgpositive, avgnegative, postotal, negtotal : REAL
DECLARE zerocount, poscount, negcount : INTEGER
zerocount <- 0
poscount <- 0
negcount <- 0
postotal <- 0
negtotal <- 0
FOR i <- 1 TO 10O
OUTPUT "Enter a number"
INPUT num
IF num < 0 THEN
negtotal <- negtotal + num
negcount <- negcount + 1
ELSE
IF num > 0 THEN
poscount <- poscount + 1
postotal <- postotal + num
ELSE
zerocount <- zerocount + 1
ENDIF
ENDIF
NEXT
IF negcount > 0 THEN
- 1
avgnegative <- negtotal / negcount
OUTPUT "Average of negative numbers = ", avgnegative
ENDIF ELSE

Si
IF poscount > 0 THEN
avgpositive <- postotal / poscount
OUTPUT "Average of positive numbers = ", avgpositive
ENDIF
IF zerocount > 0 THEN
OUTPUT "Number of zeros = ", zerocount
ENDIF

-
IF negcount = 0 THEN
OUTPUT "There are no negative numbers"
ENDIF
IF poscount = 0 THEN
OUTPUT "There are no positive numbers"
ENDIF
IF zerocount = 0 THEN
OUTPUT "There are no zeros"
ENDIF
10.
Sum <- 0
DECLARE i : INTEGER
i <- 0
WHILE i < 10 DO
i <- i + 1
INPUT Num
IF Num > 100 THEN
Sum <- Sum + Num
ENDIF
ENDWHILE
OUTPUT Sum
Sum <- 0
DECLARE i : INTEGER
i <- 0
REPEAT
i <- i + 1
INPUT Num
IF Num > 100 THEN
Sum <- Sum + Num
ENDIF
UNTIL i = 10
OUTPUTSum
11.
DECLARE num, total, avg : REAL
DECLARE count : INTEGER
total <- 0
count <- 0
FOR i <- 1 TO 100
OUTPUT "Enter a number"
INPUT num
IF num > 40 THEN
total <- total + num
count <- count + 1
ENDIF
NEXT ③
IF count > 0 THEN
avg <- total / count
OUTPUT "The average = ", avg

~
ELSE
OUTPUT "There are no numbers more than 40"
ENDIF

12.
DECLARE num, total : REAL
total <- 0
FOR i <- 1 TO 10
OUTPUT "Enter a number"
INPUT num
total <- total + num
NEXT
IF total >= 70 THEN
OUTPUT "Good"

~
ELSE
OUTPUT "Bad"
ENDIF
13.

DECLARE num, total, avg: REAL


DECLARE count : INTEGER
count <- 0
total <- 0
FOR i <- 1 TO 10
OUTPUT "Enter a number"
INPUT num
total <- total + num
count <- count + 1
NEXT
avg <- total / count
IF avg < 50 THEN
OUTPUT "Bad"
ELSE
IF avg > 70 THEN
OUTPUT "Good"

~
ELSE
OUTPUT "Moderate"
ENDIF
ENDIF
14.
DECLARE num : REAL
DECLARE count : INTEGER
count <- 0
FOR i <- 1 TO 5
OUTPUT "Enter a number"
INPUT num
IF num = INT(num) THEN
count <- count + 1
ENDIF
NEXT


OUTPUT "Number of whole numbers = ", count

15.

DECLARE num, Ptotal, Ntotal : REAL


DECLARE J : INTEGER
Ptotal <- 0
Ntotal <- 0
OUTPUT "How many numbers do you wish to input?"
INPUT J
FOR i <- 1 to J validate
=>
OUTPUT "Enter a number"
wHSLE icO DO
INPUT num number"
IF num < 0 THEN OUTPUT"Enter athe
Ntotal <- Ntotal + num INPUTJ
ELSE ENDWAZE
IF num > 0 THEN
Ptotal <- Ptotal + num
ENDIF
ENDIF
NEXT
OUTPUT "The total of positive numbers = ", Ptotal
OUTPUT "The total of negative numbers = ", Ntotal
LOOPS P4 p48
1.
DECLARE age : INTEGER
OUTPUT "What is your age?"
INPUT age
WARE
IF unDO
age < 1 OR age > 99 THEN
OUTPUT "Invalid age. Try again"
INPUT age
-

2
ELSE ENDWHILE
I
IF age >= 18 THEN
OUTPUT "You can drive"
ELSE
OUTPUT "You can not drive"
ENDIF
ENDIF

2.

DECLARE temp, sum, avg : REAL


DECLARE count : INTEGER
for necessarye
count <- 0
sum <- 0
Count,
FOR i <- 1 TO 30
OUTPUT "Enter a temperature"
INPUT temp
WHILE temp > 40 OR temp < -19 DO
OUTPUT "Invalid temperature. Try again"
INPUT temp
ENDWHILE
sum <- sum + temp
count <- count + 1
NEXT
avg <- sum / count
OUTPUT "The average temperature = ", avg
-
3.
DECLARE num, min : REAL
OUTPUT "Enter a number"
INPUT num
min <- num
FOR i <- 1 TO 99
OUTPUT "Enter a number"
INPUT num
IF num < min THEN
min <- num
ENDIF
NEXT
OUTPUT "The minimum = ", min ⑤
4.
DECLARE mark : INTEGER
OUTPUT "Enter a mark"
INPUT mark
WHILE mark < 0 OR mark > 100 DO
OUTPUT "Invalid mark. Try again"
INPUT mark
ENDWHILE
IF mark > 50 THEN
OUTPUT "Passed"

~
ELSE
OUTPUT "Failed"
ENDIF
5.

DECLARE temp, max : REAL


OUTPUT "Enter a temperature"
INPUT temp z 21
-

max
max <- temp
FOR i <- 1 TO 364
OUTPUT "Enter a temperature"
INPUT temp
WHILE temp < -20 OR temp > 100 DO
OUTPUT "Invalid temperature. Try again"
INPUT temp

-
ENDWHILE
IF temp > max THEN
max <- temp
ENDIF
NEXT
OUTPUT "The maximum temperature = ", max
6. DECLARE mark, sum : INTEGER
DECLARE avg : REAL
sum <- 0
FOR i <- 1 TO 5 0
OUTPUT "Enter a mark"
INPUT mark
WHILE mark < 0 OR mark > 100 DO
OUTPUT "Invalid mark. Try again"
INPUT mark
ENDWHILE
sum <- sum + mark ⑯
NEXT
avg <- sum / 50

~
IF avg >= 70 THEN
OUTPUT "Good performance"
ELSE
OUTPUT "Bad performance"
ENDIF
7.
DECLARE mark, max : INTEGER
max <- -1
FOR i <- 1 TO 100
OUTPUT "Enter exam mark"
INPUT mark
WHILE mark < 0 OR mark > 100 DO
OUTPUT "Invalid mark. Try again"
INPUT mark
ENDWHILE
IF mark > max THEN
max <- mark

/
ENDIF
NEXT
OUTPUT "The highest mark = ", max

8.

DECLARE age, countA, countR : INTEGER


countA <- 0
countR <- 0
FOR i <- 1 TO10
5
OUTPUT "Enter an age"
INPUT age
WHILE age > 80 OR age < 1 DO
OUTPUT "Invalid age. Try again"
INPUT age

ENDWHILE
IF age > 12 THEN
countA <- countA + 1
ELSE
countR <- countR + 1
ENDIF
NEXT


OUTPUT "The number of people who can't play the game = ", countR
OUTPUT "The number of people who can play the game = ", countA
P53 Arrays
1.
DECLARE numbers[1:10] : REAL
FOR i <- 1 TO 10
OUTPUT "Enter a number"
INPUT numbers[i]
NEXT
DECLARE count : INTEGER
count <- 10
OUTPUT "Numbers in reverse :"
REPEAT
OUTPUT numbers[count]
count <- count - 1
UNTIL count = 0

king
1
10T0Δ5P
-

f0Ri<
2.

DECLARE temp[1:365] : REAL


FOR i <- 1 TO 365
OUTPUT "Enter a temperature"
INPUT temp[i]
NEXT

DECLARE maxFirst20 : REAL


maxFirst20 <- -9000
FOR i <- 1 TO 20 -
b
IF temp[i] > maxFirst20 THEN
maxFirst20 <- temp[i]
ENDIF
NEXT
OUTPUT "The highest temperature in the first 20 days = ", maxFirst20

DECLARE maxLast20 : REAL


maxLast20 <- -9000
346
*
FOR i <- 345 TO 365
IF temp[i] > maxLast20 THEN
maxLast20 <- temp[i]
ENDIF
NEXT
OUTPUT "The highest temperature in the last 20 days = ", maxLast20
3.

18
DECLARE names[1:10] : STRING
DECLARE ages[1:10] : INTEGER
FOR i <- 1 TO 10
OUTPUT "Enter student's name"
INPUT names[i]
OUTPUT "Enter student's age"
INPUT ages[i]
WHILE ages[i] <= 0 DO
OUTPUT “Invalid age. Try again"
INPUT ages[i]
NEXT

DECLARE max : INTEGER


max <- 0
FOR i <- 1 TO 10
IF max < ages[i] THEN
max <- ages[i]
ENDIF
NEXT
OUTPUT "Oldest student(s) : "
FOR i <- 1 TO 10

s
IF ages[i] = max THEN
OUTPUT names[i]
ENDIF
NEXT
4.

//Task 1
DECLARE marks[1:100] : INTEGER
FOR i <- 1 TO 100
OUTPUT "Enter the student's mark"
INPUT marks[i]
WHILE marks[i] < 0 OR marks[i] > 2100 DO
OUTPUT "Invalid mark. Try again"
INPUT marks[i]
ENDWHILE
NEXT

//Task 2
DECLARE sum : INTEGER
DECLARE avg : REAL
sum <- 0
FOR i <- 1 TO 100
sum <- sum + marks[i]
NEXT
avg <- sum / 100
OUTPUT "The average mark = ", avg

//Task 3
DECLARE countPassed, countFailed : INTEGER
countPassed <- 0
countFailed <- 0
FOR i <- 1 TO 100
IF marks[i] >= 13 THEN
countPassed <- countPassed + 1
ELSE
countFailed <- countFailed + 1
ENDIF

r
NEXT
OUTPUT "The number of students who passed = ", countPassed
OUTPUT "The number of students who failed = ", countFailed
5.

//Task 1
DECLARE midday[1:30], midnight[1:30] : REAL
FOR i <- 1 TO 30
OUTPUT "Enter the temperature at midday"
INPUT midday[i]
WHILE midday[i] < -20 OR midday[i] > 100 DO
OUTPUT "Invalid temperature. Try again"
INPUT midday[i]
ENDWHILE
OUTPUT "Enter the temperature at midnight"
INPUT midnight[i]
WHILE midnight[i] < -20 OR midnight[i] > 100 DO
OUTPUT "Invalid temperature. Try again"
INPUT midnight[i]
ENDWHILE
NEXT

//Task 2
DECLARE sumday, avgday : REAL
sumday <- 0
FOR i <- 1 TO 30
sumday <- sumday + midday[i]
NEXT

avgday <- sumday/30
OUTPUT "Average temperature for midday = ", avgday

DECLARE sumnight, avgnight : REAL


sumnight <- 0
FOR i <- 1 TO 30
sumnight <- sumnight + midnight[i]
NEXT
avgnight <- sumnight / 30
OUTPUT "Average temperature for midnight = ", avgnight

//Task 3 min
DECLARE maxday, maxnight
un : REAL
maxday <- -21
day"
-elect
maxnight <- -21 the
FOR i <- 1 TO 30
IF midday[i] > maxday THEN
30
maxday <- midday[i] FOR i z ITO
ENDIF
Onion If [i]:minnightthe
midnight
IF midnight[i] > maxnight THEN
OUTPUTI
maxnight <- midnight[i]
ENDIF SNSF
midday(i): maxday ...

NEXT outPUT i
OUTPUT "The highest temperature in midday = ", maxday
m temperature in midnight = ", maxnight
OUTPUT "The highest ENDIF
Lowest
6.

//Task 1
DECLARE temp[1:365] : REAL
FOR i <- 1 TO 365
OUTPUT "Enter a temperature"
INPUT temp[i]
WHILE temp[i] < -25 OR temp[i] > 100 DO
OUTPUT "Invalid temperature. Try again."
INPUT temp[i]
ENDWHILE
NEXT

//Task 2
DECLARE max : REAL
max <- -26
FOR i <- 1 TO 365
IF temp[i] > max THEN
max <- temp[i]
ENDIF
NEXT
OUTPUT "The highest temperature in the year= ", max

//Task 3
OUTPUT "The numbers of the days where temperature exceeded 30:"
FOR i <- 1 TO 365
IF temp[i] > 30 THEN
OUTPUT i
ENDIF
NEXT w
7.
//Task1
DECLARE weights[1:50] : REAL
FOR i <- 1 TO 50
OUTPUT "Enter a weight"
INPUT weights[i]
WHILE weights[i] < 10 OR weights[i] > 300 DO
OUTPUT "Invalid weight. Try again"
INPUT weights[i]
ENDWHILE
NEXT

//Task2
DECLARE count : INTEGER

DECLARE sum, avg : REAL
count <- 0
sum <- 0
FOR i <- 1 TO 50
IF weights[i] < 80 THEN
sum <- sum + weights[i]
count 0 THEN 180"
it
>

count <- count + 1 Of


weig

SolidateELSExpuT
ENDIF "No
NEXT
avg <- sum / count
C
OUTPUT "The average of weights lighter than 80 kg = ", avg

//Task3
DECLARE count2 : INTEGER
count2 <- 0
FOR i <- 1 TO 50


IF weights[i] > 100 THEN
count2 <- count2 + 1
ENDIF
NEXT
OUTPUT "The number of people heavier than 100 kg = ", count2
8.

//Task 1
DECLARE names[1:50] : STRING
DECLARE weights[1:50] : REAL
FOR i <- 1 TO 50
OUTPUT "Enter the name of the parcel"
INPUT names[i]
OUTPUT "Enter the weight of the parcel "
INPUT weights[i]
WHILE weights[i] < 10 OR weights[i] > 230 DO
OUTPUT "Invalid weight. Try again."
INPUT weights[i]
ENDWHILE
NEXT

//Task 2

DECLARE max : REAL
max <- 9
FOR i <- 1 TO 50
IF weights[i] > max THEN
max <- weights[i]
ENDIF
NEXT
OUTPUT "The maximum weight = ", max

//Task 3
OUTPUT "The name(s) of the package(s) with the maximum weight:"
FOR i <- 1 TO 50 >100
IF weights[i] an
= max THEN
OUTPUT names[i]
ENDIF
NEXT
9.

//Task1
DECLARE marks[1:10] : INTEGER
DECLARE names[1:10] : STRING
FOR i <- 1 TO 10
OUTPUT "Enter the name"
INPUT names[i]
OUTPUT "Enter the mark"
INPUT marks[i]
WHILE marks[i] < 0 OR marks[i] > 50 DO
OUTPUT "Invalid mark. Try again"
INPUT marks[i]
ENDWHILE
NEXT

//Task2
DECLARE sum : INTEGER
DECLARE avg : REAL
sum <- 0
FOR i <- 1 TO 10
sum <- sum + marks[i]
NEXT
avg <- sum / 10
OUTPUT "The average mark of the class = ", avg

//Task3
DECLARE max : INTEGER
max <- -1
FOR i <- 1 TO 10
IF marks[i] > max THEN
max <- marks[i]
ENDIF
NEXT


OUTPUT "The name(s) of the student(s) that scored the highest mark:"
FOR i <- 1 TO 10
IF marks[i] = max THEN
OUTPUT names[i]
ENDIF
NEXT
10.

//Task1
DECLARE names[1:500], genders[1:500] : STRING
DECLARE salaries[1:500] : REAL
FOR i <- 1 TO 500
OUTPUT "Enter the name"
INPUT names[i]
OUTPUT "Enter the gender"
INPUT genders[i]
WHILE genders[i] <> "Male" AND genders[i] <> "Female" DO
OUTPUT "Invalid gender. Try again"
INPUT genders[i]
ENDWHILE
OUTPUT "Enter the salary"
INPUT salaries[i]


WHILE salaries[i] < 1000 OR salaries[i] > 40000 DO
OUTPUT "Invalid salary. Try again"
INPUT salaries[i]
ENDWHILE
NEXT

//Task2


DECLARE maxMale : REAL
maxMale <- 999
FOR i <- 1 TO 500
IF genders[i]
- = "Male" THEN
IF salaries[i] > maxMale THEN
maxMale <- salaries[i]
ENDIF
ENDIF
NEXT

-NR
OUTPUT "The highest-paid male : "
FOR i <- 1 TO 500
-
IF genders[i] = "Male" THEN
IF salaries[i] = maxMale THEN
OUTPUT names[i]
ENDIF
ENDIF
NEXT

DECLARE maxfemale : REAL


maxfemale <- 999
FOR i <- 1 TO 500
IF genders[i] = "Female" THEN
IF salaries[i] > maxfemale THEN
maxfemale <- salaries[i]
ENDIF
ENDIF
NEXT


OUTPUT "The highest-paid female : "
FOR i <- 1 TO 500
IF genders[i] = "Female" THEN
IF salaries[i] = maxfemale THEN
OUTPUT names[i]
ENDIF
ENDIF
NEXT

//Task3
DECLARE sumMale, sumFemale, avgMale, avgFemale : REAL
DECLARE countMale, countFemale : INTEGER
countFemale <- 0
countMale <- 0
sumMale <- 0
sumFemale <- 0
FOR i <- 1 TO 500

-countralTHIN..
IF genders[i] = "Male" THEN
sumMale <- sumMale + salaries[i]
countMale <- countMale + 1
ENDIF
NEXT
avgMale <- sumMale / countMale

FOR i <- 1 TO 500


IF genders[i] = "Female" THEN
sumFemale <- sumFemale + salaries[i]
countFemale <- countFemale + 1
ENDIF
NEXT
avgFemale <- sumFemale / countFemale

IF avgFemale > avgMale THEN


OUTPUT "Average salary of females is greater"
ELSE
IF avgFemale < avgMale THEN
OUTPUT "Average salary of males is greater"
ELSE
validate
OUTPUT "Average salaries of males and females are equal"
ENDIF
ENDIF the counts

You might also like