Nesrine Cambridge IGCSE & O Level Computer Science 2ed Coursebook
Nesrine Cambridge IGCSE & O Level Computer Science 2ed Coursebook
Nesrine Cambridge IGCSE & O Level Computer Science 2ed 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.
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.
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
0 0 1 0 0 1 1 0
+
0 1 0 1 0 1 1 1
0 1 1 1 1 1 0 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.
1 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
2 9D1
3 15E
4 940
2 1 500 000
Exam-style questions
1 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.
2 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.
2 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 1 continued
3 a One mark for two correct nibbles, two marks for three, for each conversion
• 0010 0001 1010
• 1001 0000 1101
b 09C
4 One mark for one correct nibble, two marks full correct answer, one mark for
a
demonstration of working, e.g. carried bits shown
1 1 1 1 1 1
0 0 1 1 0 1 1 1
+
0 1 1 1 0 0 1 1
1 0 1 0 1 0 1 0
b One mark for 10111000
5 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).
6 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 Any two from:
• less storage space required
• less time for webpage to load for readers
• quicker to upload content to the blog.
b 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.
8 1050 MiB
3 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
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
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.
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 Any two from:
• destination address
• packet number
• originator’s address.
5 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 2 continued
2 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.
3 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.
4 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.
5 Two from:
• Serial
• Full duplex
And four from:
• 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.
6 One mark for each correct row:
Checksum Echo Check Parity Check
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 One mark for each correct term in the correct order: plain text; key; cipher text;
meaningless; decrypted; the same.
6 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.
Questions
1 RAM
2 Control unit
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 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
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.
7 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 3 continued
9 There are many other example uses than those given:
8 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 3 continued
Output Description of data output Example of use
device
Light emitting This is a screen that uses LEDs as a This screen can be built into a mobile
diode (LED) backlight to output an image. phone.
screen
Liquid crystal This is a device that shines light This can be used to project an image in
display (LCD) through crystals and then through a home cinema system.
projector a lens to project an image onto a
blank wall or screen.
Liquid crystal This is a screen that shines light This can be built into a television screen.
display (LCD) through crystals to output an
screen image.
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 This can be used in medicine to create
material to output a 3D object. prosthetic limbs.
11 Input
c Temperature – In a kettle, to turn off the heating element when the water is boiling.
9 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 i RAM
ii Program counter / PC
b i 2
ii Two from:
• Two instructions can be processed at the same time
• … which helps data be processed quicker by the CPU.
c i Primary
10 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 Any two from:
• CD
• DVD
• Blu-ray.
ii 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.
Chapter 4: Software
Discussion questions
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
11 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.
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
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.
9 Low-level language: Allows direct manipulation of hardware, reducing the memory that
the program uses.
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.
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.
12 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.
3 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.
13 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 4 continued
• 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.
7 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:
• 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.
d One mark for translator, compiler or interpreter. One mark per bullet for justification.
Justification must match translator.
Interpreter:
• 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.
14 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 4 continued
Compiler:
• 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.
e 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.
8 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.
15 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.
Questions
1 It is a text based address for a website.
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
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.
16 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.
Exam-style questions
1 The internet
3 One mark per each correct term in the correct order: web browser; domain name server;
web server; HTTP / HTTPS; HTML.
b Session cookie
17 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
9 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.
18 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
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
3 a Infra-red, proximity
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.
4 Benefits, e.g.
• faster response
• more accurate
• does not need to rest.
Drawbacks, e.g.
• initial cost
• maintenance costs
• may have been programmed incorrectly
• can be hacked.
5 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.
19 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.
• manufacturing of an object, e.g. car
• testing products
• moving products.
8 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.
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 Any three from:
• mechanical structure / framework
• electrical components
• sensors
• microprocessors
• actuators
• programmable.
4 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.
• 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.
21 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 6 continued
6 One mark each, e.g.
• Self-driving cars
• Managing the movement of items in a factory, e.g. for loading lorries.
8 a E.g. harvesting the crops, watering when there is no rain, packaging crops.
22 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 6 continued
b One mark per bullet to max six, e.g.
• 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.
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
total = number1
number1 number2 total
+ number2
23 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 E.g.
Login
5 a
Start/Stop
b
Process
c
Decision
d
Input/
Output
24 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
7
START
INPUT x, y, z
YES
IS x > y AND OUTPUT x
x > z?
NO
YES
IS y > x AND OUTPUT y
y > z?
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 The purpose of pseudocode is to design an algorithm in a non-specific
programming language.
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
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.
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 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
19 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.
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
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
2 Compare the first characters in each string, then if they are the same look at the next
character in each string.
3 E.g.
29 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.
2 a number output
7 7
6
5
4
3
2
1
0
3 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.
Design:
• Plan the algorithms for the problem.
• Decompose the problem using a structure diagram.
30 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:
• Input data and make sure that the program outputs the correct data.
• Input a range of data to check if the program works.
Game
Start Move
31 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 = YES
Lie down
down?
NO
YES
IS move = up? Jump
NO
YES
IS move = left? Move left
NO
NO IS move = YES
Move right
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.
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 Constant
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
6 CONSTANT Number1 10
CONSTANT Number2 12
Result Number1 + Number2
OUTPUT(Result)
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.
11 Answer 50
Guess INPUT("What is 5 * 10")
IF Guess = Answer THEN
OUTPUT("Correct")
ELSE
OUTPUT("Incorrect. It is 50.")
ENDIF
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
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
19 Counter 1
WHILE Counter < 11 DO
OUTPUT(Counter * Counter)
Counter = Counter + 1
ENDWHILE
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
LessThan100 LessThan100 + 1
36 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
25 12
26 WORLD
30 6
31 OUTPUT(FindValue(100))
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
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.
45 OPEN "dataStore.txt"
Value READ("dataStore.txt")
CLOSE "dataStore.txt"
OUTPUT(Value)
b 5
2 a 1
b 2
b If 6 is greater than 3
2 a False
b False
c False
d True
39 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 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.
b A variable can change while the program is running whereas a constant cannot change
while the program is running.
E.g.
INPUT Number1
INPUT Number2
OUTPUT(Number1 + Number2)
OUTPUT(Number1 * Number2)
3 a Pre-condition
40 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
E.g.
FOR X 0 TO 20
ArrayData[X] INPUT("Enter a number")
NEXT
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 Invalid
Num1 100 ✓
Num2 200
IF(Num1 and Num2)
Value1 70 ✓
Value2 190
IF(Value1 <> Value2)
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.
E.g.
FUNCTION Move(XCoordinate)
Move INPUT("Enter your move")
WHILE (TRUE)
IF Move = "left" OR Move = "LEFT" OR Move = "Left" THEN
42 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
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.
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
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.
43 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.
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.
4 a E.g.
5 12GH
59RF
3WR
52D
6SE
6 Saturn Chocolate
Vanilla Fudge
Peanuts Nuts
Jazz Fruit
Signet Fudge
7 SELECT Cost
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
15
20.3 22 11/12/2019
23.7 15 11/12/2019
16 11/12/2019 13:00 63
11/12/2019 15:00 61
11/12/2019 18:00 60
17
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
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
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.
47 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
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
b 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
48 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 9 continued
d One mark for one correct, one mark for all correct and in the correct order.
12 151
13 28
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 Input Output
2 A X
1 0
0 1
3 X = NOT A
Input 1
4 Output
Input 2
5 A B X
0 0 0
0 1 0
1 0 0
1 1 1
6 X = A AND B
49 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Chapter 10 continued
Input 1
7 Output
Input 2
8 A B X
0 0 0
0 1 1
1 0 1
1 1 1
9 X = A OR B
Input 1
10 Input 2 Output
11
A B X
0 0 1
0 1 1
1 0 1
1 1 0
12 X = A NAND B
Input 1
13 Output
Input 2
14 A B X
0 0 1
0 1 0
1 0 0
1 1 0
15 X = A NOR B
Input 1
16 Output
Input 2
17 A B X
0 0 0
0 1 1
1 0 1
1 1 0
18 X = A XOR B
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
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
51 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
Output
Input 2
Input 1
b Output
Input 2
3 One mark for each correct expression for each output (max three), one mark
a
for joining each expression with OR.
b One mark for each correct AND gate with correct inputs.
One mark for both correct OR gates with correct inputs.
B X
4 One mark for each correct expression for each output (max four), one mark for joining
each expression with OR.
5 One mark for correct AND expression, one mark for correct NOR expression,
a
one mark for joining these with NAND.
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:
L M N Workspace Y
0 0 0 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
b One mark per each correct logic gate with correct inputs.
H
X
c
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
53 Cambridge IGCSE™ & O Level Computer Science – Lawrey & Ellis © Cambridge University Press 2021
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: COURSEBOOK
Questions
1 Inputs, processes and outputs
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