Olevel Computer Science Study Notes Made by Ahmed Wael
Olevel Computer Science Study Notes Made by Ahmed Wael
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 -
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
=
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
2.
↓
4 powers
them.
⑱
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.
·
2
1 0 10 11/1
128
#
#
32
⑧
Convertto binary then to
denary
t
4
+
2
↓
171
-
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
for
Reasons
using
hexadecimal
by programmers instead of
binary
·
2 -
easier for programmers to identify errors
3. Easier to remember
· 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
·
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
·
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.
sound at
sampling:process of
determining amplitude of
·
differenttime intervals.
Bit
of audio like
->
Size an
refers
Bit
1. to one
binary digit
0101 1100
!
103
> x10
(MB)
20
x10 (GB]
140
=20
x1p Terabytep)
bytes
↑ to
petabytepp) 260
bytes
5) file compression:
J. Lossless compression:
·
·
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: ·
Data
dictionary:
·
The
repeated characters are identified
They're then indexed.
·
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
·
the file.
are
permanently
·
transmitted storage
file takes less
file can be up more quickly
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
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
=
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
=
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
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
J. Mechanical mouse:
principle of operation
1 uses a rubber ball under itto detectmovement
#
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
voice
recognition
-> softwareused
from their voice
to identify a known user
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.
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; -
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.
Measurementsareconvertedtodigital see
4. file
#) Barcode reader:
1. What's a barcode:
consists of black and white lines of varying thickness
# How does a
reader work:
shines
1. It a red light(illuminator) on the barcode.
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.
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: -
input
text digital keyboard
using
Handwriting recognition
·
computer control
#
Principle of operation:
1
computer's screen is
projected onto the board
#
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
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.
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:
take
readings more
frequently
work
continuously & no breaks
#
Examples of sensors and their uses:
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 -
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
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.
5. Ifit's within
range, no action is taken.
·
Infrared sensor detects movement of intruder
·
Pressure sensor
picks weightof an intruder
up
entering.
3. Data is converted to digital using ADC.
microprocessor
sound
7.
Flashing & continue till
system is
reset
using
a
password.
55. Main rule!.
from
Data sent sensors to microprocessor
Moni
till
tori n g continues
is shut let.
system
5) Control systems!
To consistof:
sensors
Microprocessor
actuators
#·
Advantages of control systems to humans:
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
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
microprocessor sends
rotating
1
signa to
the
brakingdecreas
thatspeed system
toincreasethepressure
so one
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
ALiquid
crystalcanbetransparentoopaquepersed
3.
r
changing
to them.
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. 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: -
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
3- Run quieter
6.
Longer-lasting lamps.
⑤ Printers -
& 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
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
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
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
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
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
·
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
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)
-
1. Platters:disks where
magnetic dots are stored.
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:
2- platters attached
are to
spindle that spins
them high speeds.
at
↑
Electromagnetic
magnetic readoriteheads applysuitableone
secondary storage: (solid-States
of
Data is storedby controlling the movement
-
·
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.
used.
2. flow of electrons is controlled by transistors
inside NAND chips.
5 Data is
values read1forsretrieving the binar
one
HDD SSD
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.
Compactdisk (CD): -
ONLY read
R i Write ONCE
only
RW:Read & write repeatedly
DUD-RAN: -
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
-
same
technology as
memory sticks
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
① Types of
programming languages:
·
High-level languages:
closer to human
languages
-
Portable ->
can be used on differentplatforms
·
·
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
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.
found and
3.
Interpreter when
stopsafter an error is
fixed.
continues only the error is
2) Assembler;
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
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:
·
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
fatch-execute cycle:
1. PC contains the address of the memory location of
the nextinstructionto be fetched
2. RAM
50 control unit
controls flow of data through CPU
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
8. Buses:
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:
-
Applications:
Wif,
Universal Serial Bus (USB)
B) Parallel:
Data is sent as
multiple bits simultaneously over
multiple wires
used
Move to install it multiple
wires.
expensive as
requires
Applications:
used in RAM
used in
Integrated Circuits/Buses (exceptUSB)
② Type I direction:
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
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
A
parity
data. byte is sent
along with the block of
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.
algorithm
4. The
original
calculated one.
checksum is compared with the
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
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
Doesn't
change (static
·
61 12 B3 47
- -
-
- 25 -
FE
↑ JP address: - InternetProtocol
-
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:
Determines bandwidth
Provides security services
④ Webpage.
Web documentwritten in HTML
⑤ Website i
Web
⑦ server:
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
* ( Web browser:
thatallows
Program the user to view
webpages
functions:
connects to webserver
translates HTML
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.
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
2 User's
2.le.
paymentdetails are stored in an
encrypted text
may
feel their
privacy is affected.
sensitive information in cookies
may
be intercepted during transmission
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
·
·
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
2.
5tafileis infected,twooptions appear;deone
constantly runs in
background
can run a scheduled scan
can
quarantine 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
Protection:
Use strong passwords
Use
encryption
NB.
Hackingin depot harmen but
cracking
set
② Data Thefti
A) spyware: ABA:key-logging software
Possible effects: -
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
-
Possible effects:
Creator data
can
getsensitive
Creditcard fraud
Protection: -
Use
spam filters
Don'tclick links from unknown sources
Possible effects:
The creator steals sensitive data
creditcard fraud
Protection:
Possible effects:
from
Preventing
emails
users
accessing
websites
Online services
Protection:
Firewall to restricttraffic to & from server
Proxy server
Protection against
data risks
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
and prevents
Hacking
Warns unauthorized access to the
system
virus
S May preventviruses being transmitted to the network
Disabling firewall
Incorrect of firewall
configuration
How firewall blocks access to undesired websites: -
1 -
traffic
2 -
firewall checks
any entering the network
3
undesiredonauthorise
*
one
Virusesare
computer
·
Personal
Firewall
Proxy Servers
#
Def server thatacts as an intermediate between PC
inition
and web server.
the webserver
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
=
Harderfor a hacker to
force
guess the key (brute
attack)
A) Symmetric Encryption:
Atype encryption
of that some my
end
asin.
uses
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
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
possible
methods
to extend FLS by addingueauthentication
Session
existing instead of creating
i resuming an session
steps:
itself
1 Browser requests server to
identify
sends its certificate browser
2 server
digital to
5 session
caching can be used
6
Asymmetrical encryption is used for all data
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
Method
3ys
Intern requires userto inputlogin decalsare
Chapter 10
Ethics ExtraS+
* Uses of hexadecimal: -
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
·
size
⑪) 25P:.
-
uses lossless compression
->
stores a of commands
set thatinstructdigital
instruments when to produce a particular sound
-
·
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 cover:
-
without permission
backing)
Privacy issues (eg. Hacking
·
on
Their importance:
-
1. Free Software: -
subject to some
copyrightlaws
-
legally study
can't or
modify code
·
-
User is allowed a free trial period 1
and
they're charged after the period
-
· 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
Steps:
1 Datais inputwith the check digitappended
2. Acalculation is performed on the input data
3.
Theinput check digitis compared withthese
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
Purpose:
allow differentpaths
certain criterial
through a
program depending on
meeting
Purpose:
used to test for
large number of discrete values.
Purpose is
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
-
-Criteria is post-tested
·
16 Totalling
The process of list of numbers
summing a
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:
·
Dimensions
Loop counters
Initial value of the counter
starting
->
Required Numberthat's
->
Required =
Initial final
I
REPEAT WHILE
UNTFL DO
·
value is checked once incremented Value is checked after incrementation
* 19 1 20
↳
=
+
Onemoreloopwillbedoveseed
once incremented, the
loop ends Conce final is incremented,
* the loop goes once more
UNTL counter=[Final] *
tonmiregnolal owedto
see
WHILELoop problem
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
done
changes
data is
have
consistent.
to be
only once -
)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 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
: "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
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
v.
Length check:
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.
IDDPredefi
valuesned
1
Quantity
Number
Type Range
# Presence
⑥ Verification:
-checking thatdata did notchange during the
input
to computer or transfer between computer S
Methods include:
·
Screen / visual
Double
entry
·
Screen/visual check
Top Down
-
design
The
breaking down of computer system to a
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 : -
←•
ftp.re-tested
☒
Already
given a
Advantages : -
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:
wrong,typeare accepted
Letters
Decimals
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
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-"
"
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
=
*
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
Parkingstartspacein
NEXT
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
Day <1
WHILE OR
Day>1 OR
ELSE
WHILEDay<] or
Day >I4OR
Parking Startspace(Day] + 1
INDIF
SAPUT
Booking License Nums (BookingCount]
OUTPUT "Would you like to make another booking?"
INPUT Continue
INPUTUser Choice
If
BookingSpace [] =5 THEN
CountAccessibleDay Count Accessible
Day 1
-
ELSE
CountGeneral
Day & Count General
Day
ENDIF
ENDI
NEXT
FOR i <1 T0
Booking Count
57
BookingSpace[i] < 5 THEN
=
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
70R i81405
OUAPnumber"
&
noretum,
and
-put
nunz
producta numb
&
OUTPU
"Productis "product
& END
2. DECLARCside, area: REAL
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]
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
average
c -
sum/3
"Productis", product,
and
OUTPUT is "
average
average
Start
↓
>
⑭
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"
↳
↓
·
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
↓
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
↓
↓
INPUTsMark
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
*
OUTPUT"Enter 2 numbers
"
2
ENDIF
OuPUN"
Bigger
numberis
numb
DECLARGheight:REAL
THEN
height
55 == 175
OUTPUT "Tall"
ELSE
ENDSF
OUTPUT
"short" INTEGER
3 h
REAL
-
DECLARE scored, scored, as :
E15E
outpUT
OUTPUT
"passed"
"Failed" END5S
↑
INPUT side
Ifside < 0 THEN
OUTPUT "Invalid side length"
ELSE
area <- side *
side
5
ENDIF OUTPUT The area =", area
pic -
22/7
DECLARE
age:INTEGER
DECLARS name: STRING
OUTPUT name
INPUT name
If <0 THEN
age
OUTPUT"Invalid
age"
ELSE
OUTPUT "Hello!My name
is", name
years old
"
ENDI
⑤
7
DECLARE
num, square:REAL
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"Equal"
ELSE
IFnum] > num2 THEN
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
55 NO 36 yes
day number L dayNumber
h =4
iS NO S
=
dayNumer
G
Yes... opUday
-
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
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"
"Moderate
OUTPUT
ELSE
OUTPUT"poor"
ENDIF
ENDIF
ENDSF
flow chart
Start
↓
↓
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
OR num2:num3 oR num3:mum3
↑HEN
numb
If -
num2 AND num]< num3 THEN
OUTPUT numb, "is the minimum"
ELSE
Ifnum2 < num3 THEN
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?
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
FLOWCHART IS REPEATED
w
4
⑤
3 : OUTPUT "Meal description is Coca Cola Can and calorie count is 160"
OTHERWISE OUTPUT "Invalid meal code"
ENDCASE
P29
1
⑤
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
~
ELSE
OUTPUT "Invalid class year"
ENDIF
ENDIF
ENDIF
~
ENDCASE
6
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."
-
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
⑯
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 "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
= =
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.
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.
~
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.
2
ELSE ENDWHILE
I
IF age >= 18 THEN
OUTPUT "You can drive"
ELSE
OUTPUT "You can not drive"
ENDIF
ENDIF
2.
~
ELSE
OUTPUT "Failed"
ENDIF
5.
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.
⑤
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.
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
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
//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
>
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
⑤
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
⑨
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