Answers Key IGCSE Computer Science 2nd Edition Hodder CourseBook by David Watson
Answers Key IGCSE Computer Science 2nd Edition Hodder CourseBook by David Watson
1 Data representation
Answers to activities
1.1
a 51
b 127
c 153
d 116
e 255
f 15
g 143
h 179
i 112
j 238
k 487
l 1364
m 3855
n 1992
o 2047
p 31984
q 16141
r 49983
s 34952
t 32767
1.2
a 00101001
b 01000011
c 01010110
d 01100100
e 01101111
f 01111111
g 10010000
h 10111101
i 11001000
j 11111111
k 1000000011101000
l 0000001101111000
m 0000111111111111
n 0100000000010000
o 1111001101100011
1.3
a C3
b F7
c 27F
d 4EE
e 1E1
f 89E
g (0)4FE
h (0)E9C
i FF7D
j 67AE
1.4
a 0110 1100
b 0101 1001
c 1010 1010
d 1010 0000 0000
e 0100 0000 1110
f 1011 1010 0110
g 1001 1100 1100
h 0100 0000 1010 1010
i 1101 1010 0100 0111
j 0001 1010 1011 0000
1.5
a 107
b 156
c 74
d 255
e 511
f 2561
g 2996
h 3240
i 4782
j 44425
1.6
a 62
b E3
c 1EA
d 1FF
e 33A
f 3E8
g A4A
h E9F
i FA7
j 1388
1.7
1 Student investigation
2 a 35, 37, 8B
b C9, 7A, CC
c C, 6F, 51
1.8
a 10000011
b 01100110
c 01111011
d 10110110
e 01101111
f 10110111
g 01111110
h 01110000
i 11111110
j 11011101
1.9
a 98 = 01100010 and 15 = 00001111; sum = 01110001 (= 113)
b 29 = 00011101 and 88 = 01011000; sum = 01110101 (= 117)
c 49 = 00110001 and 100 = 01100100; sum = 10010101 (= 149)
d 51 = 00110011 and 171 = 10101011; sum = 11011110 (= 222)
e 82 = 01010010 and 69 = 01000101; sum = 10010111 (= 151)
f 100 = 01100100 and 140 = 10001100; sum = 11110000 (= 240)
g 19 = 00010011 and 139 = 10001011; sum = 10011110 (= 158)
h 203 = 11001011 and 30 = 00011110; sum = 11101001 (= 233)
i 66 = 01000010 and 166 = 10100110; sum = 11101000 (= 232)
j 211 = 11010011 and 35 = 00100011; sum = 11110110 (= 246)
1.10
1 a 89 = 01011001 and 175 = 10101111; sum = 1 00001000 (= 8)
overflow error has occurred (9 bits)
b 168 = 10101000 and 99 = 01100011; sum = 1 00001011 (= 11)
overflow error has occurred (9 bits)
c 88 = 01011000 and 215 = 11010111; sum = 1 00101111 (= 47)
overflow error has occurred (9 bits)
2 a 1101 1111 0010 1010 – result is correct
b 1 1110 1011 1110 0100 – overflow error has occurred
1.11
1 a denary value = 64 + 32 + 8 = 104
0 0 0 0 1 1 0 1
b denary value is 13 (104 ÷ 8) therefore shift three places right is the same as division
by 23 (i.e. 8)
c denary value = 15
1 1 1 1 0 0 0 0
d denary value is 240 (15 × 16) therefore shift four places left is the same as multiplication
by 24 (i.e. 16)
2 a 29 = 00011101 and 51 = 00110011
b sum = 01010000
c 00001010
d 75 = 01001011
e 01010101
f 10101010
1.12
1 a 00100111
b 01000010
c 01011000
d 01100110
e 01101111
f 01111101
g 01001101
h 00010100
i 00110001
j 00111000
2 a 85
b 51
c 76
d 126
e 15
f 125
g 65
h 30
i 113
j 120
1.13
a 11101110
b 11100001
c 11010001
d 11000001
e 10101000
f 10100100
g 10011100
h 11111111
i 11110000
j 10000001
1.14
a −51
b −66
c −17
d −121
e −96
f −7
g −81
h −1
i −127
j −10
1.15
1 i The number of possible colours of a group of pixels (usually three or four) based on
the bit depth.
ii The coding system for all the characters on a standard keyboard and control codes;
extended ASCII, gives another 128 codes to allow for characters in non-English alphabets
and for some graphical characters to be included.
iii The coding system which represents all the languages of the world (the first 128 characters
are the same as ASCII code).
iv The number of sound samples taken per second.
v Images which are made up of pixels.
2 i, ii, iii each colour is 28 = 256
iv 256 × 256 × 256 = 16 777 216 possible colours
3 They both increase the size of the sound file.
1.16
1 1920 × 1536 = 2 949 120 pixels
colour depth = 16 16 × 2 949 120 = 47 185 920 bits
bits (÷ 8) 5 898 240 bytes
(÷ (1024 × 1024)) 5.625 MiB
2 1024 × 1536 = 1 572 864 pixels
colour depth = 24 24 × 1 572 864 = 37 748 736 bits
bits (÷ 8) 4 718 592 bytes
16 GiB = 17 179 869 bytes
number of photos = (17 179 869)/(4 718 592) = 3640 photos
3 a sample size = 44 100 × 8 × 2 (two tracks) = 705 600 bits
b file size = 44 100 × 8 × 30 × 2 (two tracks) = 21 168 000 bits
bytes (÷ 8) 2 646 000 bytes = 2.5 MiB
4 sample size = 44 100 × 16 × 210 × 2 (two songs) = 296 352 000 bits
bytes (÷ 8) 37 044 000 bytes 35.33 MiB
740 MiB CD can store 740/35.33 = 20.94 20 full songs
Answers to exam-style questions
Answers to questions 6 and 7 in this section are example answers for past paper questions. The details of
the relevant past paper can be found with the corresponding exam-style question in the Student’s Book.
1 a i The number of bits used to represent sound amplitude.
ii Better sound quality
Less sound distortion
b i The number of pixels that make up an image; for example, an image could contain
4096 × 3192 pixels (i.e. 12 738 656 pixels in total).
ii 4 bits 16 colours
iii 16 384 × 512 = 8 388 608 pixels
Colour depth = 256 (8 bits per pixel)
8 388 608 × 8 = 67 108 864 bits
(67 108 864/(1024 × 1024 × 1024)) = 0.0625 GiB
iv The developer may wish to use lossy compression and use the JPEG format to save
space on their camera and/or computer.
2 a The editor decides how many bits to represent the sound amplitude. Increasing the number
of bits to represent sound amplitude increases accuracy; this is sampling resolution.
The editor also decides how many samples per second should be taken; this is the sampling
rate – the higher the number of sound samples per second, the better the quality of the
sound recording.
b The editor will use lossy format, for example, MP3 format, which uses perceptual music
shaping, which removes sounds the ear cannot hear properly, therefore the sound quality is
essentially retained.
Lossless files would be larger than lossy files for little improvement in sound quality.
c i RLE is a form of lossless compression. It reduces the size of a string of adjacent,
identical data, for example, repeated colours of an image. The repeating string is
encoded into two values; one value represents the number of identical items and the
second value represents the code of the data item (ASCII code).
ii 3G 2W 4G 9W 4G 2W 1G 2W 2G 2W 1G (W = 1 and G = 0)
30 21 40 91 40 21 10 21 20 21 10
8 × 4 grid = 32 bytes
RLE code = 11 × 2 = 22 bytes
RLE saves 10 bytes of memory/storage
3 a 32 + 16 + 4 + 2 = 54 (base 10)
b i 00011011
ii 16 + 8 + 2 + 1 = 27 (base 10)
c i 11011000
ii 128 + 64 + 16 + 8 = 216 (base 10)
Therefore two places shift to the left = multiply by 4 (22)
4 a Parts i to iii
0 1 1 1 1 0 1 1
0 0 1 1 0 1 1 1
1 0 1 1 0 1 0 0
b i 123 + 55 = 0 1 1 1 1 0 1 1 + 0 0 1 1 0 1 1 1 = 1 0 1 1 0 0 1 0 (178)
ii 123 + 180 = 0 1 1 1 1 0 1 1 + 1 0 1 1 0 1 0 0 = 1 0 0 1 0 1 1 1 1 (47), which is
incorrect; overflow has occurred
c i 01110100
two’s complement gives: 1 0 0 0 1 1 0 0 (−116)
ii −112 = 1 0 0 1 0 0 0 0
iii 1 0 1 1 1 0 0 1 = −128 + (32 + 16 + 8 +1) = −128 + 57 = −71
d i 01101000
ii 10011000
5 a A picture element is the smallest element used to make up an image; each pixel is
represented by a minimum of 8 bits and 3 pixels are needed to make up the RGB colours.
b The number of possible colours of a group of pixels (usually three or four) based on the
bit depth.
c 1140 × 1080 = 1 231 200 pixels
1 231 200 × 24 = 29 548 800 bits
(29 548 800)/8 = 3 693 600 bytes
Memory card is 32 × (1024 × 1024 × 1024) bytes
number of photos = (32 × 1024 × 1024 × 1024)/(3 693 600) = 9302 photos
d Use file compression (e.g. JPEG) which reduces the size of the files/images being stored.
Therefore more files/images can be stored on a memory stick.
7 a Hours 0 0 0 0 0 0 1 0
Minutes 0 0 0 1 1 1 1 1
Seconds 0 0 1 1 1 0 1 0
b 00000101=5
0 0 0 1 1 0 1 0 = 26
0 0 1 1 0 1 1 1 = 55
Time shown as:
2 Data transmission
Answers to activities
2.1
1 Parts i and ii
• picture and sound out of synchronisation
• packets arriving at different times
• pauses in the video
• time delay in assembling packets
• degraded video and sound
• caused by competing traffic on the communications link
• possible 'drop out'
• packets take different routes, so some may get lost
2 • web page divided into data packets
• each packet has an IP address of the destination
• routers check header against IP address values to determine next router to send data packet
• hop value checked to see if it is zero
• destination computer reassembles data packets to build up the web page
3 a This takes all the 1-values in the payload and adds them together to generate a hex number.
• this hex value is stored in the trailer
• receiving computer carries out the same calculation on received payload
• if values match, data packets has been received error-free
• if values do not match, data packet needs to be re-sent
b 29 1-bits 1D in hex. If recalculated value doesn’t equal 1Dhex then it needs to be re-sent.
4 a • packets keep 'bouncing around' from router to router and never reach the destination
• use hop numbers; if hop number = 0 then the packet is deleted and is therefore lost
2.4
Parity bits: 1, 0, 1, 1, 0, 0, 1, 0, 1, 0
2.5
1 no error, error, error, no error, error, error, no error, no error, no error, no error
2.9
a E – text following an encryption algorithm
b B – the receiver
c B – plaintext
d E – there is a security problem when transmitting the encryption key
e A – symmetric key encryption
f E – check digit
g A – automatic repeat request
h B – parity check
i D – checksum
j A – echo check
2 i Packet switching is a method of data transmission where a message is broken into many
data packets, which can then be sent along different pathways independently of each other.
ii Cyclic redundancy check is an error-checking method which adds up all the 1-bits in the
data packet payload and stores this hex number in the trailer; the same calculation is done
at the receiving station.
iii Data skewing occurs when data arrives at the destination with the bits no longer
synchronised; this usually occurs during parallel data transmission.
iv Universal serial bus is a type of serial data transmission which has become the industry
standard for connecting computers to devices using the USB port.
v Parity bit (0 or 1) is added to a byte of data in the most significant bit position (left-most
bit); this ensures that the byte follows the correct even parity or odd parity protocol.
3 Checksum Parity check ARQ
Description
7 a i
Method 1 Tick Method 2 Tick
Serial Simplex
Parallel Half-duplex
Full-duplex
8 a True False
Statement
3 Hardware
Answers to activities
3.1
1 a address bus, data bus, control bus
b address bus: carries addresses throughout the computer; it is unidirectional
data bus: bidirectional bus allowing data to be sent throughout the computer
control bus: carries signals from the control unit to all other computer components;
it is bidirectional
c • wider address and data buses would increase computer performance
• wider control bus would have little, if any, effect on performance
• higher clock speed would increase processor speed, (overclocking could have serious
consequences however, such as unsynchronised operations or overheating)
2 fetches
current instruction register (CIR)
program counter (PC)
memory address register (MAR)
address bus
memory data register (MDR)
decoded
executed
control signals
control bus
arithmetic and logic unit (ALU)
accumulator (ACC)
3.2
1 a • increasing the width of the address bus and width of the data bus
• increasing clock speed but care needed to avoid over-clocking
• use of larger cache memories (uses static RAM) which have faster data access time
than normal RAM (which is dynamic)
• using dual core and quad core processors; but doubling number of cores doesn’t double
processor performance since the CPU needs to communicate with each core which uses
up time
b • instructions are a set of operations which are decoded in sequence
• each operation is made up of an opcode (which informs the CPU about what operation
needs to be done) and an operand (data which needs to be acted on/register)
• limited number of opcodes exist and this is known as an instruction set
• instruction sets are low level language instructions which instruct the microprocessor
how to carry out an operation
2 a • destination address input
• other factors (e.g. avoiding toll roads) are input
• data from satellites, which gives the location of three or four satellites …
• … together with very accurate timings
• Sat Nav computer uses satellite data to calculate the position of a car on the
stored maps
• this combination allows accurate tracking of the vehicle on stored roads
b • use of satellite or cellular network used to download the latest map updates/software
updates
• if the Sat Nav is a portable unit, it can be connected to a computer via USB port and
new maps/software will be downloaded
3.3
1 a || wwwbwbb/wwwbbwb/wwwbbwb || bwwwwbw/bwbbbww/bbbwwbw ||
b || wwbbwwb/wwbwwbb/wbbwwwb/wbbbwbb ||
bwbwwww/bwbwwww/bwbbbww/bwwbwww ||
c || wwwbbwb/wbbwwwb/wbbwbbb/wbbwbbb/wwwbwbb ||
bbbwwbw/bbwbbww/bbbwbww/bbwwbbw/bwwbwww ||
2 a • hold more information
• fewer errors due to built-in error-checking in QR codes
• easier to read – QR codes can be read by a smartphone/tablet camera and app
• QR codes can be encrypted
b 40 × 40 = 1600 pixels = 1600 bits = 200 bytes
c • they are used as a form of alignment when reading the QR code
• the remaining corner square is used to ensure the correct size and correct angle of QR
camera shot
d • more than one QR format exists
• QR codes can contain malicious codes (called attagging); QR code software is free;
therefore, it is easy to embed malicious software or fake websites
3.4
1 a Laser printer:
• uses dry powdered ink (toner)
• makes use of the properties of static electricity to produce text and images on paper
• prints whole page in one go
• ink is fused onto paper using heated rollers
Inkjet printer:
• uses liquid ink in four or five cartridges
• printing is done line by line as paper advances forward after each printed line
• ink droplets are ejected onto paper using thermal bubble or piezoelectric technology
b Parts i and ii
Laser printer:
• high-quality flyers and posters (in large quantities)
• any large volume printing job
• equipped with large capacity toner cartridges
• have large paper trays
Inkjet printer:
• one-off printouts, such as photos
• small batch printing jobs
• can print on various types of paper and other media (for example, can print on T-shirts)
• where small paper trays and small capacity ink cartridges are not important for small
print jobs
2 Order: C, E, G, A, I, B, F, H, D
3 a In an LCD–LED screen, each pixel is made from liquid crystals that are backlit using
LEDs. In pure LED screens, the pixels are made up of the LEDs themselves.
b LEDs:
• use less power
• they do not need to warm up to reach maximum brightness
• produce a 'whiter' light
• produce a brighter light
• last for much longer
4 • Filipe uses an application on his computer that can play music files.
• The application finds the files on the backing store (HDD or SSD) and moves it into RAM.
• The data in the file is read by the application and then sent via a device driver to
loudspeakers which are connected to the computer.
• The device driver software translates the digital data into a series of analogue electrical
signal using a digital-to-analogue converter (DAC).
• The electrical signals make the loudspeaker cones move, through the use of a solenoid.
• If the file is a stereo recording then two different signals are sent to each loudspeaker.
• The movement of the loudspeaker cone moves molecules of air, which Filipe's ears detect,
and means he can hear music.
3.5
1 a Control:
• sensors used to collect data to send to a microprocessor
• sensor data is compared to stored/pre-set data
• the output affects the next set of inputs
• microprocessor sends signals to actuators to operate valves, motors and switches
Monitoring:
• sensors used to collect data to send to a microprocessor
• sensor data is compared to stored/pre-set data
• no actual changes to the process are made
• results of data comparison are shown on a screen/printed out or an alarm is activated
b • temperature and humidity sensors are used
• both sensors constantly send data to a microprocessor
• the data is converted to digital, if necessary, using an ADC
• the temperature levels are set by the user …
• … humidity levels are set at the factory
• if the temperature sensor reading > set temperature, the microprocessor will send
a signal to an actuator …
• … to switch on the air conditioning unit
• if the temperature sensor reading <= the set temperature, the microprocessor will send
a signal to an actuator …
• … to switch off the air conditioning unit
• if the humidity sensor reading > factory set value, the microprocessor will send a signal
to an actuator …
• … to switch on the air conditioning unit
• if the humidity sensor reading <= the factory setting AND temperature sensor reading
< the set temperature …
• … the microprocessor will send a signal to an actuator to switch off the air
conditioning unit
• the process is continuous
2 • pH sensors send data back to microprocessor
• data changed to digital if necessary (using ADC)
• if pH < stored value then microprocessor sends signals to actuators …
• … to open valve to add alkaline solution to soil
• if pH > stored value then microprocessor sends signals to actuators …
• … to open valve to add acidic solution to soil
• if pH = stored value then microprocessor sends signals to actuators …
• RAM is physical memory and virtual memory is RAM + swap space on HDD/SSD
• to execute a program, data is loaded into RAM from HDD/SSD
• gives the illusion that RAM is much larger than it really is
b • when P5 wants access to RAM we use virtual memory since RAM is full
• assuming P1 is oldest data, P1 data (10 GiB) is moved out of RAM into HDD/SSD
• P5 now points to memory space in RAM once occupied by P1
• process continues to allow all five programs to run in RAM
3
4 a RAM: ROM:
• temporary memory device • permanent memory device
• volatile memory • non-volatile memory device
• can be written to and read from • read-only
• used to store data, files, programs, • used to store the boot-up instructions
part of OS currently in use • an increase in the amount of ROM has no
• can be increased in size to improve effect on computer performance
operational speed of a computer
• a computer has far more RAM
memory than ROM memory
b For example:
• RAM – used by a PC to store the contents of an application when the computer
is running
• ROM – used by a PC to find out what it should to do when the power is switched on
5 a electrons
NAND
matrix
intersection
control gate
floating gate
electrons
control gate
b Compared to HDDs, SSDs:
• have faster data access times
• are lighter
• consume less power
• don’t get as hot
• are thinner
• are more reliable
c More expensive – questions over how long they can store data for
3.8
1 a • A network interface card (NIC) is needed to allow a device to connect to a network
(such as the internet).
• It is usually part of the device hardware and contains the Media Access Control (MAC)
address generated at the manufacturing stage.
b • Media Access Control is an address which refers to a number which uniquely identifies
a device on the internet.
• It takes the form: NN-NN-NN-DD-DD-DD.
c • Internet Protocol identified either as IPv4 or IPv6
• It gives a unique address to each device connected to the internet which identifies
their location.
d • These enable data packets to be routed between the different networks, for example, to
join a LAN to a WAN onto the internet.
e • A server that automatically provides and assigns an IP address.
2 a • changes each time a device connects to the internet
• allows for greater privacy
• can be less reliable for some applications (e.g. VoIP)
b • IP address is associated with a particular device and does not change each time the
device connects to the internet
• allows faster upload and download speeds
• less privacy as a specific device can be identified by its IP address
c Dynamic IP addresses are needed for the following reasons:
• they give greater privacy since they change each time a user logs on
• dynamic IP addresses can be an issue when using, for example, VoIP since this type of
addressing is less reliable as it can disconnect and change the IP address causing the
VoIP connection to fail
Static IP addresses are needed for the following reasons:
• since static IP addresses don’t change, they allow each device to be fully traceable
• allow for faster upload and download speeds
3 MAC:
• Permanent address associated with the piece of hardware
• Unique
• 48-bit address
• Used to find the particular device within a network
IP:
• An address assigned to hardware by an ISP – even a static IP address is not physically
associated with the hardware
• Not necessarily unique
• 32 (IPv4) or 128 (IPv6) bit address
• Used to route data to the correct network
Answers to exam-style questions
Answers to questions 7–9 in this section are example answers for past paper questions. The details of
the relevant past paper can be found with the corresponding exam-style question in the Student’s Book.
1 a • The plastic, organic layers of an OLED are thinner, lighter and more flexible than the
crystal structures used in LEDs or LCDs.
• The light-emitting layers of an OLED are lighter; OLED layers can be made from
plastic rather than the glass used in LED and LCD screens.
• OLEDs give a brighter light than LEDs.
• OLEDs do not require backlighting like LCD screens – OLEDs generate their
own light.
• Since OLEDs require no backlighting, they use much less power than LCD screens
(most of the LCD power is used to do the backlighting); this is very important in
battery-operated devices such as mobile phones.
• Since OLEDs are essentially plastics, they can be made into large, thin sheets (this
means they could be used on large advertising boards in airports, subways, and so on).
• OLEDs have a very large field of view, about 170 degrees, which makes them ideal for
use in televisions and for advertising screens.
b • many colours are possible if each primary colour (RGB) uses several bits to represent
its colour intensity …
• … for example, 32 bits per colour gives 232 × 232 × 232 possible colour combinations
• however, the human eye cannot detect more than a few thousand different colour
shades …
• … therefore, it is impossible to experience the 1 million different colours as claimed by
the manufacturer
• television contrast (etc.) needs to be set up perfectly to show all colours accurately
2 a i Two from:
• cannot be changed by the user
• more difficult to copy the software
• immediately available as soon as device powered up
• programs are permanently stored
ii RAM allows the user to store their own data, such as game status
• only the part of the software needed at each stage in the game would be in RAM at
any time
iii USB ports allow other games stored on memory sticks, for example, to be plugged into
the games console
• can plug the console into external speakers for better sound effects
• can plug in keyboard and/or mouse to navigate menu systems
• can plug in VR headsets for consoles with this capability
b • the design may change several times …
• … therefore, it is cheaper and quicker to make a prototype using a 3D printer
• the 3D solid object lets the development team see how well it will work in real life
before building the final version
3 a • both use sensors to gather data
• in control, the output affects the input and actuators are used to change the process
(for example, open valve, operate pump)
• in monitoring, no changes to the process are made; the system simply shows the status
on a screen or prints out data or sounds an alarm
b • temperature and humidity sensors are used
• both sensors constantly send data to a microprocessor
• the data is converted to digital, if necessary, using an ADC
• the temperature levels are set by the user …
• … humidity levels are set at the factory
• if the temperature sensor reading is > set temperature, the microprocessor will send a
signal to an actuator …
• … to switch on the air conditioning unit
• if the temperature sensor reading <= the set temperature, the microprocessor will send
a signal to an actuator …
• ... to switch off the air conditioning unit
• if the humidity sensor reading > factory set value, the microprocessor will send a signal
to an actuator …
• … to switch on the air conditioning unit
• if the humidity sensor reading <= factory setting AND temperature sensor reading < set
temperature …
• … the microprocessor will send a signal to an actuator to switch off the air
conditioning unit
b RAM: ROM:
• temporary memory device • permanent memory device
• volatile memory • non-volatile memory device
• can be written to and read from • data cannot be altered
• used to store data, files, part of OS • sometimes used to store the BIOS
currently in use and other start-up procedures
• can be increased in size to improve the
performance of computer
c DVD: Blu-ray:
• uses red laser technology • uses blue laser technology
• storage capacity is ~ 4.7 GB max • storage capacity can be up to ~ 50 GB
• doesn’t allow great interactivity • allows much greater interactivity
• relatively easy to copy • has built-in data encryption
• data transfer rate is ~ 10 Mbps • data transfer rate is ~ 36 Mbps
• always comes in dual-layer format • can come in single-layer, dual-layer …
up to 6-layer formats
6 a Capacitive touch screens:
• capacitive touch screens are composed of a layer of glass (protective layer),
a transparent electrode (conductive) layer and a glass substrate
• since human skin is a conductor of electricity, when bare fingers (or special stylus)
touch the screen, the electrostatic field of the conductive layer is changed
• the installed microcontroller is able to calculate where this change took place and
hence determine the coordinates of the point of touching
• with surface capacitive screens, sensors are placed at the corners of a screen
• small voltages are also applied at the corners of the screen creating an electric field
• a finger touching the screen surface will draw current from each corner reducing
the capacitance
• a microcontroller measures the decrease in capacitance and hence determines the point
where the finger touched the screen
• this system only works with a bare finger or stylus
• with projective capacitive screens, the transparent conductive layer is in the form of
an X–Y matrix pattern
• this creates a three dimensional (3D) electrostatic field
• when a finger touches the screen it disturbs the 3D electrostatic field allowing a
microcontroller to determine the coordinates of the point of contact
• this system works with bare fingers, stylus and thin surgical or cotton gloves; it also
allows multi-touch facility (for example, pinching or sliding)
7 a touchscreen/concept keyboard/microphone/trackerball/touchpad
b headphones/speakers
c (removable) hard disk drive/SSD/USB drive/Blu-ray disk
d • QR code scanned using a camera on smartphone or tablet
• QR code is decoded/read using the app on the smartphone/tablet
• customer is provided with text about the animal
• customer is directed to a website about the animal
• QR code can be saved for future use
8 a input device which measures/takes readings from the surroundings/environment
b • moisture sensor:
• measures water content of the soil
• alerts Anna when soil is too dry/too wet
• maintains correct water level in the soil
• pH sensor:
• measures how acidic/alkaline the soil is
• alerts Anna when there may be something polluting the soil
• maintains correct pH level of the soil
• light sensor:
• measures brightness of the surroundings
• alerts Anna when fruit has too little/too much light
• temperature sensor:
• measures the temperature of the surroundings
• alerts Anna when it is too hot/too cold for optimum growing conditions
• gas/O2/CO2 sensor:
• measures amount of CO2 in the air
• alerts Anna if CO2 levels are too high/too low
• humidity sensor:
• measures the water content of the air
• alerts Anna if the air is too dry/too damp
• infrared sensor/motion sensor:
• measures infrared/microwaves
• detects intruders/wild animals
• pressure sensor:
• measures the weight of fruit fallen to the ground …
• … to alert Anna about how much fruit has fallen from the trees
4 Software
Answers to activities
4.1
1 Software System software Application software
Screensaver
Anti-virus software
Control and measurement software
Printer driver
Video editing software
Compiler
QR code reader
On-screen calculator
Operating system software
2 a buffer
b • data sent to printer buffer
• meanwhile, data from download/video buffer is sending data to video player
• once printer buffer is full, attention returned to video download and video buffer starts
to fill again
• document starts to print
• when printer buffer is empty, an interrupt is sent to microprocessor requesting
more data
• microprocessor temporarily halts video download process to service printer
• more data is sent to the printer buffer
• meanwhile video player plays movie
• if video buffer is at minimum value, an interrupt is sent to stop other processes to allow
video buffer to start filling again
• process goes on until whole document is printed out
c interrupt sent to CPU indicating an error and message appears on screen; printing process
suspended until new black ink cartridge is installed
3 Human computer interface can be CLI or GUI; permits user to interact with computer
Multitasking allows computer to carry out several tasks at the same time
(allocating resources to each task)
Platform (to run software) all apps come under the control of OS; manages movement
of data into and out of RAM to allow software to run with
required resources
User account management allows more than one user to log onto a computer; each user
is allocated separate parts of memory; administrator has
overall control
Managing files carries out specific tasks (for example, create, open, close,
delete, rename, copy, etc.); maintains directory structures;
monitors access control mechanisms and ensures they are
maintained; loads files into memory as required
Hardware management involves management of all I/O devices; communicates
with devices via device drivers; ensures allocation of
resources according to priority; manages queues and buffers
Memory management manages RAM and keeps track of which apps are using
memory locations; prevents competing apps from using the
same memory locations
Interrupt handling handles interrupts from hardware and software to ensure
they are serviced in correct priority and that all devices
have access to the CPU and resources as required
System security ensures the integrity, confidentiality and availability of data
is maintained; use of passwords, maintaining access rights,
and so on
4.2
1 True False
An assembler translates a high-level language program.
It is more difficult to write a program in a low-level language.
Java is an assembly language.
It is quicker to develop a program using a high-level language.
You always need a compiler to run a compiled program.
A program that is interpreted takes a longer time to run than
a compiled program.
Low-level languages are machine dependent.
2 a • Auto-completion means that an IDE can automatically show the reserved words or
variable names that are available for use, so that the correct one can be picked from
a list.
• Prettyprinting – code editors can colour code parts of a program, for example reserved
words or strings and automatically lay out the program in a meaningful way.
• Translators are supplied as part of the IDE; these can be compilers or interpreters
or both.
b A compiler translates the whole program written in a high-level language into machine
code program. An interpreter executes a program written in a high-level language by
translating then executing each line of the program.
A compiler can produce a file containing the translated machine-code program that can be
executed without the compiler, whereas an interpreter will always need to be present
during the execution of an interpreted program.
c Assembly language programs can be smaller in size and execute tasks more quickly as
fewer instructions are used, programs can also control specialist hardware using
appropriate simple commands.
2 a virus scanner
b defragmentation
c security software
d screen saver
e device driver
3 a provide a platform for the execution of apps and also provides an HCI (human-computer
interface), memory management, security management and management of user accounts,
hardware management (e.g. keyboards and monitors), file management, handles interrupts,
manages multitasking (i.e. running more than one application at a time)
b memory management system which gives the impression that the RAM is larger than it is;
involves moving data into and out of RAM and HDD/SSD
c this occurs when large volumes of data are being moved in and out of HDD; involves a
large number of head movements
d program within the operating system that allows a user to run several applications at the
same time; but only one app is actually 'active' at any given time
e signal sent from a device or software to a processor to temporarily halt the process
currently being run
9 As the program has already been written it can be translated using a compiler as the
development has already been done. This means that there would be an executable program
available in binary that can be run on his friend’s computer without the use of any additional
software. Pedro knows that his friend’s internet connection is very slow, and the compiled
program is smaller than the original program so there will be less data to transmit, which
means that it will take less time for the program to arrive and the transmission is more likely to
be successful.
• allows social networking sites to recognise certain preferences and browsing history
• allows different languages to be used on web pages automatically/personalised web
pages stored
• indicates if customer is new or returning
3
Feature Internet World Wide Web
b If block 4 is hacked and any data is changed, then the hash value for the block will change;
this will result in the chain being broken since block 5 can no longer point to block 4.
2 • cryptocurrency uses cryptography to track transactions
• cryptocurrency is decentralised unlike digital currencies which are centralised
• traditional digital currencies are regulated by central banks and governments
• unlike normal digital currencies, cryptocurrency transactions are publicly available and can
be tracked/money monitored
• cryptocurrency uses blockchaining
5.3
1 a b c
Three from:
brute force attacks to crack passwords make passwords difficult to
crack and change them often
data interception tapping into networks to obtain use private lines/networks and
information encrypt all data
denial of service ‘… which cause it to crash use a malware checker, firewalls
attack and email filters
hacking illegal access to a computer firewalls and passwords
system (including biometrics)
malware (worms, deletion or altering of data use up-to-date anti-malware
viruses, spyware, …) software
phishing legitimate-looking emails which don’t open links in emails, use
contain links to fake websites up-to-date browsers, look out for
https, check if url looks
legitimate
pharming code on HDD/SSD or server use anti-virus software to detect
which redirects browser to fake website tampering, check
website without user’s spelling of websites
knowledge
social engineering cybercriminal creates social be aware of scam text messages,
situation that can lead a victim phone calls, memory sticks left
to dropping their guard using: lying around on purpose, and
instant messaging, scareware, so on
phishing, baiting or phone calls
2 • worm: type of stand-alone virus that can replicate itself with the intention of spreading to
other computers/networks; often uses networks to search out computers with weak security
• ransomware: programs that encrypt data on a user’s computer; a decryption key is sent
back to the user once they pay a sum of money (ransom); they are often sent via a Trojan
horse or by social engineering
• Trojan horse: malicious programs often disguised as legitimate-looking software; they
replace all or part of the legitimate software with the intent of carrying out some harm to
the user’s computer system
5.6
1 a two-step verification
b proxy server
c privacy settings
d SSL
e firewall
f DNS
g biometrics
h authentication
i social engineering
j pharming
2 A browser requests an SSL/TLS digital certificate from the website it is trying to access. This is
sent from the web server to the user’s browser, containing a public key which can be used to
authenticate the website. Once the digital certificate is authenticated, the browser lets the web
server know, and secure communication can begin.
3 a Three from:
• Are there spelling or grammar errors?
• Does the email FROM address look like it is real?
• Is the domain name in the email address spelt correctly, or does it exactly match the
real company?
• Is the email addressed to you?
• Is there a clickable link? If so, what address does the link point to when you hover over
it? (DO NOT CLICK THE LINK!) It may not match the expected website.
• If it claims to be from a real company, log into your account with the company without
using the link.
b Three from:
• poor spelling and grammar
• not addressed to the user
• WW and Co does not look like a real company
• the email address which this is from does not look like a real or reputable company
• there is no further information in the email, such as details about the company itself
• reputable companies would not expect a customer to click on a link in an email to pay
an account
• does not look professional
b Two step verification – extra security that means that even if passwords are stolen
criminals cannot gain access to the bank account. It requires some biometric
identification – this would limit access to specified employees only.
c • checks for any unusual network traffic and blocks access to the local network
• can be used to only allow specified external connections, so that all traffic is blocked
apart from these specified sites
• any known undesirable sites can be added to a list of blocked network sites
d • passwords/biometrics
• levels of access
• proxy servers
• physical security methods – e.g. PCS in locked rooms, etc.
3
4 a Order: C, E, A, B, D
b • student places finger on scanner
• map of fingerprints taken and converted to digital image
• data sent to a computer
• fingerprint map compared to those stored
• if recognised, the database is updated to show student present (including time and
date of entry)
• on leaving, the same process is carried out and the database is again updated to show
the date/time student left the school premises
5 a Four from:
• instant messaging – links embedded in messages to fake websites
• scareware – pop-up message claiming, for example, user’s computer is infected with a
virus and user downloads the fake virus checker
• emails/phishing – apparently genuine emails sent out which contain links to
fake websites
• baiting – cybercriminal leaves malware-infected memory stick so that it can be easily
'found'; once inserted into a computer, the malware is transferred
• phone calls – so-called IT professional calls a user on their mobile phone claiming their
device has been compromised and they are advised to download software which lets
the cybercriminal take over their device
b • Stage 1 – victim is identified and necessary information is gathered
• Stage 2 – victim is targeted by the chosen method
• Stage 3 – attack on victim takes place and information is gathered or disruption to their
system done
• Stage 4 – when cybercriminal has achieved their goal, all traces of the attack
are removed
c i digital currency exists purely in a digital format; there is no physical money
(fiat currency); digital currency involves electronic transfer of funds
ii if a hacker accessed a block and changed anything (for example, an amount
of money) …
• … the hash value of the block would change
• this means that all blocks beyond the hacked block would now be invalid because
the chain would be broken
• use of 'proof-of-work' is necessary before a block can be added to the chain …
• … thus preventing a hacker quickly creating a new block to complete the chain
6 a Used for layout of content – this structure is defined by HTML tags, e.g. for each heading
and paragraph text.
b browser
Internet Protocol address (IP address)
web server
Hypertext Markup Language (HTML)
7 a SSL is a security protocol:
• it encrypts any data that is sent
• it uses/sends digital certificates …
• … which are sent to the user’s browser …
• … that contains the gallery’s public key …
• … that can be used to authenticate the gallery
• once the digital certificate is authenticated, the transaction can begin
b True False
Statement
() ()
• more consistent – each bottle will have almost exactly the same amount of
each ingredient
• less expensive over time as it can replace most of the workforce who would need to
monitor the process 24 hours a day
• less wastage and more efficient use of materials
• higher productivity
Disadvantages:
• expensive to set up
• needs considerable testing
• possible for a set of conditions to occur that were never considered during testing
• automated systems always need enhanced maintenance which can be expensive
• any computerised system is subject to cyberattacks
6.2
• needs camera to pick up parallel lines in parking spot
• extra data needs to be width and length of gap (infrared and ultrasonic sensors can be used
to find these values)
• data needs to indicate that no vehicle is already in the parking space
• parallel parking will use cameras which will search out white (parallel) lines and ensure
that the distance between vehicle and white lines is consistent
6.3
• the computer takes readings from sensors in the car's front bumper …
• … to calculate the distance between the car and the vehicle in front
• the computer takes additional sensor readings to determine the speed of the car
• the computer calculates required safe braking distance
• data from the (given) table is then used and the computer determines if the calculated
braking distance is greater than the data in the table ….
• … if braking distance is greater than safe distance (in table) then brakes are applied and
accelerator/throttle also reduced and warning signal/light produced
• if distance between vehicles is OK then no action taken
6.4
Students should produce a table showing all the advantages and disadvantages of using an
automated weather station. This will require research using the internet or a local weather
station (if it exists). No answer has been supplied because this answer will vary from country to
country and students will need to make their own judgements.
6.5
1 • data gathered automatically from various locations around the world …
• … could all be collated over time and patterns of global weather changes
automatically generated
• automatic projection of key weather data into the future to predict weather could then be
checked for its accuracy (by comparison of predicted weather with ACTUAL weather)
• results of this comparison would allow the climate change model to be modified
2 • three sensors needed: temperature, light and moisture
• all three sensors send data continuously to a microprocessor
• data would need to be converted to digital (using ADC) if necessary
• if temperature readings < pre-set value, the microprocessor sends a signal to
the actuators …
• … to switch on the heating system/close the windows
• if temperature readings >= pre-set value, the microprocessor sends a signal to
the actuators …
• … to operate motors to open windows (and switch off heaters)
• if light level readings < pre-set value, the microprocessor sends a signal to the actuators …
• … to operate motors to open blinds (and turn on artificial lighting)
• if light level readings >= pre-set value, the microprocessor sends a signal to
the actuators …
• … to operate motors to close blinds (and turn off artificial lighting)
• if moisture level readings < pre-set value, the microprocessor sends a signal to
the actuators …
• … to switch on water pump to irrigate soil
• if moisture level readings >= pre-set value, the microprocessor sends signals to
the actuators …
• … to switch off water pumps
• process is continuous
3 • cameras read road signs (60 kph) and software converts the images into a text file
• … which allows the microprocessor to interpret road signs
• if the car’s speed > 60 kph, the microprocessor sends a signal to the actuators …
• … to operate motors to apply the brakes and/or reduce throttle position
• if the car’s speed < 60 kph, the microprocessor sends a signal to the actuators …
• … to operate motors to increase throttle position
• sensors in the car’s bumpers/fenders will ensure a safe distance between car and vehicle in
front is maintained (by applying brakes and altering throttle as necessary)
• the Sat Nav calculates the car’s position on a map
• data is sent to a central computer which checks optimum driving conditions
• if present driving is not the same as stored driving parameters, then computer sends signals
to actuators to change gears and apply brakes as necessary
4 Parts i and ii
Step 1
A sensor detects a vehicle and sends a signal to instruct a camera to capture an image of
the front of the vehicle (often an infrared camera is used to give a clearer image and for use
at night).
Step 2
a An algorithm is used to locate and isolate the number plate from the image taken by the
camera. This algorithm also takes into account the size of the number plate and any
damage or orientation.
b
c Each character is then recognised using optical character recognition (OCR) software. The
characters are converted into a string of editable text by the software.
d This text string is then stored on a database.
Step 3
Once all of this has happened, the car park barrier is raised and the motorist is issued with a
ticket. The ticket shows the date and time of entering the car park.
Step 4
When the motorist returns to the car park, they insert their ticket into a machine which
calculates the car park charges. The payment is registered on the database.
The motorist then drives to the exit barrier and the ANPR system again reads the number plate
and checks its database. If the number plate is recognised (and payment made), the exit barrier
is raised.
iii Advantages:
• no need to employ car park security guards which saves money
• much faster system than having to check a ticket at the exit; car parks can issue tickets
on entry, but this ticket is simply used for payment purposes by the motorist before
leaving the car park and isn’t used at the exit since payment will now be linked to the
number plate on the car
• can be used to automatically control the entry and exit to a car park or private roads
• can be used as a security system; preventing illegal parking and preventing
unauthorised access to private car parks
Disadvantages:
• there is a lack of manned security car park surveillance which could lead to vandalism
(and other crimes) since nobody is checking on a regular basis; CCTV is often used,
but this is often just used 'after the event'
• invasion of privacy issues due to the recording of driver’s number plates
• damaged or very dirty number plates won’t be recognised by the system
• number plate cloning; the ANPR system only recognises the number plate and not the
car, so it is possible for a car to be fitted with a cloned number plate thus by-passing
car park security, for example
6.6
Each student should produce a presentation in the form of a table which highlights the
advantages and disadvantages of immersive games consoles. The table should include research
into which sensors are used (for example, accelerometers, proximity, magnetic field and
pressure), together with a description of the function of each sensor identified.
6.7
1 a i flow sensors, temperature sensors
ii light sensors, infrared/motion sensors
iii infrared/motion sensors, cameras, pressure sensors
b i Advantages, two from:
• faster response to non-optimum conditions
• more precise monitoring
• greater consistency of product(s)
• 24/7 monitoring
Disadvantages:
• expensive to set up initially and to maintain
• may not respond well to unusual conditions
ii Advantages, two from:
• saves money on unnecessary lighting
• completely automated system
• better control of lighting
Disadvantages, two from:
• expensive to set up
• needs expertise to program the lights exactly as required
• may require specialist equipment
iii Advantages, two from:
• much safer
• fewer staff needed
• fewer delays caused by people pulling emergency cord if someone has an item
stuck in the door
Disadvantages, two from:
• still requires human monitoring
• expensive to set up and implement
• requires extensive testing to make sure it works
2
Statement True False
6.9
1 Examples:
• harvesting/picking of vegetables and fruit
• weed control
• phenotyping (plant growth and health)
• seed-planting and fertiliser distribution
• autonomous labour-saving devices
Harvesting and picking:
• robots have been designed to do this labour-intensive work; they are more accurate (only
picking ripe fruit, for example) and much faster at harvesting
• for the reasons above, this leads to higher yields and reduces waste – for example, Vegebot
(Cambridge University) uses cameras to scan, for example, a lettuce and decide whether or
not it is ready to be harvested
• a second camera in Vegebot (near the cutting blades) guides an arm to remove the lettuce
from its stalk with no damage.
Weed control:
• weed management robots can distinguish between a weed and crop using AI
• examples of weed control robots are being used in France (by Mouton Rothschild) to
remove weeds between grape vines in their vineyards; this saves considerably on labour
costs and improves vine growth
• weed control robots use GPS tracking to stay on course to move along the rows of vines
and remove the weeds; a weed removal blade is operated by an actuator under the control
of the controller (microprocessor) in the robot
• very often a drone (flying robot) is used first to do an aerial view of the vineyard, so that a
programmed course of action can be produced, which is then sent to the weed control
robot’s memory.
Phenotyping:
• phenotyping is the process of observing physical characteristics of a plant in order to assess
its health and growth
• robots designed to do phenotyping are equipped with sensors (including spectral sensors
and thermal cameras) that can create a 3D image/model of the plant, thus allowing it to be
monitored for health and growth
• machine learning is used to recognise any issues with leaves (for example, if they have a
blight or have the wrong colour) so that the robot can convey this back to the farmer
• these robots are much more accurate and faster at predicting problems than when done
manually.
6.10
Essay produced by student on robotics in entertainment including their advantages and
disadvantages.
6.11
1 Advantages Disadvantages
• robots are capable of working in • robots can find it difficult to do 'non-
conditions which may be hazardous standard' tasks (for example,
to humans windscreen being fitted to a car
• robots work 24/7 without the need to stop is cracked)
• robots are less expensive in the long run • robots can lead to higher
(since there will be fewer salaries to pay) unemployment amongst manual
labourers
• robots are more productive than humans
(higher productivity) • there is a risk of deskilling when
robots take over certain tasks (for
• although not necessarily more accurate,
example, welding and paint spraying)
robots are more consistent
• factories can now be moved to
• robots are better suited to boring,
anywhere in the world where
repetitive tasks than humans (therefore
operation costs are lower (leading
less likely to make mistakes)
again to unemployment in some
• there will be less cost in heating and countries)
lighting (robots don’t need good light
• robots are expensive to buy and set up
or warmth)
in the first place
4 sensors
microprocessor
environment
end-effectors
controller
programs
repetitive
adaptive
5 a • sensors can use radar/sonar to detect objects under the sea
• cameras take images which allow device to be recognised
• if ship recognised, then microprocessor sends signals to actuators to operate
digital cameras
• actuators also used to operate electric motors in undersea robots to allow them to move
around the shipwreck
b i • sensors can be used to recognise samples
• data sent to microprocessor after digital conversion (using ADC)
• if rock samples recognised, microprocessor sends signals to actuators to …
• … stop robot’s motors
• … to operate 'claws' to take samples of rock
ii camera used to recognise terrain, recognise potential rock samples and to allow
manoeuvring safely
c Advantages include:
• harsh environment which is dangerous to humans
• more precise than humans
• can operate non-stop
• no need for any humans to be present (useful on long journeys, such as visit to Mars
which takes several years)
Disadvantages include:
• expensive devices to design, test and manufacture
• difficult to repair such devices remotely if they break down
• as with any robot, they are limited to the functions programmed in (although some
ability to reprogram will exits – they may not have the necessary attachments to carry
out a newly required task)
d Could be used in defusing bombs, clean-up operations in nuclear plants (for example,
Chernobyl), etc.
6.12
a knowledge base
b explanation system
c expert system shell
d robotics
e rules base
6.13
1 artificial intelligence
cognitive
expert systems
explanation system
inference engine
search engine
inference rules
2 a • Is there anything showing on the screen?
• Can sound be heard through internal loud speakers?
• If external speakers are plugged into another computer, do they work?
• Are the connections between the speakers and the computer OK?
(or any series of logical questions)
b • oil and mineral prospecting
• diagnosis of patient’s illness
• tax and financial calculations
• strategy games, such as chess
• logistics (parcel deliveries)
• identification of plants, animals and chemicals (for example)
3 a • sub-set of AI
• algorithms are trained and learn from past experiences and examples
• offer fast and accurate outcomes due to very powerful processing capability
• ability to manage and analyse considerable volumes of complex data
• machines learn through data acquisition to solve problems
• can make decisions without being programmed to do so
b AI Machine learning
this is the practice of getting a machine to
represents simulated intelligence
make decisions without being
in machines
programmed to do so
the aim is to make machines that learn
the aim is to build machines which are
through data acquisition, so that they can
capable of thinking like humans
solve new problems
2 • accelerometers
• to measure and respond to tilting of device
• to respond to forward/backward and side-to-side movement
• proximity sensors
• used in smart touch pads …
• … to detect hand/finger positions
• embedded accelerometers and other sensors in game consoles
• allow increased human interaction with the game …
• … giving a more immersive games experience
3 a • data from proximity sensor compared to pre-set value
• pre-set value shows minimum distance
• if sensor value is the same/lower
• then the microprocessor sends a signal to actuators to stop the robot
• if sensor value higher
• then no action is taken
• whole process is continuous
b i • light sensors in offices
• light sensors and infrared/motion sensors in offices and corridors
• if a person is detected entering an office or corridor, a signal is sent by
microprocessor to turn on the lights
• if light sensor value < stored value for office the microprocessor sends signal to
turn on lights
ii Advantages:
• less expensive, because lights only on when office or corridor occupied
• longer bulb life because switched on for less time
• possible to program light displays if required
Disadvantages:
• expensive to set up initially
• will require more maintenance than a manual system
4 a Expert
Task Control Monitor
system
automatic control of the atmosphere in a large greenhouse
(to ensure ideal growing conditions)
b Four from:
• explanation system informs user of the expert system’s reasoning behind its
conclusions and recommendations
• inference engine is a type of search engine used in an expert system that examines the
knowledge base for information that matches the queries
• knowledge base is a repository of facts which contain all the knowledge of the expert
system; it is composed of a collection of objects and attributes
• rules base is a collection of inference rules used to draw conclusions, based on inputs
• user interface is a method whereby the expert system interacts with the user; the
interaction can be through dialogue boxes or command prompts; questions are often
simple Yes/No responses and are based on responses to previous questions
5 a • sensors (infrared, pressure) indicate the presence of a person trying to leave/enter
the train
• cameras can also be used to check that nobody is trapped in the doors
• sensors send data back to a microprocessor …
• … after being converted to digital (using an ADC)
• camera data is put through an algorithm which determines if a person is trapped in
a door
• if camera or sensor data indicate a trapped person …
• … a signal is sent to actuators to operate motors to open doors/halt the closing of doors
• if sensors and camera detect no presence of passenger in door area, …
• … signals are sent to actuators to operate motors to close doors
• the train is then able to move
8 a end effector
b inference engine
c autonomous
d machine learning
e automated systems
f artificial intelligence
g chatbots
h search bot/web crawler
i robotics
j cognitive
k attributes
l knowledge base
m drone
n controller
o inference rules
7.3
Amount 100
TotalPrice 350
Discount 0.2
FinalPrice 280
Name "Nikki"
Message "Hello Nikki"
7.4
OUTPUT "Please enter a mark "
INPUT Mark
7.8
Telephone number – the number needs to be the one that is required as well as having the
necessary characteristics.
Pupil's name – the name needs to be the one that is associated with the pupil.
Part number – a part number could have the required format but not be for the part intended.
7.9
For example:
Normal test data: 7, 34, 55, 67, 74, 83, 21, 45, 72, 64; Expected result: 54.2
(Other values acceptable.)
7.10
For example:
Erroneous test data: −7, 1001; Expected result: both values rejected
(Other values acceptable.)
7.11
1 Boundary test data for 100 is: 100, 101; Expected result: 100 accepted, 101 rejected
2 Normal test data: 2, 14, 15, 6, 7, 13, 20, 4, 10, 9; Expected result: 10
Normal test data: 17, 13, 15, 15, 14, 16, 2, 8, 7, 6; Expected result: 11.3
Erroneous test data: −7, 23; Expected result: both values rejected
Boundary test data: −1, 0 and 20, 21
Expected results: −1 rejected, 0 accepted and 20 accepted, 21 rejected
7.12
Answer in chapter (page 285).
7.13
A B C X OUTPUT
1 4 4 4
2 8 8
3 19 19
4 17
5 3 3
6 11
7 6
8 1 1
9 13
10 9 19 1
7.14
Temperature
First Last Index Swap Temp
[1] [2] [3] [4] [5] [6] [7] [8]
1 8 1 FALSE 35 31 32 36 39 37 42 38
TRUE 35 31 35
2 TRUE 35 32 35
5 39 39 37 39
7 42 38 42
7 1 FALSE
6 TRUE 39 38 39
6 1 FALSE
7.15
Sample data: −1, −7, −11, −19, −3, −20, −9, −4, −6, −8
A B C X OUTPUT
0 0 100
1 -1
2 -7 -7
3 -11 -11
4 -19 -19
5 -3
6 -20 -20
7 -9
8 -4
9 -6
10 0 -3
0 -20
A B C X OUTPUT
1 12390 12390
2 0
3 77
4 359
5 -2
6 -89
7 5000
8 21
9 67
12390,-97
7.18
0, 26
Expected results rejected – erroneous data
1, 25
Expected results: Your tickets cost 20
Your tickets cost 400 – extreme data
9, 10
Expected results: Your tickets cost 180
Your tickets cost 180 – normal data
19, 20
Expected results: Your tickets cost 342
Your tickets cost 320 – normal data
Extra test data:
0, 1
Expected results: 0 rejected
1 Your tickets cost 20 – boundary data lower bound
26, 25
Expected results: 26 rejected
25 Your tickets cost 400 – boundary data upper bound
-30, 200
Expected results rejected – erroneous data
7.19
1 Change FOR Test ← 1 to 4 // outer loop for the tests
to FOR Test ← 1 to 2 // outer loop for the tests
remove 3 : SubjectName ← "English" and 4 : SubjectName ← "IT"
change FOR StudentNumber ← 1 TO 600
to FOR StudentNumber ← 1 TO 5
change SubjectAverage ← SubjectTotal / 600
to SubjectAverage ← SubjectTotal / 5
change OverallAverage ← OverallTotal / 2400
to OverallAverage ← OverallTotal / 10
The code should now look like this:
// initialisation of overall counters
OverallHighest ← 0
OverallLowest ← 100
OverallTotal ← 0
FOR Test ← 1 to 2 // outer loop for the tests
// initialisation of subject counters
SubjectHighest ← 0
SubjectLowest ← 100
SubjectTotal ← 0
CASE OF Test
1 : SubjectName ← "Maths"
2 : SubjectName ← "Science"
ENDCASE
FOR StudentNumber ← 1 TO 5 // inner loop for the students
REPEAT
OUTPUT "Enter Student", StudentNumber, "’s mark for ", SubjectName
INPUT Mark
UNTIL Mark < 101 AND Mark > -1
IF Mark < OverallLowest THEN OverallLowest ← Mark
IF Mark < SubjectLowest THEN SubjectLowest ← Mark
IF Mark > OverallHighest THEN OverallHighest ← Mark
IF Mark > SubjectHighest THEN SubjectHighest ← Mark
OverallTotal ← OverallTotal + Mark
SubjectTotal ← SubjectTotal + Mark
NEXT StudentNumber
SubjectAverage ← SubjectTotal / 5
OUTPUT SubjectName
OUTPUT "Average mark is ", SubjectAverage
OUTPUT "Highest Mark is ", SubjectHighest
OUTPUT "Lowest Mark is ", SubjectLowest
NEXT Test
OverallAverage ← OverallTotal / 10
OUTPUT "Overall Average is ", OverallAverage
OUTPUT "Overall Highest Mark is ", OverallHighest
OUTPUT "Overall Lowest Mark is ", OverallLowest
Test data (sample – yours might be different): 1, 99, −1, 101, 20, 80, 30, 70, 40, 60, 50, 50
2 Trace table:
1 1 1 1 1 1 1 1
Enter student 1’s
mark for Maths
2 99 99 100 99 100
Enter student 2’s
mark for Maths
3 -1
Enter student 3’s
mark for Maths
101
Enter student 3’s
mark for Maths
20 120 120
Enter student 3’s
mark for Maths
4 80 200 200
Enter student 4’s
mark for Maths
5 30 230 230
Enter student 5’s
mark for Maths
Maths
Average mark is 46
46
Highest mark is 99
Lowest mark is 1
2 0 100 0
1 70 70 70 70 300
Enter student 1’s
mark for English
2 40 40 110 340
Enter student 2’s
mark for English
3 60 60 170 400
Enter student 3’s
mark for English
4 50 50 220 450
Enter student 4’s
mark for English
5 50 50 270 500
Enter student 5’s
mark for English
English
Average mark is 54
54
Highest mark is 70
Lowest mark is 40
Overall average
mark is 50
50
Overall highest
mark is 99
Overall lowest
mark is 1
7.20
1 Total ← 0
FOR Counter ← 1 TO 10
REPEAT
OUTPUT "Enter positive number "
INPUT Number
UNTIL Number > 0
Total ← Total + Number
NEXT Counter
Average ← Total / 10
OUTPUT "Average is ", Average
OUTPUT "Total is ", Total
2 Total ← 0
Counter ← 0
REPEAT
REPEAT
OUTPUT "Enter positive number, -1 to finish "
INPUT Number
UNTIL Number > 0 OR Number = -1
IF Number <> -1
THEN
Total ← Total + Number
Counter ← Counter + 1
ENDIF
UNTIL Number = -1
Average ← Total / Counter
OUTPUT "Average is ", Average
OUTPUT "Total is ", Total
3 For 1, I chose a FOR … NEXT loop because it has a fixed number of iterations.
For 2, I chose a REPEAT … UNTIL loop because there must be at least one number in the list
but the number of iterations is unknown.
Answers to exam-style questions
Answers to questions 8 and 9 in this section are example answers for past paper questions. The details of
the relevant past paper can be found with the corresponding exam-style question in the Student’s Book.
1 • Inputs – the data used by the system that needs to be entered while the system is active
• Processes – the tasks that need to be performed using the input data and any other
previously stored data
• Outputs – information that needs to be displayed or printed for the users of the system
• Storage – data that needs to be stored in files on an appropriate media for use in the future
3 a Diners – range check 2 to 12 inclusive, presence check and type check of integer
Bill – range check 10 to 500 inclusive, presence check and type check of real
b Test data (sample – yours might be different):
• Normal data: 5 diners and a bill of $90.00
Expected result: $18.00
• Normal data: 8 diners and a bill of $69.00
Expected result: $8.63
c Test data (sample – yours might be different):
• Abnormal data: 15 diners and a bill of $5.00
Expected result: both values rejected
d • Boundary data for lower bounds 1 diner and 2 diners and bills of $9.99 and $10.00
Expected result: 1 and $9.99 both values rejected, 2 and $10.00 $5.00
• Boundary data for upper bounds 12 diners and 13 diners and bills of $500.00 and
$500.01
Expected result: 13 and $500.01 both values rejected, 12 and $500.00 $41.67
4 Validation – the automated checking by a program that data is reasonable before it is accepted
into a computer system
Verification – checking that data has been accurately copied from another source and input into
a computer or transferred from one part of a computer system to another
5 Name:
Validation checks:
• presence to ensure name is entered
• length check to ensure there are not too many letters
Verification check – yes to ensure that the name entered is the one intended and there are no
typing errors
Date of birth:
Validation checks:
• presence to ensure date of birth is entered
• format check to ensure that all the components of the data are in range
• range check to ensure that the value for the date is realistic
Verification check – yes to ensure that the date entered is the one intended and there are no
typing errors
Password:
Validation checks:
• presence to ensure password is entered
• length check to ensure there are the appropriate number of characters
• format check for any special rules, for example at least one digit
Verification check – yes to ensure that the password entered is the one intended and there are
no typing errors
Phone number:
Validation checks:
• presence to ensure phone number is entered
• length check to ensure there are the appropriate number of digits/characters
• format check for any special rules, for example must start with +44
Verification check – yes to ensure that the phone number entered is the one intended and there
are no typing errors
6 a Counter Accept Reject Length Breadth Size OUTPUT
0 0 0
1 1 15 10 150
2 2 20 17 340
3 1 32 10
4 2 30 35
5 3 30 15 450
6 3 30 28 840
7 4 25 25 625
8 4 20 15 300
9 5 40 20 800
10 5 12 10 120 5 5
d Test data: 1, 0, 67, 10, 22, −10, 3, 7, 2, 8, 1, 9 (sample – yours might be different).
1 extreme, 0 erroneous, 67 normal, 10 normal, 22 normal, −10 erroneous, 3 normal,
7 normal, 2 normal, 8 normal, 1 normal and 9 normal.
8 a Number1 Number2 Sign Answer OUTPUT
5 7 + 12 12
6 2 - 4 4
4 3 * 12 12
7 8 ? 0
0 0 / (0)
b CASE Sign OF
ꞌ+ꞌ : Answer ← Number1 + Number2
ꞌ-ꞌ : Answer ← Number1 - Number2
ꞌ*ꞌ : Answer ← Number1 * Number2
ꞌ/ꞌ :
Answer ← Number1 / Number2
OTHERWISE Answer ← 0
ENDCASE
9 a To ensure no changes are made on input, because the details do not have fixed values and
there is no clear set of rules that can be used for validation.
The programmer could ask the contributor to type in each detail twice and then check that
both values are equal. If they are not equal, then the input should be rejected.
b Email – check for @ to ensure that it is an email address. Password – length check to
ensure sufficient characters have been entered.
8 Programming
Answers to activities
8.1
Python
print("Hello World")
Visual Basic
Module Module1
Sub Main()
Console.WriteLine("Hello World")
Console.ReadKey()
End Sub
End Module
Java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
8.2
Pseudocode
DECLARE radius, length : REAL
CONSTANT PI = 3.142
Python
# Python does not require separate declarations...
# ...values are simply assigned as required
# Python does not differentiate between constants and variables
radius = 10.0
length = 10.0
PI = 3.142
Visual Basic
Dim radius As Decimal
Dim length As Decimal
Const PI As Decimal = 3.142
Java
final double PI = 3.142;
double radius;
double length;
8.2a
Python
StoreIngeger = int(input())
StoreDecimal = float(input())
StoreLetter = input()
StoreText = input()
StoreBoolean = bool(input())
Visual Basic
StoreInteger = Integer.parse(Console.Readline())
StoreDecimal = Decimal.parse(Console.Readline())
StoreLetter = Console.Readline()
StoreText = Console.Readline()
StoreBoolean = Bool.parse(Console.Readline())
Java
int StoreInteger = myObj.nextInt();
double StoreDecimal = myObj.nextDouble();
char StoreLetter = myObj.next);
String StoreText = myObj.next();
Boolean StoreBoolean = myObj.nextBoolean();
8.3
Python
ConstPi = 3.142
radius = float(input("Please enter the radius of the cylinder "))
length = float(input("Please enter the length of the cylinder "))
volume = radius * radius * length * ConstPi
print("Volume of the cylinder is ", volume)
Visual Basic
Module Module1
Public Sub Main()
Dim radius As Decimal
Dim length As Decimal
Dim volume As Decimal
Const PI As Decimal = 3.142
Console.Write("Please enter the radius of the cylinder ")
radius = Decimal.Parse(Console.ReadLine())
Console.Write("Please enter the length of the cylinder ")
length = Decimal.Parse(Console.ReadLine())
volume = radius * radius * length * PI
Console.WriteLine("Volume of cylinder is " & volume)
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Cylinder
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
final double PI = 3.142;
double radius;
double length;
}
}
8.4
Python
num = int(input("Please enter a number "))
if num >= 100:
print ("100 or over")
else:
print ("less than 100")
Visual Basic
Module Module1
Sub Main()
Dim num As Integer
Console.Write("Please enter a number ")
num = Integer.Parse(Console.ReadLine())
If num >= 100 Then
Console.WriteLine("100 or over")
Else
Console.WriteLine("less than 100")
End If
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_4
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
int num;
8.5
Python
num = int(input("Please enter a number "))
if num == 1:
print ("Number equals 1")
elif num == 2:
print ("Number equals 2")
elif num == 3:
print ("Number equals 3")
elif num == 4:
print ("Number equals 4")
else: print ("Invalid number")
Visual Basic
Module Module1
Sub Main()
Dim num As Integer
Console.Write("Please enter a number ")
num = Integer.Parse(Console.ReadLine())
Select Case num
Case 1
Console.WriteLine("Number equals 1")
Case 2
Console.WriteLine("Number equals 2")
Case 3
Console.WriteLine("Number equals 3")
Case 4
Console.WriteLine("Number equals 4")
Case Else
Console.WriteLine("Invalid number")
End Select
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_5_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
int num;
8.6
Python
#count controlled loop
for Counter in range (1, 30, 3):
print(Counter)
#condition controlled loop
Counter = 1
while Counter < 30:
print(Counter)
Counter = Counter + 3
Visual Basic
Module Module1
Sub Main()
Dim Counter As Integer
'count controlled loop
For Counter = 1 To 30 Step 3
Console.WriteLine(Counter)
Next
'condition controlled loop
Counter = 1
Do
Console.WriteLine(Counter)
Counter = Counter + 3
Loop Until Counter >= 30
Console.ReadKey()
End Sub
End Module
Java
class Activity_8_6_Java
{
public static void main(String args[])
{
int Counter;
//count controlled loop
for (Counter = 1; Counter <= 30; Counter = Counter + 3){
System.out.println(Counter);
}
}
}
8.7
Python
Count = 0
TotalSackWeight = 0
SackWeight = float(input("Enter weight of next sack, -1 to finish "))
while SackWeight != -1:
Count = Count + 1
TotalSackWeight = TotalSackWeight + SackWeight
SackWeight = float(input("Enter weight of next sack, -1 to finish "))
print ("Total number of sacks is ", Count)
print ("Total weight of sacks is ", TotalSackWeight)
Visual Basic
Module Module1
Sub Main()
Dim Count As Integer
Dim SackWeight As Decimal
Dim TotalSackWeight As Decimal
Count = 0
TotalSackWeight = 0
Console.Write("Please enter weight of next sack ")
SackWeight = Decimal.Parse(Console.ReadLine())
While SackWeight <> -1
Count = Count + 1
TotalSackWeight = TotalSackWeight + SackWeight
Console.Write("Please enter weight of next sack ")
SackWeight = Decimal.Parse(Console.ReadLine())
End While
Console.WriteLine("Total number of sacks is " & Count)
Console.WriteLine("Total weight of sacks is " & TotalSackWeight)
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_7_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
int Count = 0;
double SackWeight;
double TotalSackWeight = 0;
}
}
8.8
Python
MyName = input("Please enter your full name ")
print ("There are ", len(MyName), " characters in your name")
print ("The first three characters are are ", MyName[0:3])
print ("Upper Case ", MyName.upper())
print ("Lower Case ", MyName.lower())
Visual Basic
Module Module1
Public Sub Main()
Dim MyName As String
Console.Write("Please enter your full name ")
MyName = Console.ReadLine()
Console.WriteLine("There are " & MyName.Length() & " characters in your
name")
Console.WriteLine("The first three characters are are " &
MyName.Substring(0, 3))
Console.WriteLine("Upper case " & UCase(MyName))
Console.WriteLine("Lower case " & LCase(MyName))
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_8_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
System.out.println("Please enter your full name ");
String MyName = myObj.next();
System.out.println("There are " + MyName.length() + " characters in
your name");
System.out.println("The first three characters are " +
MyName.substring(0,3));
System.out.println("Upper case " + MyName.toUpperCase());
System.out.println("Lower case " + MyName.toLowerCase());
}
}
8.9
Python
Number1 = float(input ("Enter first number "))
Number2 = float(input ("Enter second number "))
print("Add ", Number1 + Number2)
print("Subtract ", Number1 - Number2)
print("Multiply ", Number1 * Number2)
print("Divide ", Number1 / Number2)
print("Raise to the power of ", Number1 ** Number2)
Number3 = int(input ("Enter third number "))
print("Number3 * (Number1 + Number2) ", Number3 * (Number1 + Number2))
print("Number3 * (Number1 - Number2) ", Number3 * (Number1 - Number2))
print("(Number1 + Number2) ^ Number3 ", (Number1 + Number2) ** Number3)
Visual Basic
Module Module1
Public Sub Main()
Dim Number1 As Decimal
Dim Number2 As Decimal
Dim Number3 As Integer
Console.Write("Please enter the first number ")
Number1 = Decimal.Parse(Console.ReadLine())
Console.Write("Please enter the second number ")
Number2 = Decimal.Parse(Console.ReadLine())
Console.WriteLine("Add " & (Number1 + Number2))
}
}
8.10
Python
Number1 = float(input ("Enter first number "))
Number2 = float(input ("Enter second number "))
if (Number1 == Number2):
print("Both numbers are equal ")
elif (Number1 > Number2):
print("Numbers are not equal, Number 1 is the largest and Number 2 is the
smallest")
else:
print("Numbers are not equal, Number 2 is the largest and Number 1 is the
smallest")
Number3 = float(input ("Enter third number "))
if (Number1 == Number2) and (Number2 == Number3):
print("All numbers are equal ")
else:
print("All numbers are not equal")
if (Number1 > Number2 and Number2 > Number3):
print("Number 1 is the largest and Number 3 is the smallest")
if (Number1 > Number3 and Number3 > Number2):
print("Number 1 is the largest and Number 3 is the smallest")
if (Number2 > Number1 and Number1 > Number3):
print("Number2 is the largest and Number3 is the smallest")
if (Number2 > Number3 and Number3 > Number1):
print("Number2 is the largest and Number1 is the smallest")
if (Number3 > Number2 and Number2 > Number1):
print("Number3 is the largest and Number1 is the smallest")
if (Number3 > Number1 and Number1 > Number2):
print("Number3 is the largest and Number2 is the smallest")
Visual Basic
Module Module1
Public Sub Main()
Dim Number1 As Decimal
Dim Number2 As Decimal
Dim Number3 As Decimal
Else
If Number1 > Number2 And Number2 > Number3 Then
Console.WriteLine("Number1 is largest and Number3 is
smallest")
End If
If Number1 > Number2 And Number3 > Number2 And Number1 > Number3
Then
Console.WriteLine("Number1 is largest and Number2 is
smallest")
End If
If Number2 > Number3 And Number3 > Number1 Then
Console.WriteLine("Number2 is largest and Number1 is
smallest")
End If
If Number2 > Number1 And Number1 > Number3 And Number1 > Number3
Then
Console.WriteLine("Number2 is largest and Number3 is
smallest")
End If
If Number3 > Number2 And Number2 > Number1 Then
Console.WriteLine("Number3 is largest and Number1 is
smallest")
End If
If Number3 > Number1 And Number1 > Number2 And Number3 > Number2
Then
Console.WriteLine("Number3 is largest and Number2 is
smallest")
End If
End If
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_10_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
System.out.println("Please enter first number ");
double Number1 = myObj.nextDouble();
System.out.println("Please enter second number ");
double Number2 = myObj.nextDouble();
if (Number1 == Number2) {
System.out.println("Both numbers are equal");
} else {
System.out.println("Both numbers are not equal");
if (Number1 > Number2) {
else {
if (Number1 > Number2 && Number2 > Number3) {
System.out.println("Number1 is the largest and Number3 is the
smallest");
}
if (Number1 > Number3 && Number3 > Number2) {
System.out.println("Number1 is the largest and Number2 is the
smallest");
}
if (Number2 > Number1 && Number1 > Number3) {
System.out.println("Number2 is the largest and Number3 is the
smallest");
}
if (Number2 > Number3 && Number3 > Number1) {
System.out.println("Number2 is the largest and Number1 is the
smallest");
}
if (Number3 > Number2 && Number2 > Number1) {
System.out.println("Number3 is the largest and Number1 is the
smallest");
}
if (Number3 > Number1 && Number1 > Number2) {
System.out.println("Number3 is the largest and Number2 is the
smallest");
}
}
}
}
SubjectHigh = 0
SubjectLow = 100
SubjectTotal = 0
For Test = 1 To NumberOfTests
Console.Write("Please enter mark ")
Mark = Decimal.Parse(Console.ReadLine())
If Mark > SubjectHigh Then
SubjectHigh = Mark
End If
If Mark < SubjectLow Then
SubjectLow = Mark
End If
SubjectTotal = SubjectTotal + Mark
Next Test
SubjectAverage = SubjectTotal / NumberOfTests
Console.WriteLine("Average mark for Subject " & Subject & " is "
& SubjectAverage)
Console.WriteLine("Highest mark for Subject " & Subject & " is
" & SubjectHigh)
Console.WriteLine("Lowest mark for Subject " & Subject & " is
" & SubjectLow)
If SubjectHigh > StudentHigh Then
StudentHigh = SubjectHigh
End If
If SubjectLow < StudentLow Then
StudentLow = SubjectLow
End If
StudentTotal = StudentTotal + SubjectTotal
Next Subject
StudentAverage = StudentTotal / (NumberOfTests * NumberOfSubjects)
Console.WriteLine("Average mark for Student " & Student & " is " &
StudentAverage)
Console.WriteLine("Highest mark for Student " & Student & " is " &
StudentHigh)
Console.WriteLine("Lowest mark for Student " & Student & " is " &
StudentLow)
If StudentHigh > ClassHigh Then
ClassHigh = StudentHigh
End If
If StudentLow < ClassLow Then
ClassLow = StudentLow
End If
ClassTotal = ClassTotal + StudentTotal
Next Student
ClassAverage = ClassTotal / (NumberOfTests * NumberOfSubjects *
ClassSize)
Console.WriteLine("Average mark for Class is " & ClassAverage)
Console.WriteLine("Highest mark for Class is " & ClassHigh)
Console.WriteLine("Lowest mark for Class is " & ClassLow)
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_13_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
double ClassAverage, StudentAverage, SubjectAverage;
int Student, Subject, Test, Mark;
int ClassHigh, ClassLow, ClassTotal;
int StudentHigh, StudentLow, StudentTotal;
int SubjectHigh, SubjectLow, SubjectTotal;
ClassHigh = 0;
ClassLow = 100;
ClassTotal = 0;
}
}
8.14
Python
def Stars():
print("************")
print("************")
print("************")
Stars()
Visual Basic
Module Module1
Sub Main()
Stars()
Console.ReadKey()
End Sub
Sub Stars()
Console.WriteLine("************")
Console.WriteLine("************")
Console.WriteLine("************")
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_14_Java
{
static void Stars()
{
System.out.println("***********");
System.out.println("***********");
System.out.println("***********");
}
public static void main(String args[])
{
Stars();
}
}
8.15
Python
def Stars(Number):
for Counter in range(Number):
print("************\n")
Stars(7)
Visual Basic
Module Module1
Sub Main()
Stars(7)
Console.ReadKey()
End Sub
Sub Stars(Number As Integer)
Dim Counter As Integer
For Counter = 1 To Number
Console.WriteLine("************")
Next
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_14_Java
{
static void Stars(int Number)
{
for (int Counter = 1; Counter <= Number; Counter ++)
{
System.out.println("***********");
}
}
public static void main(String args[])
{
Stars(7);
}
}
8.16
Python
def Fahrenheit (Temperature):
return (1.8 * Temperature + 32)
Answer = Fahrenheit(0)
print (Answer)
Visual Basic
Module Module1
Sub Main()
Dim Answer As Decimal
Answer = Fahrenheit(0)
Console.WriteLine(Answer)
Console.ReadKey()
End Sub
Function Fahrenheit(ByVal Temperature As Decimal)
Return 1.8 * Temperature + 32
End Function
End Module
Java
import java.util.Scanner;
class Activity_8_16_Java
{
static double Fahrenheit (double Temperature)
{
return (Temperature * 1.8 + 32);
}
public static void main(String args[])
{
double Answer = Fahrenheit (0);
System.out.println(Answer);
}
}
8.17
Python
def Test():
Number1 = 10
Number2 = 20
Number3 = 30
Answer = Number1 + Number2
print ("Number1 is now ", Number1)
print ("Number2 is now ", Number2)
print ("Answer is now ", Answer)
Number1 = 50
Number2 = 100
Answer = Number1 + Number2
print ("Number1 is ", Number1)
print ("Number2 is ", Number2)
print ("Answer is ", Answer)
Test()
print ("Number1 is still ", Number1)
print ("Number2 is still ", Number2)
print ("Answer is still ", Answer)
print ("Number3 is ", Number3)
Java
import java.util.Scanner;
class Activity_8_17_Java
{
static void Test()
{
int Number1 = 10;
int Number2 = 20;
int Number3 = 30;
int Answer = Number1 + Number2;
System.out.println("Number1 is now " + Number1);
System.out.println("Number2 is now " + Number2);
System.out.println("Answer is now " + Answer);
}
public static void main(String args[])
{
int Number1 = 50;
int Number2 = 100;
int Answer = Number1 + Number2;
System.out.println("Number1 is " + Number1);
System.out.println("Number2 is " + Number2);
System.out.println("Answer is " + Answer);
Test();
System.out.println("Number1 is still " + Number1);
System.out.println("Number2 is still " + Number2);
System.out.println("Answer is still " + Answer);
System.out.println("Number3 is " + Number3);
}
}
Note – the program will not run, try defining Number3 in the main program instead.
8.18
Subject Procedure local variables:
Test, Mark, SubjectAverage, SubjectTotal
Student Procedure local variables:
Subject, StudentAverage, StudentTotal, SubjectHigh, SubjectLow,
8.19
Value1 is 1
Value2 is 3
Value3 is 6.97
8.20
Python
import random
a = int(input ("Enter first integer "))
b = int(input ("Enter second integer "))
AnswerMod = a%b
AnswerDiv = a//b
print(a, "MOD", b, "is", AnswerMod)
print(a, "DIV", b, "is", AnswerDiv)
c = int(random.random() * 200 + 100)
print(c, "is a random number between 100 and 300")
Visual Basic
Module Module1
Sub Main()
Dim a, b, c As Integer
Dim AnswerMod, AnswerDiv As Integer
Console.Write("Please enter the first integer ")
a = Integer.Parse(Console.ReadLine())
Console.Write("Please enter the second number ")
b = Integer.Parse(Console.ReadLine())
AnswerMod = a Mod b
AnswerDiv = a \ b
Console.WriteLine(a & " MOD " & " is " & AnswerMod)
Console.WriteLine(a & " DIV " & " is " & AnswerDiv)
c = CInt(Rnd() * 200 + 100)
Console.WriteLine(c & " is a random integer between 100 and 300")
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
import java.lang.Math;
import java.util.Random;
class Activity_8_20_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
System.out.println("Please enter first integer ");
int a = myObj.nextInt();
System.out.println("Please enter second integer ");
int b = myObj.nextInt();
int AnswerMod = a % b;
int AnswerDiv = a / b;
8.22
Python
MyList=[]
for counter in range(10):
MyList.append (int(input("Enter next value")))
print (MyList)
Visual Basic
Module Module1
Sub Main()
Dim MyList(9), Counter As Integer
For Counter = 0 To 9
Console.Write("Enter next value ")
MyList(Counter) = Integer.Parse(Console.ReadLine())
Next
For Counter = 0 To 9
Console.Write(MyList(Counter) & " ")
Next
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_22_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
int MyList[] = new int[10];
int Counter;
for (Counter = 0; Counter <= 9; Counter ++) {
System.out.print("Enter next value ");
MyList[Counter] = myObj.nextInt();
}
for (Counter = 0; Counter <= 9; Counter ++) {
System.out.print(MyList[Counter] + " ");
}
}
}
8.23
Python
MyTable =[]
for ColumnCounter in range(3):
Column =[]
for RowCounter in range(10):
Column.append(int(input("Enter next value ")))
MyTable.append(Column)
print(MyTable)
Visual Basic
Module Module1
Sub Main()
Dim MyTable(9, 2), ColumnCounter, RowCounter As Integer
For ColumnCounter = 0 To 2
For RowCounter = 0 To 9
Console.Write("Enter next value for Column " & ColumnCounter)
MyTable(RowCounter, ColumnCounter) =
Integer.Parse(Console.ReadLine())
Next
Next
For RowCounter = 0 To 9
For ColumnCounter = 0 To 2
Console.Write(MyTable(RowCounter, ColumnCounter) & " ")
Next
Console.WriteLine()
Next
Console.ReadKey()
End Sub
End Module
Java
import java.util.Scanner;
class Activity_8_23_Java
{
public static void main(String args[])
{
Scanner myObj = new Scanner(System.in);
int MyTable[][] = new int[10][3];
int ColumnCounter, RowCounter;
for (ColumnCounter = 0; ColumnCounter <= 2; ColumnCounter ++) {
for ( RowCounter = 0; RowCounter <= 9; RowCounter ++) {
System.out.print("Enter next value for column " +
ColumnCounter);
MyTable[RowCounter][ColumnCounter] = myObj.nextInt();
}
}
for ( RowCounter = 0; RowCounter <= 9; RowCounter ++) {
for ( ColumnCounter = 0; ColumnCounter <= 2; ColumnCounter ++) {
System.out.print( MyTable[RowCounter][ColumnCounter]+ " ");
}
System.out.println();
}
}
}
8.24
Python
# writing to and reading a line of text from a file
MyFile = open ("MyText.txt","w") # open file for writing
TextLine = input("Please enter a line of text ") # enter line of text from
keyboard
MyFile.write(TextLine) # write line of text to file
print("The file contains this line of text")
MyFile = open ("MyText.txt","r")# open file for reading
TextLine = MyFile.read()# read line of text from file
print(TextLine) # output line of text from file
Visual Basic
' writing to and reading from a text file
Imports System.IO
Module Module1
Sub Main()
Dim textLn As String
Dim objMyFileWrite As StreamWriter
Dim objMyFileRead As StreamReader
objMyFileWrite = New StreamWriter("textFile.txt") ' setup file for
writing
Console.Write("Please enter a line of text ")
textLn = Console.ReadLine() ' enter line of text from keyboard
objMyFileWrite.WriteLine(textLn) ' write line of text to file
objMyFileWrite.Close() ' close file after writing line of text
Console.WriteLine("The line of text is ")
objMyFileRead = New StreamReader("textFile.txt") ' setup file for
reading
textLn = objMyFileRead.ReadLine ' read line of text from file
Console.WriteLine(textLn) ' output line of text from file
objMyFileRead.Close() ' close file after reading line of text
Console.ReadLine()
End Sub
End Module
Java
//writing to and reading from a text file
import java.util.Scanner;
import java.io.BufferedReader; // library routines for file handling
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
class TextFile {
}
8.25
DECLARE TextLine : STRING // variables are declared as normal
DECLARE MyFile : STRING
MyFile ← "MyText.txt"
MyOtherFile ← "MyOtherText.txt"
// reading the line of text from the file
OUTPUT "The file contains this line of text:"
OPEN MyFile FOR READ // opens file for reading
READFILE, TextLine // reads a line of text from the file
CLOSEFILE(MyFile) // closes the file
// writing the line of text to another file
OPEN MyOtherFile FOR WRITE // opens the file for writing
WRITEFILE, TextLine // writes the line of text to the
file
CLOSEFILE(MyFile) // closes the file
9 Databases
Answers to activities
Answers to question 3 in this section are example answers for past paper questions. The details of
the relevant past paper can be found with the corresponding exam-style question in the Student’s Book.
9.1
Sample fields for database APPOINTMENT:
• Number of patients: e.g. PatientNumber
• Name of patient: e.g. PatientName
• Time of appointment: e.g. AppointmentTime
• Length of appointment: e.g. Duration
9.2
9.3
9.4
1 Four from:
• Text – a number of characters, for example a person’s name
• Char – a single character, for example M or F for male or female
• Boolean – True or False, for example whether an item has been sold or not
• Integer – a whole number, for example the number of items in stock
• Real – a decimal number, for example the price of an item
• Date/time – for example the date and time of an appointment
2 A single table database contains one table. Each table consists of many records. Every record
has the same number of fields. Every field is given a data type. Examples of data types are
char, Boolean and text. Some fields will have validation rules.
9.5
1 a SELECT FirstName, FamilyName
FROM PATIENT
WHERE Consultant = 'Mr Jones';
b SELECT FirstName, FamilyName
FROM PATIENT
WHERE WardNumber <> 6;
c SELECT FirstName, FamilyName
FROM PATIENT
WHERE DateOfAdmisson = '12/11/2022';
d SELECT FirstName, FamilyName, DateOfAdmission
FROM PATIENT
WHERE DateOfAdmission >= '12/10/2022' AND <= '30/10/2022';
2
9.6
1 a SELECT Count (WardNumber)
FROM PATIENT
WHERE WardNumber = 7;
b SELECT Count (WardNumber)
FROM PATIENT
WHERE WardNumber <> 7;
2
9.7
1 a
i SELECT CubName
FROM CUB
WHERE Six = 'red';
ii SELECT CubName
FROM CUB
WHERE Six = 'red' OR Six = 'blue';
iii SELECT COUNT(Six)
FROM CUB
WHERE Six = 'red';
c SELECT Sum (Badges)
FROM CUB;
9.8
1 a • Family name – text
• Other names – text
• Student ID – text
• Date of Birth – date
• Date of Entry to School – date
• Current Class – date
• Current school year/grade – integer
• Email address – text
b • Family name – verification
• Other names – verification
• Student ID – verification and validation
• Date of Birth – verification and validation
• Date of Entry to School – verification and validation
• Current Class – verification and validation
• Current school year/grade – verification and validation
• Email address – verification and validation
c • Student ID – presence check, length check and format check
• Date of Birth – range check and format check
• Date of Entry to School – range check and format check
• Current Class – format check
• Current school year/grade – format check
• Email address – format check
d Student ID
e Example: five characters, S followed by four digits
f
b For instance, to display the stock of each model number where there are less than 20 bikes
left in stock, ordered by number in stock, we would use:
SELECT ModelNumber, NumberInStock
FROM CYCLE
WHERE NumberInStock < 20
ORDER BY NumberInStock;
10 Boolean logic
Answers to activities
10.1
(A AND
(A OR B)
A AND NOT A NOT B) OR NOT (A
A B A OR B AND (NOT
NOT B AND B (NOT A AND B)
(A AND B))
AND B)
0 0 0 0 0 0 1 0
0 1 0 1 1 1 1 1
1 0 1 0 1 1 1 1
1 1 0 0 0 1 0 0
10.2
1 a A B X
0 0 1
0 1 0
1 0 0
1 1 1
b A B X
0 0 0
0 1 0
1 0 0
1 1 0
c A B C X
0 0 0 1
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1
d A B C X
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 0
e A B C X
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1
10.3
1 i A B C X
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
ii
2 i A B C X
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0
ii
5 a (NOT A AND NOT B AND NOT C) OR (NOT A AND NOT B AND C) OR (A AND
NOT B AND NOT C) OR (A AND NOT B AND C)
or
(a.b.c) + (a.b.c) + (a.b.c) + (a.b.c)
b NOT A AND A AND (NOT A AND NOT B)
A B C X
NOT B NOT B OR (A AND NOT B)
0 0 0 1 1 0 1
0 0 1 1 1 0 1
0 1 0 0 0 0 0
0 1 1 0 0 0 0
1 0 0 1 0 1 1
1 0 1 1 0 1 1
1 1 0 0 0 0 0
1 1 1 0 0 0 0
10.4
1 a
A B X
0 0 0
0 1 1
1 0 1
1 1 1
A B C Y
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 0
K L M T
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 1
A B C X
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 0
1 1 1 0
A B C R
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
Truth table:
R T C X
0 0 0 1
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0
Truth table:
G R W S
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
4 i Truth table:
E P W S
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
0 0 0 1 1 1
0 1 0 0 0 0
1 0 0 0 0 0
1 1 1 0 1 1
c A B C X
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 0
b S T V X
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
5 a A B OUTPUT
0 0 0
0 1 1
1 0 1
1 1 1
b XOR gate
c (T AND NOT P) OR (S AND NOT T)
d Two from:
• continuous measurements taken
• won't forget to take readings
• more accurate readings
• safer since no human in contact with potentially dangerous process
• cost saving since no need to pay any wages
c S T P X
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1
To confirm we can write down both truth tables. First, for the circuit shown in the question:
A B C J K X
0 0 0 0 1 1
0 0 1 0 0 0
0 1 0 0 1 1
0 1 1 0 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 1 1
1 1 1 1 0 1
A B C F G H J X
0 0 0 0 1 1 0 1
0 0 1 0 0 1 1 0
0 1 0 0 1 1 0 1
0 1 1 0 0 1 1 0
1 0 0 0 1 1 0 1
1 0 1 0 0 1 1 0
1 1 0 1 1 0 0 1
1 1 1 1 0 0 1 1
The yellow highlights show the inputs and outputs for both circuits, which are the same, and
therefore the circuits are equivalent.
2 One way to approach this is to first consider the XOR truth table, which is what we want
to achieve:
A B X
0 0 0
0 1 1
1 0 1
1 1 0
We can see how close this is to an OR gate truth table:
A B F G X
0 0 1 1 0
0 1 1 0 1
1 0 0 1 1
1 1 0 0 1
The only row we need to amend from the OR gate truth table is the final one. We require F and
G to both be 1 so that X = F NAND G is 0 on that final row, i.e.:
A B F G X
0 0 1 1 0
0 1 1 0 1
1 0 0 1 1
1 1 1 1 0
It is only when A and B are both 1 that we want to amend the OR gate circuit. A NAND could
be used to do this, because a NAND gate has the property that only when both inputs are 1 is
the output different:
A B A NAND B
0 0 1
0 1 1
1 0 1
1 1 0
How can we combine A NAND B with A in order that F has the values we require?
By combining gates as follows:
A B A NAND B F
0 0 1 1
0 1 1 1
1 0 1 0
1 1 0 0
It can be seen that F = A NAND (A NAND B).
We can use the same approach for G, but this time considering the input B:
Task 3
A B F G H X
0 0 1 1 0 1
0 1 1 0 1 0
1 0 0 1 1 0
1 1 0 0 1 0
By considering only the inputs A, B and the output X we can see this is the inverse of an OR gate,
which is called an NOR gate.