Uploaded by adeebaasif07

igcse compsci 2ed cb coursebook answers

advertisement
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Sample answers have been written by the authors. In examinations, the way marks are awarded may be different.
Coursebook answers
Chapter 1: Data representation
Discussion questions
1
The answer will depend on the students.
2
This will be an open-ended discussion.
Questions
1
Any three examples of data that is heard, smelt, seen or touched, e.g. hearing music or
a soundwave.
2
It has lots of different possible values, rather than limited values like discrete data.
3
1
1
0
0
0
1
1
0
0
1
0
1
0
0
0
0
1
1
0
1
0
1
1
1
0
0
1
1
+
4
0
0
1
0
0
1
1
0
0
1
0
1
0
1
1
1
0
1
1
1
1
1
0
1
+
1
5
Each bit in the byte is shifted either to the left or the right by a set number of places.
The spaces left from the value shifted are replaced with 0 values.
6
00111011
7
It could potentially remove data that is vital. All text in a file is likely to be required,
so none can be removed.
8
Yes, as it will remove some of the detail, such as reducing the number of colours used
to create the image.
9
Yes, as it will remove some of the natural background noises, etc. from the recording,
so it won’t be as close to the original.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 1 continued
Skills focus 1.1 questions
1
15
2
0110
3
1001
4
00111010
5
01111011
6
255
7
99
8
25 225
32768
16384
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1
0
1
1
0
0
0
1
0
1
0
0
0
1
0
0
1
Skills focus 1.2 questions
1
10100010
2
9D1
3
15E
4
940
Skills focus 1.3 questions
1
Three times
2
1 500 000
Exam-style questions
1
2
2
a
It is a continuous stream of data that is processed by humans.
b
It is discrete data that has two values, 1 and 0, and is processed by computer.
Four from:
•
A denary number system is a base 10 system, whereas a binary number system is a
base 2 system.
•
The units in a denary number system increase by 10, whereas the units in a binary
number system increase by 2.
•
A denary number system uses the values 0 to 9, whereas a binary number system
uses the values 0 and 1.
•
A denary number system cannot be processed by a computer, whereas a binary
number system can be processed by a computer.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 1 continued
3
a
b
4
One mark for two correct nibbles, two marks for three, for each conversion
•
0010 0001 1010
•
1001 0000 1101
09C
a
One mark for one correct nibble, two marks full correct answer, one mark for
demonstration of working, e.g. carried bits shown
1
0
1
0
1
1
0
1
1
0
1
1
1
1
0
1
1
1
1
1
1
0
0
1
0
0
1
1
1
0
+
b
5
6
One mark for 10111000
One mark for correct working, one mark for correct answer.
•
Convert 28 to binary number (00011100)
•
Invert the values (11100011)
•
Add 1 to get final answer (11100100).
a
Any one from: Compress the image; reduce the resolution; reduce the colour depth.
b
Two marks for two stages of working, one mark for the correct answer.
•
150 × 250 = 37 500 (number of pixels per image)
•
37 500 × 16 = 600 000 (number of bits per image)
•
600 000 / 8 = 75 000 (number of bytes per image)
•
75 000 / 1024 = 73.24 (number of KiB per image)
•
73.24 / 1024 = 0.07 (number of MiB per image)
•
0.07 * 20 = (number of MiB for 20 images) = 1.43 = 1.4 MiB
NOTE: There can be several different ways of working and any two viable stages can
be awarded.
7
a
b
8
3
Any two from:
•
less storage space required
•
less time for webpage to load for readers
•
quicker to upload content to the blog.
Four from:
•
A compression algorithm is used.
•
Patterns of notes in the file are identified
•
… and grouped with an index.
•
No data is permanently removed from the file.
1050 MiB
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 2: Data transmission
Discussion questions
1
The answer will depend on the students.
2
This will be an open-ended discussion.
Questions
1
They are the packet header, the payload and the trailer/footer.
2
It includes the destination address, the packet number and the originator’s address.
3
The payload
4
The transmission media, such as the wires and radio waves, would not be able to
transmit large amounts of data. It needs to be broken down into smaller units so that
it can be sent using these.
5
Parallel. It will allow the data to be transmitted quicker to the printer, to allow more
leaflets to be processed per minute. It is also only a short distance, so parallel data
transmission will still be reliable.
6
Serial
7
Parallel
8
Serial half-duplex
9
Any two from:
•
There is less chance of data being skewed or out of sequence, as it is sent one bit at
a time.
•
There is less chance of interference that could corrupt data, as only a single
wire used.
•
It is cheaper to manufacture or set up, as only a single wire used.
•
It is more reliable over a longer distance.
10 Any two from:
•
It can only be used over a limited distance.
•
There is more chance of interference as multiple wires are used.
•
There is more chance of errors in data as it is sent, multiple bits at a time and out
of sequence.
•
It is more expensive to manufacture or set up, as multiple wires are used.
11 Serial full-duplex. The distance is too far to use a parallel cable. The customer data is
valuable so it needs to be correct and serial transmission will have less chance of error,
because a single wire is used, so less interference or skewing of data. It needs to be
full-duplex as this is the only transmission method that will allow data to be sent in
both directions at the same time.
12 Universal serial bus
13 Serial
4
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 2 continued
14 Any two from:
•
It is a universal standard.
•
The cable can only be inserted one way into the port, so this helps prevent
incorrect connections.
•
It supports different transmission speeds.
•
It is backward compatible, so USB2 cables can be inserted into USB3 ports.
•
It can power another device whilst transmitting data.
•
Devices are automatically detected when connected.
•
The data transmission speed is relatively high.
15 Five of, e.g. keyboard, mouse, mobile phone, speaker, web camera, microphone.
16 5 metres. It is limited so that the data transmission rate can be kept fairly high.
It would deteriorate over a greater distance.
17 c (10101000)
18 c (10001000)
19 If an even number of bits had been transposed / interchanged, as it would still add up
to an odd or even number, depending on the parity used.
20 The actual data / payload that is being transmitted.
21 It is attached / appended to the data that is being transmitted, so that it is transmitted
with the data.
22 If the same calculation is performed on the data, it should get the same result. If the results
are different, the data must have changed during transmission, meaning that errors must
have been introduced.
23 No. It could be possible that the data arrived correctly, but that errors occurred in
the data when it was being transmitted by back the sender.
24 Encryption key
25 Cipher text
26 No. The data can still be stolen, as the hacker can still take it. It will just be meaningless
to the hacker, as it will be scrambled.
27 The same key is used in symmetric, and is transmitted with the data, so if a perpetrator
steals the data, it is likely they will also have the key to decrypt it. Two different keys are
used in asymmetric encryption and both are needed to decrypt the data. It makes it
much more difficult for a perpetrator to obtain both keys to decrypt the data.
Exam-style questions
1
5
Any two from:
•
destination address
•
packet number
•
originator’s address.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 2 continued
2
3
4
5
Any two from:
•
ach data packet is sent individually, possibly along a different route, so it could arrive
E
out of sequence.
•
The receiving device reads the packet number from the header and reorders
the packets based on this value.
Any two from:
•
Bits of data are sent down a single wire.
•
Bits of data are sent one at a time.
•
Data can be sent in both directions
•
… but only one direction at a time.
Any two from:
•
It is a universal standard.
•
The cable can only be inserted one way into the port, so this helps prevent incorrect
connections.
•
It supports different transmission speeds.
•
It is backward compatible, so USB2 cables can be inserted into USB3 ports.
•
It can power another device whilst transmitting data.
•
Devices are automatically detected when connected.
•
Data transmission speed is relatively high.
Two from:
•
Serial
•
Full duplex
And four from:
6
•
The distance is too far to use a parallel cable.
•
The data will have less chance of error
•
… because a single wire is used, so less interference or skewing of data.
•
It needs to be full duplex as this is the only transmission method that will allow data
to be sent in both directions at the same time.
One mark for each correct row:
Statement
This method checks for errors in data after it has
been transmitted.
This method can use an odd or even process.
This method sends data back from the receiver to
the sender to compare the data to check for errors.
This method uses a value that is calculated from
the data to check for errors.
7
6
Checksum
(✓)
✓
Echo Check
(✓)
✓
Parity Check
(✓)
✓
✓
✓
✓
✓
One mark for each correct term in the correct order: plain text; key; cipher text;
meaningless; decrypted; the same.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 3: Hardware
Discussion questions
1
The answer will depend on the students.
2
This will be an open-ended discussion.
3
The answer will depend on the students.
Questions
1
RAM
2
Control unit
3
To transmit data or signals in the fetch-execute cycle.
4
It needs it to store interim results of calculations. If it did not have the accumulator,
it would need to write and read the interim result to and from RAM each time.
5
7
Component
Description
Program counter (PC)
A register that holds the address of the next instruction to
be processed.
Memory address register (MAR)
A register that stores the address of where data or an
instruction is located in RAM.
Memory data register (MDR)
A register that stores data or an instruction when it is
fetched from RAM.
Control unit (CU)
A component that sends signals to control the interactions
of all other components during the fetch-execute cycle.
Current instruction register (CIR)
A register that holds the instruction that is currently being
processed.
Arithmetic logic unit (ALU)
A component that performs all calculations and logical
operations required during the fetch-execute cycle.
Accumulator (ACC)
A register that is built into the ALU that is used to store the
interim results of calculations.
Address bus
A bus that is used to transmit addresses within the CPU and
to, and from RAM.
Data bus
A bus that is used to transmit data or instructions within the
CPU, and to and from RAM.
Control bus
A bus that is used to transmit control signals that are sent by
the control unit.
6
Quad
7
4 800 000 000
8
If there are a large amount of frequently used data and instructions stored, it will take
longer for the CPU to search through the cache to find the one it is looking for.
It could be quicker in this case for the CPU to get the instruction or data from RAM,
rather than searching a large amount of data in a large cache to find it.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 3 continued
9
10
8
There are many other example uses than those given:
Input device
Description of data input
Example of use
Barcode
scanner
It scans a barcode so that the
data stored in the barcode can be
obtained.
It is used in a supermarket to get the
price of a product and as part of a stock
control system.
Digital camera It captures light through a lens and
converts it into binary.
It is built into a mobile phone to allow
the user to photograph items or people.
Keyboard
It allows the user to press keys that
have a designated ASCII/Unicode
value that is converted to binary.
It is one of the main methods of input
that allows a user to type data into a
personal computer.
Microphone
It captures soundwaves and
converts them to binary.
It is built into a mobile phone to capture
the user’s voice so that it can be heard
by the other users.
Optical mouse It captures the light that is bounced
back from a laser that is shone
from the mouse to the surface
underneath, to track the mouse’s
movements.
It is one of the main methods of input
that allows a user to select icons and
menu options whilst using a personal
computer.
QR code
scanner
It uses a sensor or a camera to
capture light reflected from a QR
code and converts it to binary.
It can be an application that is
downloaded onto a mobile phone and
used to SCAN QR codes that store
information, e.g. a website link.
Scanner (2D
and 3D)
They use sensors to capture light
that is reflected from a 2D or 3D
object and convert it to binary.
It can be used to scan 3D objects to
create a digital copy of them.
Touch screen
(resistive,
capacitive and
infra-red)
They use pressure, conductivity or
light to register the touch of a user
on a screen. The coordinates of the
touch can be calculated.
It is built into a ticket machine to allow
a user to select which ticket they would
like to buy.
Output
device
Description of data output
Example of use
Actuator
It is a component that outputs an
action, often a type of movement,
that causes another device to
operate.
It can be used in an automated system
to move or turn on/off another device,
e.g. a light.
Digital light
processing
(DLP)
projector
It is a device that uses light
reflected from millions of little
mirrors to output an image.
It can be used in a classroom to project
an image onto an interactive whiteboard.
Inkjet printer
This is a device that squirts liquid
ink from nozzles to output a
document or image.
It can be used in a house to print
photographs.
Laser printer
This is a device that uses a rotating
drum and powdered toner to
output a document.
It can be used in an office to print letters.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 3 continued
Output
device
Description of data output
Example of use
Light emitting
diode (LED)
screen
This is a screen that uses LEDs as a
backlight to output an image.
This screen can be built into a mobile
phone.
Liquid crystal
display (LCD)
projector
This is a device that shines light
through crystals and then through
a lens to project an image onto a
blank wall or screen.
This can be used to project an image in
a home cinema system.
Liquid crystal
display (LCD)
screen
This is a screen that shines light
through crystals to output an
image.
This can be built into a television screen.
Speaker
This is a device that outputs sound.
This can be built into a mobile phone
so one user can hear another user’s voice
3D printer
This is a device that builds layers of
material to output a 3D object.
This can be used in medicine to create
prosthetic limbs.
11 Input
12 Any five from:
•
acoustic
•
accelerometer
•
flow
•
gas
•
humidity
•
infra-red
•
level
•
light
•
magnetic field
•
moisture
•
pH
•
pressure
•
proximity
•
temperature.
13 Any valid example, such as:
9
a
Light – To automatically turn a car’s headlights on, when it is dark.
b
Magnetic field – To operate an ABS braking system in a car.
c
Temperature – In a kettle, to turn off the heating element when the water is boiling.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 3 continued
14 Any two from:
•
They are more accurate than a human.
•
They can monitor 24/7 as they don’t need to take a break like a human.
•
Their use can mean that humans can complete other tasks that require more thought.
•
Their use can stop humans getting bored doing repetitive tasks.
•
Their use means that humans don’t need to go into dangerous environments
to monitor and control them.
15 It could help detect when the hard drive is falling through the air and turn the device off,
to try to help prevent damage to data.
Exam-style questions
1
a
b
c
2
10
i
RAM
ii
Program counter / PC
iii
Any three from:
•
The instruction is sent to the control unit.
•
The control unit decodes the instruction by converting it to binary.
•
It does this using an instruction set
•
… which is a set of all the commands that are understood by the CPU.
i
2
ii
Two from:
•
Two instructions can be processed at the same time
•
… which helps data be processed quicker by the CPU.
i
Primary
ii
One mark for each type of storage:
•
RAM: Programs and data that are currently is use.
•
ROM: Start-up instructions, such as the BIOS.
One mark per each correct sensor
Scenario
Most appropriate sensor
To monitor the amount of pollution in a river.
pH
To count the number of competitors who finish a race.
Magnetic / pressure / Infra-red
To detect a person who is approaching an automatic
door system.
Infra-red
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 3 continued
3
a
i
ii
b
i
ii
4
Any two from:
•
CD
•
DVD
•
Blu-ray.
Six from:
•
A laser is directed at a reflective surface on a disk.
•
The disk is spun.
•
A read / write head that contains the laser is moved across the surface of
the disk.
•
The laser burns pits into the surface of the disk.
•
It starts at the centre of the disk and works outward in a spiral track.
•
Each pit represents a binary value.
Any one from:
•
They do not have to pay for the hardware to store the data.
•
They do not have the responsibility for the security of the hardware that
stores the data.
•
They can access the data and resources using different devices from anywhere
that has an Internet connection.
•
They can increase and decrease the amount of storage space that they need
very easily, on demand.
Any two from:
•
They are relying on a third party making sure that their data is safe.
If they do not do this correctly, they might put their data at risk.
•
If their connection fails or is not available, they will not be able to access
their data.
•
If their connection is slow, this can also mean that accessing their data is slow.
Any two from:
•
It is a numerical.
•
It uses 32 bits.
•
Each section is separated using full stops / periods / dots.
Chapter 4: Software
Discussion questions
11
1
E.g. easier to make an error, harder to debug
2
E.g. easier for people to write programs, more accessible to others, increase in
user-friendly interfaces for a range of users
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 4 continued
Questions
1
E.g. word processor, database, spreadsheet. Do not allow brand names.
2
To manage the hardware and software and allow these to communicate.
3
The application software runs on the operating system. The operating system runs on
the firmware. The firmware is loaded by the bootstrap.
4
E.g. create a file or directory, name a file or directory, move a file or directory, put a file
in a directory
5
Software, e.g. division by 0, attempt to access memory location not accessible.
Hardware, e.g. printer out of paper, pressing a key on the keyboard.
6
The interrupt handler determines where the interrupt goes in the queue, based on the
priority. When a FDE cycle finishes, the interrupt queue is checked. If there is a higher
level interrupt than the current process, the current process is stored. The ISR for
the interrupt is run. When finished, the current process is reinstated.
7
It uses English-style statements. It needs to be translated to a low-level language to
be run. It is portable / machine-independent.
8
Assembly; High-level; Machine code
9
Low-level language: Allows direct manipulation of hardware, reducing the memory that
the program uses.
10 Assembler, interpreter and compiler
11 Interpreter - whilst writing the program code. It allows Nasrat to make corrections
without having to restart the program each time.
Compiler Either: Whilst writing the program, because it gives all the errors together so they can all
be corrected before starting the program.
Or: When the program is finished. It can be tested without having to re-compile each time.
It produces an executable file - this means the source code does not need to be released
(so it cannot be copied or amended) and the user can run the program without
the translator.
12 Run-time environment, allows the user to interact with the program. Breakpoints, to stop
the code at specific points and check the variables. Stepping, to run the code one line at
a time to check the values. Variable watch window, displays the variable values while
the program runs.
Skills focus 4.1 questions
12
1
The interpreter will stop at an error so that Saria can correct it in real-time and then
continue where the program stopped.
2
The compiler will produce an executable file, this means that Saria can distribute
the software without having to give users the source code, and it saves time when testing
multiple times as it does not have to interpret the code each time.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 4 continued
Exam-style questions
1
One mark for four correct, two marks for 5 correct, three marks for 6 correct, four marks for 6 correct,
five marks for all correct.
System software
Word processor
✓
Defragmentation
✓
Operating System
✓
Image manipulation
System clean-up
2
3
Application software
✓
✓
Database
✓
Web browser
✓
One mark per bullet:
•
An interrupt is a signal
•
... that tells the processor its attention is needed.
One mark for system software definition, e.g. allows the hardware and software to run
and communicate.
One mark for application software, e.g. software that allows the user to perform useful tasks.
One mark for an example of each, e.g. system = OS, application = word processor.
Do not award brand names. It must be clear which type of software each example refers to.
4
a
b
5
13
One mark per bullet to max three.
•
It allocates memory to processes.
•
It moves data between memory.
•
E.g. It fetches data from RAM.
•
It stores data in RAM.
•
It prevents two processes from accessing the same memory location.
One mark each from:
•
Managing files
•
Handling interrupts
•
Providing an interface
•
Managing peripherals and drivers
•
Managing multitasking
•
Providing a platform for running applications
•
Managing user accounts.
One mark per bullet to max five.
•
The interrupt handler puts the interrupt in the queue depending on its priority.
•
The processor finishes the current FDE cycle.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 4 continued
6
7
•
It checks if there is a higher level interrupt,
•
if there is, it stores the current contents of memory…
•
... it then accesses the ISR for that interrupt…
•
... when finished it reloads the current contents of memory and continues,
•
if not, it processes the next instruction.
One mark for each completed section:
•
Operating System
•
Bootstrap program.
a
One mark per bullet, max three for low-level, max three for high-level.
Low-level language:
•
Machine code or assembly language
•
(Machine code) does not need translating for the computer to run the code
•
Not portable.
High-level language:
b
•
Written in human-understandable / English language
•
Needs translating into low-level language before it can be run
•
Is portable
•
Is easier for humans to read / write / debug, etc.
One mark per bullet.
•
It is easier for the person to read and write the code
•
... because it is in more English-style syntax.
•
It is easier for the person to debug.
•
It is portable / machine-independent…
•
... so it can be used on different computers.
c
One mark for: to write a more memory efficient program.
d
One mark for translator, compiler or interpreter. One mark per bullet for justification.
Justification must match translator.
Interpreter:
14
•
It runs the code and stops when an error is found
•
… this means Qui can correct the error and continue running the program from
that position.
•
Qui can add a small section to the program and test it
•
... without having to create a complete code that is all syntactically correct.
•
A compiler would report all the errors at the end
•
… so Qui cannot test small sections of the program.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 4 continued
Compiler:
e
8
15
•
Qui will get a report of all the syntax errors
•
... so that he can correct them all before running the whole program without it
stopping.
One mark per bullet to max six.
•
Qui can an editor to write the code.
•
Pretty printing ...
•
… will colour key words to help identify errors.
•
He can use auto-complete so that ...
•
... he can enter part of a word and it will give him options to select and reduce
the chance of errors.
•
Qui can use the run-time environment ...
•
…to show the output and allow inputs from the user.
•
It has error diagnostics and a ...
•
... breakpoint to ...
•
... stop the code at a set point to check the values.
•
Stepping will ...
•
... run the code one line at a time to view how the values change and the order
the program runs.
•
Qui can use the variable watch window …
•
... to see how the values change.
One mark per bullet to max eight. Max four for naming functions.
•
It allows the user to communicate with hardware.
•
It runs the hardware.
•
It provides a platform for software to run.
•
It manages files ...
•
... allowing users to create / rename / move files and,
•
and allowing users to create / rename / move directories / folders.
•
It handles interrupts
•
... so that when a device needs the attention of the process it adds it to the interrupt queue
•
... and it uses the interrupt service routine to perform the required functions.
•
It provides an interface ...
•
... such as GUI / command line
•
... to allow the user to input data and receive output.
•
It manages peripherals and devices,
•
... installs device drivers
•
... and sends data to the device / fetches data from the device.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 4 continued
•
It manages memory,
•
... allocates memory to running processes,
•
... avoids two processes accessing the same memory and
•
…moves data between memory, e.g. RAM and HDD.
•
It manages user accounts
•
... allowing for security / sets username and passwords.
Chapter 5: The internet and its uses
Discussion questions
1
The answer will depend on the students.
2
The answer will depend on the students.
3
There will be an open-ended discussion.
Questions
1
It is a text based address for a website.
2
It is a unique address that is given to a device, such as a computer or a web server.
It is often allocated by a router. It can be static or dynamic.
3
Protocol; domain name; web page name or file name
4
It is a certificate given to a website company that can be produced to show that the
website is authentic and secure. It is stored on the web server and is requested by the web
browser when the HTTPS protocol is used. The web browser checks the authenticity of
the digital certificate.
5
Web browser
6
To store personal data about a user
7
A session cookie is deleted when the web browser is closed. A persistent cookie is deleted
only when its expiry date is reached, or it is manually deleted by the user.
8
Cookies build up an online profile that some users believe can be used to target them for
criminal activity, such as stealing their identity. Other users think it is an invasion of their
privacy to build this kind of online profile.
9
A hacker is a perpetrator who gains unauthorised access to data.
10 Use security methods such as:
16
•
a firewall
•
automatic software updates
•
strong or biometric passwords
•
two-step verification.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 5 continued
11 Use anti-malware software to find any malware that may be redirecting website requests
and visually checking the web page. Also, only download data from trusted sources.
12 You could check:
•
if the URL at the top of the screen is the correct one
•
if the site is secured using HTTPS
•
if the website looks like it normally does, such as the usual colours and placement
of items.
Exam-style questions
1
The internet
2
a
b
•
protocol
•
domain name.
Domain name server / DNS
3
One mark per each correct term in the correct order: web browser; domain name server;
web server; HTTP / HTTPS; HTML.
4
a
b
5
6
Any two from:
•
It provides an address bar that you can use to type in a URL.
•
It keeps a record of all the web pages that you have visited.
•
It allows you to bookmark web pages and set web pages as your favourites.
•
It allows you to open multiple tabs at a time.
•
It allows you to navigate between web pages.
Session cookie
One mark for one bullet, from:
•
Transactions that have been recorded cannot be changed.
•
Anyone can view the transactions that have been made.
a
One mark for one bullet from:
b
17
Any one from:
•
A proxy server can be used.
•
Users can scan their computers with anti-malware software to prevent it being
used as a bot.
Any three from:
•
The user is encouraged to click an infected link / download
•
... this triggers a download of malware onto the user’s computer
•
… that turns the user’s computer into a bot.
•
Multiple bots are created from users’ computers that are all part of a network.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 5 continued
7
One mark for each of the following shown in the diagram:
•
Data packets are being sent from one computer to another.
•
A packet sniffer has been installed on a device on the route, e.g. router.
•
A packet sniffer is examining each packet that passes through it.
Router
Device 1
Device 2
Data packets
sent to device 2
Packet sniffer installed onto
router that examines packets
that pass through
8
9
18
One mark per each correct line to a max of three.
Security solution
Description
Firewall
This is a protocol that encrypts data that is sent
across the internet.
Anti-malware
This is software that can be used to scan a
computer for malicious files.
Access levels
This can be hardware or software based and it
examines traffic incoming and outgoing from a
computer system or network.
SSL
This is connected to a user’s username and
provides information about what data the user is
allowed to access on a system.
Two marks (one per method, one per explanation) for two methods
(for a total of four marks) from:
•
Phishing: a link sent to a user via email has encouraged the user to type their login
details into a fake website.
•
Pharming: malicious software has been downloaded onto the user’s computer that
has redirected the user to a fake website where they have typed their details.
•
Spyware: key presses from the user’s computer have been sent to a third party and
analysed for patterns revealing login details.
•
Social engineering: a perpetrator has manipulated the user into providing their
login details.
•
Brute-force attack: a perpetrator has used software to repeatedly enter password
combinations until the correct one is found.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 6: Automated and emerging
technologies
Discussion questions
1
This is dependent on the learner, e.g. it could be the ability to adapt, the ability to learn
or the ability to make decisions.
2
This is dependent on the learner as there is no right answer, e.g. asking it questions,
attempting to teach it something new, could test it against a human’s output.
3
This is dependent on the learners, as some may consider that they should and some may
think otherwise.
Questions
1
Digital
2
It reads data from the environment and sends it to an ADC.
3
a
Infra-red, proximity
b
Data is converted from analogue to digital.
c
The microprocessor
d
It compares the data to its stored value. If it is in range or it matches the stored value,
it sends a message to the actuator to open the doors.
e
It will run forever or until the system is turned off.
4
Benefits, e.g.
•
faster response
•
more accurate
•
does not need to rest.
Drawbacks, e.g.
5
19
•
initial cost
•
maintenance costs
•
may have been programmed incorrectly
•
can be hacked.
E.g.
•
It can run all day every day ...
•
... whereas people would have to work in shifts.
•
It will be more precise …
•
... which will give more accurate results.
•
It may have an initial high cost ...
•
... because the hardware and software will need purchasing.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 6 continued
•
The jobs of the people who usually monitor the weather may be lost ...
•
... but new jobs may be created to maintain the system.
6
It is a mechanical device that moves and that simulates human movement.
7
E.g.
8
•
manufacturing of an object, e.g. car
•
testing products
•
moving products.
Benefit: e.g. saves people time from having to perform repetitive tasks.
Drawback: e.g. initial cost may be high.
9
Algorithms control the movement of the cars.
Benefits include: more precise and can react faster, therefore safer. Not prone to human
error or distraction. People do not need to learn to drive, therefore more people will be
able to use the cars.
Drawbacks include: risk if the programs are hacked, initial cost will be high.
10 It means: a program / computer designed to mimic human behaviour / intelligence.
11 It means: an AI program that can adapt its knowledge and/or programming without
the need for human interaction.
12 It is to mimic the knowledge of a human expert.
13 E.g. diagnosing illness, troubleshooting computers.
14 Knowledge base - the facts.
Rule base - logical statements derived from the knowledge.
Skills focus 6.1 questions
1
E.g. a pressure sensor will continuously send data to the microprocessor that is converted
to digital.
2
E.g. the microprocessor will compare the data to the stored value / weight. If the value meets
(or is greater than) than the stored data it will send a signal to an actuator to open the door.
3
E.g. when the sensor has not detected a person for 5 seconds.
Exam-style questions
1
a
E.g. troubleshooting, diagnostics.
b
One mark for each word.
An expert system is made up of four parts. The knowledge base is the set of facts.
The rule base is a set of logical rules. The inference engine applies the two bases
to decide what questions to ask next and to work out the response. The interface is
the elements that allow the user to input data and to output data to the user.
20
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 6 continued
2
3
4
Any three from:
•
mechanical structure / framework
•
electrical components
•
sensors
•
microprocessors
•
actuators
•
programmable.
One mark per bullet to max six.
•
Infra-red sensors are used
•
... and they send a signal to the microprocessor.
•
The signal is converted from analogue to digital.
•
The microprocessor compares the signal to its stored distance value
•
... and if the value is less than the stored distance it sends a signal
•
... to an actuator
•
... to play the sound
•
... and the process is continuous.
One mark for a description, e.g. Machine learning is when an AI program can change its own
data or rules.
One mark for an example, e.g. a computer game AI can learn which moves are successful
and which are not, e.g. an image recognition system can learn how to recognise objects in
an image.
5
One mark per bullet, max four for advantages, max four for disadvantages.
Advantages e.g.
•
Long-term costs may be reduced
•
... e.g. fewer wages to pay.
•
The factory can work all day every day.
•
Robots may be more precise.
•
Robots will make fewer errors / no human error.
•
New jobs will be created in their maintenance.
Disadvantages e.g.
21
•
The initial cost will be high.
•
People will lose their jobs.
•
They are expensive to fix if broken.
•
The robots have limited actions they can perform.
•
It is expensive to change any robotic processes.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 6 continued
6
7
8
One mark each, e.g.
•
Self-driving cars
•
Managing the movement of items in a factory, e.g. for loading lorries.
One mark per bullet to max four.
•
They can employ machine learning.
•
It can be used supervised or unsupervised.
•
Sounds are input and the system is told what users are saying
•
... this is repeated many times with different variations.
•
Sounds are input and the system has to categorise them …
•
... into those that are similar.
a
E.g. harvesting the crops, watering when there is no rain, packaging crops.
b
One mark each, e.g.
c
9
22
a
•
They are productive / the farmer can perform other tasks at the same time.
•
The farmer gets better harvest / crops by keeping them watered without having
to check them continually.
•
Fewer accidents / automated system not prone to human error.
One mark each, e.g.
•
Initial cost could be very high.
•
Any problems with the systems will be expensive to fix.
•
Jobs will be lost.
One mark per bullet to max six, e.g.
•
They can receive input using sensors
•
… e.g. infra-red to detect movement
•
… e.g. pressure to detect if they are being touched
•
… e.g. acoustic to detect sound.
•
Image recognition can be used to identify what has moved
•
... e.g. if it is another animal.
•
A set of possible movements are stored
•
… e.g. move head towards the other animal
•
... one of these can be chosen depending on the image detected.
•
Speech recognition can be used to identify the sounds recorded
•
... e.g. the species of an animal
•
… and then react, e.g. perform an action.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 6 continued
One mark per bullet to max six, e.g.
b
•
Human interaction is not needed
•
... and will not cause fear.
•
They can record the animals’ natural behaviour
•
… because they will not be influenced by people.
•
Animals might not act naturally
•
... because there is a new item present.
•
Animals could attack the robots
•
... and cause damage or hurt themselves.
•
Robots can record all day every day
•
... whereas humans will need to stop.
Chapter 7: Algorithm design and
problem solving
Discussion questions
1
An event driven language has code that is only run when an event happens, such as
when a button is clicked or an option is selected from a drop-down box.
2
E.g. office software such as word processors and spreadsheets would benefit from
an event-driven language. A computer game would be better written in a procedural or
object-oriented language.
Questions
1
It means splitting a problem / system down into subproblems/subsystems.
2
E.g.
Addition
Input
number1
23
number2
Process
Output
total = number1
+ number2
total
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
3
E.g.
Sat-nav
4
Input
Process
Output
Destination
Find route
Directions
E.g.
Login
Process
Input
username
5
password
search for
username and
password
Compare
username and
password
Output
Correct
Incorrect
re-enter
a
Start/Stop
b
Process
c
Decision
d
24
Input/
Output
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
6
a
b
and c
d
e
f
7
START
INPUT x, y, z
IS x > y AND
x > z?
YES
OUTPUT x
NO
IS y > x AND
y > z?
YES
OUTPUT y
NO
OUTPUT z
STOP
25
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
8
9
The purpose of pseudocode is to design an algorithm in a non-specific
programming language.
Statement
x  x + 1
Appropriate
INPUT z
✓
IF y < 6 THEN
✓
Not appropriate
✓
add 3 to the value entered
✓
store the value entered in the
variable newValue
value1  INPUT("Enter a number")
✓
✓
IF number is more than 10
WHILE number1 <> 0
✓
✓
10 E.g.
INPUT Number1
INPUT Number2
INPUT Number3
Result  Number1 * Number2 * Number3
OUTPUT Result
11 E.g.
Total  0
FOR X  0 TO 9
Number  INPUT
Total  Total + Number
NEXT X
OUTPUT "The total is ", Total
12 Any three of: normal, abnormal, extreme, boundary.
13 Extreme tests data that is on the edge of what is allowed and normal tests any values that
are allowed.
14 Extreme only tests the valid boundary whereas boundary tests just inside and outside of
the boundary.
15
Test type
Test data
Normal
1 2 3 4 5 6 7 8 9 10
Abnormal
Anything < 1 or > 10, or characters, e.g. "a"
Extreme
1 10
Boundary
0 1 10 11
16 Compare to 10; compare to 5; compare to 6; found
26
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
17 Compare to b; compare to u; compare to l; compare to p; compare to f; found
18
19
1
5
6
2
9
0
1
1
5
2
6
9
0
1
1
5
2
6
0
9
1
1
5
2
6
0
1
9
1
2
5
6
0
1
9
1
2
5
0
6
1
9
1
2
5
0
1
6
9
1
2
0
5
1
6
9
1
2
0
1
5
6
9
1
0
2
1
5
6
9
1
0
1
2
5
6
9
0
1
1
2
5
6
9
60
2
40
52
3
5
60
40
2
52
3
5
60
40
52
2
3
5
60
40
52
3
2
5
60
40
52
3
5
2
60
52
40
3
5
2
60
52
40
5
3
2
20 The inefficient algorithm continues to loop and make comparisons even when all
the data is in the correct order.
The efficient algorithm stops as soon as the data has been run through once without
any changes.
21 Totalling adds the values together, counting it adds one for each new value.
22 Smallest - any number above 200; largest - any number below 20
23 E.g.
Total  0
FOR X  0 TO 39
Total  Total + INPUT()
NEXT X
OUTPUT Total
OUTPUT Total / 40
27
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
24 E.g. (N.B. works for numbers between −9999 and 9999)
Smallest  9999
Largest  -9999
FOR X  0 TO 99
INPUT Number
IF Number > Largest THEN
Largest  Number
ENDIF
IF Number < Smallest THEN
Smallest  Number
ENDIF
NEXT X
OUTPUT "The largest is ", Largest
OUTPUT "The smallest is ", Smallest
25 It means checking that data entered is reasonable and within bounds.
26 Any three of: range, length, type, presence, format, check digit.
27 The purpose is to check that data has been entered accurately.
28 Range check
29 Range check
30 E.g.
INPUT Word
IF LENGTH(Word) >= 10
THEN
OUTPUT "Valid"
ELSE
OUTPUT "Invalid"
ENDIF
31 E.g.
INPUT Number
IF Number.IsInteger = TRUE
THEN
OUTPUT "Valid"
ELSE
OUTPUT "Invalid"
ENDIF
28
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
Skills focus 7.1 questions
1
5
2
It is because of the number of (Number of items − 1) = 3, will compare all of the items
with all of the items
3
Change the comparison from less than to greater than.
Skills focus 7.2 questions
1
6
2
Compare the first characters in each string, then if they are the same look at the next
character in each string.
Skills focus 7.4 questions
1
You record variables’ values and outputs.
2
You change the value in a column whenever there is a change.
Skills focus 7.5 questions
1
Students’ answers, e.g. including a negative number.
2
Stop when you have identified the pattern.
3
E.g.
quantity
total
value
small
0
0
0
999
OUTPUT
1
1
100
100
100
2
150
50
50
3
160
10
10
4
193
33
3
5
235
42
small = 10
47
Look at what is output and how it is calculated:
29
•
The smallest number input between 10 and 100
•
The average of the numbers entered that are between 10 and 100.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
Skills focus 7.6 questions
1
Trace table, walk through
2
To demonstrate an understanding of the overall purpose and how this code works
altogether.
3
Takes 10 numbers as input and outputs the largest of the numbers.
Skills focus 7.8
1
total
average
counter
mark
0
0
0
20
20
1
50
70
2
60
130
3
25
155
4
35
190
5
38
output
The total is 190
The average is 38
2
a
number
output
7
7
6
5
4
3
2
1
0
b
3
Outputs the numbers from the one the user enters to 0.
Reads in values from the user until they don’t enter Y to continue. Records and outputs
how many valid numbers are entered - between 10 and 20. Records and outputs how many
invalid numbers are entered.
Exam-style questions
1
It is series of steps that solve a problem.
2
One mark for name, one mark for description:
Design:
30
•
Plan the algorithms for the problem.
•
Decompose the problem using a structure diagram.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
Coding:
•
Write the program code for the program.
•
Include iterative testing.
Testing:
3
4
•
Input data and make sure that the program outputs the correct data.
•
Input a range of data to check if the program works.
One mark per bullet to max two.
•
It splits a system into sub-systems repeatedly.
•
It makes the problem more manageable.
•
It identifies smaller parts that can be programmed independently.
a
One mark per bullet.
•
Write the system name in the top box.
•
Split into at least two parts for level 1.
•
Include start options of load game and new game.
•
Include all four movements as input and correct output.
One possible answer, e.g.
Game
Move
Start
Load game
b
31
New game
INPUT left
arrow
INPUT right
arrow
INPUT up
arrow
INPUT down
arrow
Move
character left
Move
character right
Character
jump
Character lie
down
One mark per bullet.
•
There is an appropriate start.
•
The value is input.
•
There are four decision boxes
•
... with yes and no options.
•
There are process boxes for movement.
•
All lines join and all boxes have arrows in and out.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
E.g.
Start
INPUT move
IS move =
down?
YES
Lie down
NO
IS move = up?
YES
Jump
NO
IS move = left?
YES
Move left
NO
NO
c
IS move =
right?
i
Format / presence / type
ii
One mark per bullet.
YES
•
Input of name
•
Getting length of name
•
Checking length is 8 or more
•
Outputting appropriate messages.
Move right
E.g.
INPUT Name
IF LENGTH(NAME) >= 8 THEN
OUTPUT "Valid"
ELSE
OUTPUT "Invalid"
ENDIF
32
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 7 continued
5
One mark per bullet.
•
Initialising values
•
Inputs the correct colours and quantities
•
Updates blue, white and yellow correctly
•
Outputs how many left for each
•
Outputs Continue? each time.
blue
white
yellow
continue
colour
quantity
10
5
2
Y
blue
5
5
Blue left = 5
Y
Continue?
4
blue
1
Y
3
Y
white
5
x
8
Try again
Continue?
0
7
Blue left = 4
Continue?
yellow
6
output
White = 0
Continue?
One mark per bullet.
•
Compare 100 with first value
•
... and all successive values in order.
•
Report it not found.
One mark for each swap in order.
apple
pear
banana
pineapple
orange
peach
apple
banana
pear
pineapple
orange
peach
apple
banana
pear
orange
pineapple
peach
apple
banana
pear
orange
peach
pineapple
apple
banana
orange
pear
peach
pineapple
orange
banana
orange
peach
pear
pineapple
One mark for each line number and corrected line.
05 FOR X  0 TO 19
07
IF Number < 10 THEN
09
ELSEIF Number = 10 THEN
19 OUTPUT "Average = ", Total / 20
33
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8: Programming
Discussion questions
1
It is so that they can be used / understood by any programmer and so that programmers can
change language easily.
2
This is entirely up to the learners as there are many that could be found, e.g. REPEAT UNTIL.
Questions
1
Statement
Variable
You cannot change the value when the program is running.
✓
It has an identifier.
✓
✓
It is a memory location.
✓
✓
You can change its value when the program is running.
✓
It stores a piece of data.
✓
2
MyWord  "house"
3
CONSTANT MultiplyValue  10
4
a
30
b
10
c
400
d
35
e
10
f
6
g
0
h
4
5
Constant
✓
Number  INPUT("Enter a number")
Number  Number * 2
OUTPUT Number
6
CONSTANT Number1  10
CONSTANT Number2  12
Result  Number1 + Number2
OUTPUT(Result)
7
Name  INPUT("Enter your name")
Age  INPUT("Enter your age")
OUTPUT("Hello " & Name & " you are " & Age & " years old)
34
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
8
It is a programming construct where code is run, or not run, depending on a condition.
9
IF and (SELECT) CASE
10 Num1  INPUT("Enter the first number")
Num2  INPUT("Enter the second number")
IF Num1 > Num2 THEN
OUTPUT(Num1)
ELSE
OUTPUT(Num2)
ENDIF
11 Answer  50
Guess  INPUT("What is 5 * 10")
IF Guess = Answer THEN
OUTPUT("Correct")
ELSE
OUTPUT("Incorrect. It is 50.")
ENDIF
12 Colour  INPUT("Enter a colour")
CASE OF Colour
"yellow": OUTPUT("Yellow is very bright")
"green": OUTPUT("Green is like the trees")
"blue": OUTPUT("Blue is like the sky")
OTHERWISE: OUTPUT("You need to enter yellow, green or blue")
ENDCASE
13 Pre-condition tests the condition before starting the loop, post-condition runs the code
then tests the condition.
In pre-condition the code in the loop may never run, in post-condition the code in
the loop will at least run once.
14 Count-controlled
15 FOR Count  100 TO 200
OUTPUT(Count)
NEXT Count
35
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
16 FOR Count  1 TO 12
OUTPUT(Count * 5)
NEXT Count
17 REPEAT
Number  INPUT("Enter a number")
UNTIL Number = 10
18 Word  INPUT("do you want to stop?")
WHILE Word <> "stop" DO
OUTPUT("Hello")
Word  INPUT("you want to stop?")
ENDWHILE
19 Counter  1
WHILE Counter < 11 DO
OUTPUT(Counter * Counter)
Counter = Counter + 1
ENDWHILE
20 Initialise the variable to 0. Add the values to the total.
21 Initialise the count variable to 0. Add 1 to the variable for each item.
22 Total  0
FOR X  1 TO 100
Total  Total + INPUT("Enter a number")
NEXT X
OUTPUT Total
23 LessThan100  0
MoreThanEqualTo100  0
NumberInput  1
WHILE NumberInput <> 0 DO
NumberInput  INPUT("Enter a number")
IF NumberInput < 100 THEN
36
LessThan100  LessThan100 + 1
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
ELSE
MoreThanEqualTo100  MoreThanEqualTo100 + 1
ENDIF
ENDWHILE
24 A selection inside a selection; an iteration in an iteration; a selection in an iteration;
an iteration in a selection
25 12
26 WORLD
27 StringInput  INPUT("Enter a string")
CountNumbers  0
FOR Letter  0 to LENGTH(StringInput) - 1
Character  SUBSTRING(StringInput, Letter, 1)
IF Character = "0" OR Character = "1" OR Character = "2" OR Character
= "3" OR Character = "4" OR Character = "5" OR Character = "6" OR
Character = "7" OR Character = "8" OR Character = "9" THEN
CountNumbers  CountNumbers + 1
ENDIF
NEXT Letter
OUTPUT("There are ", CountNumbers ", numbers")
28 StringInput  INPUT("Enter a string")
FOR Count  LENGTH(StringInput) - 1, 0)
OUTPUT(SUBSTRING(StringInput, Count, 1))
NEXT Count
29 A function returns a value whereas a procedure does not return a value.
30 6
31 OUTPUT(FindValue(100))
32 PROCEDURE Largest(Num1, Num2, Num3)
IF Num1 > Num2 AND Num1 > Num3 THEN
OUTPUT(Num1)
ELSEIF Num2 > Num3 THEN
OUTPUT(Num2)
37
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
ELSE
OUTPUT(Num3)
ENDIF
ENDPROCEDURE
33 FUNCTION ReturnString(String1, String2)
NewString  SUBSTRING(String1, 0, 3) & SUBSTRING(String2, 0, 3)
RETURN NewString
ENDFUNCTION
34 They split the code into smaller sections. Each section has a name that describes it.
A subroutine only needs to be changed once, and it will change every time it is used.
35 Comments – they describe what the code does, so other people can understand its purpose.
Meaningful identifiers – they describe what the variables, etc. do so that people can
understand their purpose.
36 RANDOM(1, 5)
37 3.1
38 A variable can store 1 value whereas an array can store multiple values.
39 It stores different data types whereas arrays can only store one data type.
40 For Count  0 TO 9
MyNumbers[Count]  INPUT("Enter a number")
NEXT Count
41 Total  0
FOR Count  0 TO 99
Total  Total + MyNumbers[Count]
NEXT Count
42 FUNCTION SearchArray(SearchValue)
FOR Row  0 TO 19
FOR Column  0 TO 4
IF MyData[Row, Column] = SearchValue THEN
RETURN TRUE
ENDIF
38
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
NEXT Column
NEXT Row
RETURN FALSE
ENDFUNCTION
43 It is so that they can be accessed next time the program loads, or so that the data is not
lost when the program stops running.
44 •
Open the file.
•
Write the data.
•
Close the file.
45 OPEN "dataStore.txt"
Value  READ("dataStore.txt")
CLOSE "dataStore.txt"
OUTPUT(Value)
46 Filename  INPUT("Enter the filename")
OPEN Filename
WRITE("house")
CLOSE Filename
Skills focus 8.1 questions
1
2
a
4
b
5
a
1
b
2
Skills focus 8.2 questions
1
2
39
a
If 1 is less than 2
b
If 6 is greater than 3
c
If 999 is greater than or equal to 998
d
If 34 is less than or equal to 77
a
False
b
False
c
False
d
True
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
Skills focus 8.3 questions
1
Count  0
WHILE(Count < 101) DO
OUTPUT(Count + Count)
Count  Count + 1
ENDWHILE
2
New  100
WHILE(New < 112) DO
OUTPUT(New ^ New)
New  New + 1
ENDWHILE
Exam-style questions
1
a
b
2
One mark per bullet to max two.
•
They are both memory locations.
•
They can both store an item of data.
•
They both have an identifier.
A variable can change while the program is running whereas a constant cannot change
while the program is running.
One mark per bullet.
•
Taking two values as input and storing them.
•
Adding the inputs together.
•
Multiplying the inputs together.
•
Providing both outputs.
E.g.
INPUT Number1
INPUT Number2
OUTPUT(Number1 + Number2)
OUTPUT(Number1 * Number2)
3
40
a
Pre-condition
b
To loop the number of times represented by the variable, quantity.
c
Three of: quantity, largest, total, smallest.
d
One mark per bullet.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
•
Changing while to for
•
Including count = 0 in the for statement
•
Looping until quantity (or quantity +1)
•
Removing counter = counter + 1
•
Ending with Next.
E.g.
FOR Counter  0 to Quantity
Value  INPUT("Enter the mark)
Total  Total + Value
IF (Value > Largest) THEN
Largest  Value
ENDIF
IF (Value < Smallest) THEN
Smallest  Value
ENDIF
NEXT
4
One mark per bullet.
•
Looping 20 times
•
Inputting a number
•
Storing in appropriate array index.
E.g.
FOR X  0 TO 20
ArrayData[X]  INPUT("Enter a number")
NEXT
5
One mark per row.
Statement
True
IF(10 < 20)
✓
False
IF(100 > < 2)
IF(5 >= 5)
Invalid
✓
✓
IF(9 <= 8)
✓
X  1
✓
Y  3
IF(X = Y)
41
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
Statement
True
False
Num1  100
Invalid
✓
Num2  200
IF(Num1 and Num2)
Value1  70
✓
Value2  190
IF(Value1 <> Value2)
6
One mark per bullet.
•
Looping through first index 10 iterations.
•
Looping through second index 20 iterations.
•
Generating a random number between 1 and 100.
•
Storing in the correct indices.
E.g.
FOR Row  0 TO 9
FOR Column  0 TO 19
Numbers[Row][Column]  RANDOM(1, 100)
NEXT
NEXT
7
a
It returns a value.
b
One mark per bullet to max seven.
•
Function declaration with identifier move
•
... taking an appropriate parameter.
•
Reading input from the user and storing the result.
•
Checking if the move entered is left ...
•
… decreasing the x coordinate.
•
Checking if the move entered is right …
•
... increasing the x coordinate.
•
Returning the x coordinate in both left and right.
•
Looping until there is a valid input.
E.g.
FUNCTION Move(XCoordinate)
Move  INPUT("Enter your move")
WHILE (TRUE)
42
IF Move = "left" OR Move = "LEFT" OR Move = "Left" THEN
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 8 continued
RETURN(XCoordinate - 1)
ELSEIF Move = "right" OR Move = "RIGHT" OR Move = "Right" THEN
RETURN(XCoordinate + 1)
ENDIF
ENDWHILE
ENDFUNCTION
8
One mark for each box.
Comments: give people information about how the program works / the meaning
of each section of code.
Meaningful identifiers: give people information about the purpose / stops people
confusing different variables.
9
One mark per bullet.
•
It declares the procedure with identifier and no parameters.
•
It opens the file, number.txt.
•
It reads the data from the file.
•
It closes the file.
•
It loops 12 times.
•
It outputs the 12 times table for the data read.
E.g.
PROCEDURE Twelve()
OPEN "number.txt"
Number  READ("number.txt")
CLOSE "number.txt"
FOR X  1 TO 12
OUTPUT(X * Number)
NEXT
ENDPROCEDURE
Chapter 9: Databases
Discussion questions
43
1
This is dependent on the site chosen, but if data is stolen then the perpetrators may
be able to access other accounts and card details.
2
This is dependent on the company, but the damage could be financial, reputational, etc.
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 9 continued
Questions
1
E.g.
Data type
Example
Boolean
True
Integer
1
Text
"Hello"
Character
"!"
Real
2.36
Date/time
5/5/2021
2
A table has several fields. Each field is one piece of information. A row of data about
one object/item is called a record.
3
To uniquely identify each record
4
a
b
5
E.g.
Field name
Data type
Username
Text/alphanumeric
Password
Text/alphanumeric
Online name
Text/alphanumeric
Date account created
Date/time
Number of friends
Integer
E.g. Username, or adding an ID, e.g. user ID
12GH
59RF
3WR
52D
6SE
6
7
Saturn
Chocolate
Vanilla
Fudge
Peanuts
Nuts
Jazz
Fruit
Signet
Fudge
SELECT Cost
FROM PRODUCTS
8
SELECT ID Number, Name
FROM PRODUCTS
44
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 9 continued
9
SELECT Name, Cost, Quantity in stock
FROM PRODUCTS
10 596
Computer Science
Programming 2
806
Computer Science
Programming 2
11 596
Computer Science
Pass
123
Maths
Pass
023
Maths
Pass
806
Computer Science
Pass
596
Science
Pass
12 SELECT
Test name, Percentage, Grade
FROM MARKS
WHERE Percentage > 50
13 SELECT Student ID, Subject, Percentage
FROM MARKS
WHERE SUBJECT = "Science"
14 SELECT Student ID, Test name, Percentage
FROM MARKS
WHERE Percentage <= 25
15
16
17
20.3
22
11/12/2019
23.7
15
11/12/2019
11/12/2019
13:00
63
11/12/2019
15:00
61
11/12/2019
18:00
60
11/12/2019
10:00
11/12/2019
13:00
11/12/2019
15:00
11/12/2019
18:00
12/12/2019
15:00
18 SELECT Time
FROM WEATHER
WHERE Date = 12/12/2019 AND Humidity > 50
45
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 9 continued
19 SELECT Wind speed, Temperature
FROM WEATHER
WHERE Wind speed < 15 OR Wind speed > 20
20 17.2
18
12/12/2019
18.4
20
12/12/2019
20.3
22
11/12/2019
23.7
15
11/12/2019
23.9
16
11/12/2019
24.0
13
11/12/2019
21 11/12/2019
13:00
23.7
63
11/12/2019
15:00
24.0
61
11/12/2019
18:00
23.9
60
11/12/2019
10:00
20.3
59
12/12/2019
15:00
18.4
52
12/12/2019
18:00
17.2
48
22 SELECT Date, Wind speed, Humidity
FROM WEATHER
ORDER BY Wind speed
23 SELECT Date, Time, Temperature
FROM WEATHER
ORDER BY Humidity DESC
24 SELECT Temperature, Wind speed, Humidity
FROM WEATHER
ORDER BY Temperature DESC
25 51
26 8
27 1
28 135.71
29 SELECT COUNT(FirstName)
FROM ORDERS
WHERE FirstName = "James" AND LastName = "Smith"
46
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 9 continued
30 SELECT SUM(TotalCost)
FROM ORDERS
WHERE NumberItems >= 5
31 SELECT COUNT(NumberItems)
FROM ORDERS
WHERE TotalCost > 50.0
Skills focus 9.1 questions
1
Sum adds together the values. Count identifies how many records there are.
2
160
3
5
4
2.78
5
4
Exam-style questions
1
One mark per definition.
Record the completed fields for one object / item. Example: all the data about one student.
Field one piece of data. Example: Date of birth.
2
One mark per description and example to max four.
Boolean: can only be 2 values Example: true.
Real: decimal number. Example: 23.5.
Date/time: a date or a time. Example: 1/1/1900.
Text: one or more letters, symbols and/or numbers. Example: "hello1!".
3
47
One mark per bullet.
•
ID (or other appropriate key field), data type Integer / Text
•
Screen number, data type Integer / Text
•
Film, data type Text / Alphanumeric
•
Date, data type Date / Time
•
Time, data type Date / Time
•
SeatsSold, data type Integer
•
Primary key is ID (or other appropriate key field defined).
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 9 continued
4
a
6
b
7
c
One mark for definition, e.g. A unique identifier.
One mark for Appointment ID.
d
One mark for first correct, one mark for remainder correct.
JP
Cut
AD
Cut and dry
AD
Colour
JP
Cut and dry
JP
Cut
AD
Colour
e
2
f
One mark for each statement.
SELECT Customer first name, Customer last name
FROM APPOINTMENTS
WHERE Date = 1/2/2020
g
One mark for each statement.
SELECT COUNT(Employee ID)
FROM APPOINTMENTS
WHERE Employee ID = "JP"
5
a
b
c
One mark per bullet.
•
Sales ID: integer
•
Date: date / time
•
Customer ID: text
•
Quantity bought: integer
•
Total Cost: real
One mark for one correct, two marks for all correct in the correct order.
3/3/2020
1GHF2
3/3/2020
1GHF2
4/4/2020
1GHF2
One mark for each completed statement.
SELECT Customer ID, Total Cost
FROM SALES
WHERE Total Cost > 1
48
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 9 continued
d
e
One mark for one correct, one mark for all correct and in the correct order.
12
151
13
28
One mark for each completed statement.
SELECT SUM(Quantity bought)
FROM SALES
WHERE Date = 4/4/2020
One mark for each completed statement.
f
SELECT SUM(Total Cost)
FROM SALES
Chapter 10: Boolean logic
Discussion questions
1
In Boolean, values are either true (1) or false (0). In a computer, if there is electricity
that means 1 and if there is no flow of electricity that means 0.
2
A logic gate takes one or more inputs as a Boolean value (or values) and outputs a value.
3
All digital computers represent data in binary form with 0s and 1s, so they would not
be able to operate without logic gates.
Questions
1
2
Output
A
X
1
0
0
1
3
X = NOT A
4
Input 1
Input 2
5
6
49
Input
Output
A
B
X
0
0
0
0
1
0
1
0
0
1
1
1
X = A AND B
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 10 continued
7
8
9
Input 1
Output
Input 2
A
B
X
0
0
0
0
1
1
1
0
1
1
1
1
X = A OR B
Input 1
10 Input 2
11
Output
A
B
X
0
0
1
0
1
1
1
0
1
1
1
0
12 X = A NAND B
13
14
Input 1
Input 2
Output
A
B
X
0
0
1
0
1
0
1
0
0
1
1
0
15 X = A NOR B
16
17
Input 1
Input 2
Output
A
B
X
0
0
0
0
1
1
1
0
1
1
1
0
18 X = A XOR B
19 Q = (A OR (NOT B AND C))
20 X = ((A AND B) OR (A NAND C))
50
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 10 continued
21 a
X = ((NOT A AND NOT B) OR (NOT A AND B))
b
A
X
B
22
A
B
C
X
0
0
0
1
0
0
1
0
0
1
0
0
0
1
1
0
1
0
0
1
1
0
1
0
1
1
0
1
1
1
1
1
23 A
Z
B
C
Skills focus 10.1 questions
1
51
A
B
C
Workspace
Q
0
0
0
0
0
0
1
1
0
1
0
0
0
1
1
0
1
0
0
1
1
0
1
1
1
1
0
1
1
1
1
1
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 10 continued
2
P
Q
R
Workspace
Z
0
0
0
0
0
0
1
0
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
0
1
1
0
0
1
1
1
0
Exam-style questions
1
To control the flow of electricity.
2
a
Input 1
Input 2
b
Input 1
Input 2
3
Output
Output
a
One mark for each correct expression for each output (max three), one mark
for joining each expression with OR.
X = ((NOT A AND NOT B) OR (A AND NOT B) OR (A AND B))
b
One mark for each correct AND gate with correct inputs.
One mark for both correct OR gates with correct inputs.
A
X
B
4
One mark for each correct expression for each output (max four), one mark for joining
each expression with OR.
Z = ((NOT S AND NOT T AND P) OR (NOT S AND T AND NOT P) OR
(S AND NOT T AND NOT P) OR (S AND NOT T AND P))
5
a
One mark for correct AND expression, one mark for correct NOR expression,
one mark for joining these with NAND.
Y = ((NOT L AND M) NAND (L NOR N))
52
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 10 continued
b
Award:
Four marks for 8 correct outputs
Three marks for 6 or 7 correct outputs
Two marks for 4 or 5 correct outputs
One mark for 2 or 3 correct outputs.
6
L
M
N
0
0
0
Workspace
Y
1
0
0
1
1
0
1
0
0
0
1
1
1
1
0
0
1
1
0
1
1
1
1
0
1
1
1
1
1
a
X = ((NOT M AND NOT H) OR (T AND H))
b
One mark per each correct logic gate with correct inputs.
M
H
X
T
c
53
M
T
H
Workspace
X
0
0
0
1
0
0
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
0
1
1
0
0
1
1
1
1
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 11: Programming scenarios practice
Discussion questions
1
There will gaps in the data that you need to tackle the problem and going back later may
be costly, time consuming and difficult to implement.
2
This is dependent on the student.
Questions
1
Inputs, processes and outputs
2
E.g. an action, a modification of a value
3
E.g. validation, appropriate messages, comments.
Exam-style questions
1
E.g.
OUTPUT "Enter a number"
INPUT Number
FOR Count  1 TO Number + 1
OUTPUT Count
IF number MOD(number, 5) = 0
THEN
OUTPUT "Divisible by 5"
ENDIF
IF number MOD(number, 7) = 0
THEN
OUTPUT "Divisible by 7"
ENDIF
NEXT Count
2
E.g.
Height  INPUT "Enter the minimum height of a plant needed"
Shade  INPUT "Enter TRUE if the plants needs to be in shade, or FALSE
if not"
FOR Count  0 TO 49
IF HeightArray[Count] > Height AND ShadeArray[Count] = Shade
THEN
OUTPUT(PlantName[Count])
54
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 11 continued
ENDIF
NEXT Count
3
E.g.
Player1Score  0
Player2Score  0
FOR Count  0 TO 15
IF Player1[Count] = "lion" AND Player2[Count] = "horse"
THEN
Player1Score  Player1Score + 1
ELSEIF Player2[Count] = "lion" AND Player1[Count] = "horse"
THEN
Player2Score  Player2Score + 1
ELSEIF Player1[Count] = "Elephant" AND Player2[Count] = "lion"
THEN
Player1Score  Player1Score + 1
ELSEIF Player2[Count] = "Elephant" AND Player1[Count] = "lion"
THEN
Player2Score  Player2Score + 1
ELSEIF Player1[Count] = "horse" AND Player2[Count] = "cat"
THEN
Player1Score  Player1Score + 1
ELSEIF Player2[Count] = "horse" AND Player1[Count] = "cat"
THEN
Player2Score  Player2Score + 1
ELSEIF Player1[Count] = "cat" AND Player2[Count] = "elephant"
THEN
Player1Score  Player1Score + 1
ELSE
Player2Score  Player2Score + 1
ENDIF
NEXT Count
IF Player1Score > Player2Score
55
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 11 continued
THEN
OUTPUT "Player 1 wins"
OPENFILE HighScore
WRITE Player1Score
CLOSEFILE
ELSEIF Player2Score > Player1Score
THEN
OUTPUT "Player 2 wins"
OPENFILE HighScore
WRITE Player2Score
CLOSEFILE
ELSE
OUTPUT "Draw"
ENDIF
4
E.g.
Total  0
Smallest  100000
Largest  -1
FOR Count  0 to 99
Costs[Count]  INPUT "Enter the cost of an item"
Total  Total + Costs[Count]
IF Costs[Count] > Largest
THEN
Largest  Costs[Count]
ENDIF
IF Costs[Count] < Smallest
THEN
Smallest  Costs[Count]
ENDIF
NEXT Count
OUTPUT "The total is ", Total
OUTPUT "The average is ", Total / 100
56
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 11 continued
OUTPUT "The cheapest item costs ", Smallest
OUTPUT "The most expensive item costs ", Largest
5
E.g.
OUTPUT "Enter 1 to output how many words have 5+ letters"
OUTPUT "Enter 2 to output the longest word"
OUTPUT "Enter 3 to output the shortest word"
INPUT Choice
IF Choice = 1
THEN
OUTPUT FiveLetters()
ELSEIF Choice = 2
THEN
OUTPUT Longest()
ELSEIF Choice = 3
THEN
OUTPUT Shortest()
ELSE
OUTPUT "Invalid option"
ENDIF
FUNCTION FiveLetters()
Count  0
Numberofwords = 0
FOR Count  0 TO 999
IF LENGTH(Words[Count]).length >= 5
THEN
Numberofwords  Numberofwords + 1
ENDIF
NEXT Count
RETURN Numberofwords
ENDFUNCTION
57
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 11 continued
FUNCTION Longest()
Longest  ""
FOR Count  0 TO 999
IF LENGTH(Words[Count]) > LENGTH(Longest)
THEN
Longest = LENGTH(Words[Count])
ENDIF
NEXT Count
RETURN Longest
ENDFUNCTION
FUNCTION Shortest()
Shortest  "abcdefghijklmnopqrstuvwxyz"
FOR Count  0 TO 999
IF LENGTH(Words[Count]) < LENGTH(Shortest)
THEN
Shortest  LENGTH(Words[Count])
ENDIF
NEXT Count
RETURN Shortest
ENDFUNCTION
58
Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
Download
Study collections