Problem solving, algorithms and programming – Edexcel IGCSE Computer Science (4CP0)
2 questions · Clear filters
Question text
4 Algorithms can be used to perform calculations and to process data.
(a) State what is meant by the term algorithm.
(1)
(b) Figure 3 shows an algorithm.
Start
Number1 = 1
Number2 = Number1
Output
Number1 Number2
Count = 0
Yes
Stop
Count = 2?
No
Number3 = Number2 + Number1
Output
Number3
Number1 = Number2
Number2 = Number3
Count = Count + 1
Figure 3
(i) Complete this trace table for the algorithm.
You may not need to use all the rows.
(5)
Number1
Number2
Number3
Count
Output
Count = 2?
1
1
–
0
1 1
False
(ii) The benefits of using a trace table include that they allow variable states,
outputs and decisions to be recorded.
Give one other benefit of using a trace table to test an algorithm.
(1)
(c) An algorithm is needed to count and display the number of vowels in a word.
The vowels are a, e, i, o, and u.
The completed algorithm must:
•
count the number of vowels
create a message as a single string (e.g. there are number vowels)
•
•
print the message to the display.
Here is a partially completed algorithm written in pseudocode.
Complete the algorithm in the spaces provided.
(5)
SET word TO 'elephant'
FOR EACH letter FROM word DO
END FOREACH
(Total for Question 4 = 12 marks)
Question text
6 A software engineer is working with some algorithms.
(a) An algorithm needs to be developed.
The algorithm must:
•
check for a change of hour every minute
•
use the library subprogram getHour() to get the hour part of the current time
in the 24-hour clock (0 to 23)
•
output “Good morning” when the hour is between 3 and 12, inclusive
•
output “Good afternoon” when the hour is between 13 and 19, inclusive
•
output “Good night” at all other times.
Complete the flowchart to represent this algorithm, in the space provided on the
next page.
The call to the library subprogram getHour() has already been included.
Use this subprogram symbol to show waiting for 1 minute.
wait
1 minute
(6)
Draw your flowchart here.
START
getHour()
(b) Another algorithm determines when to change the flavoured syrups for a drinks
dispensing machine.
Figure 4 shows this algorithm written in pseudocode.
11 SET flavours TO [“anise”, “mango”, “cola”, “apple”, “papaya”, “strawberry”,
“lychee”, “banana”]
12
13 SET volume TO [0.7, 0.2, 0.6, 0.1, 0.05, 0.8, 0.4, 0.6]
14
15 SET i TO 0
16
17 WHILE i < 8 DO
18
19 IF (volume[i] < 0.1) THEN
10 SEND (flavours[i] & “ needs changing”) TO DISPLAY
11
12 ELSE
13 IF (volume[i] >= 0.3) AND (volume[i] <= 0.5) THEN
14 SEND (flavours[i] & “ needs ordering”) TO DISPLAY
15 END IF
16 END IF
17
18 SET i TO i + 1
19
20 END WHILE
Figure 4
(i) Give the output produced by the algorithm.
(2)
The algorithm works with a fixed number of flavours.
(ii) Give the number of the line in the algorithm that would need to be amended
to allow for any number of flavours.
(1)
(iii) State how the pseudocode needs to be changed to make this amendment.
(1)
QUESTION 6(c) BEGINS ON THE NEXT PAGE.
(c) The algorithms will be coded in a high-level language.
Programs written in high-level languages must be translated in order to be
executed by a computer.
Discuss the similarities and differences between a compiler and an interpreter.
(6)
(Total for Question 6 = 16 marks)