Programming – IGCSE Computer Science (0478)
270 questions · page 12 of 18 · Clear filters
Question text
2
An algorithm has been written in pseudocode to generate 50 positive random integers with values
less than or equal to 100. These numbers are stored in the array NumRand[]
The function RandUp(X,Y) generates a random integer greater than X and less than or equal to Y
For example, RandUp(1,4) generates 2 or 3 or 4
0
1 Count
2 WHILE Counter > 50 DO
RandUp(1,100)
3
NumRand[Counter]
Counter − 2
4
Counter
5 ENDWHILE
(a) Find the four errors in the pseudocode and write a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
…
[4]
(b) The pseudocode for this algorithm could be shortened by the use of a FOR … NEXT loop.
Rewrite the algorithm using a FOR … NEXT loop.
…
…
…
… [3]
Question text
1
(a) All variables, constants and other identifiers must have meaningful names.
(i)
Identify one constant you could have used for Task 1, give the value that would be
assigned to it and its use.
Constant …
Value …
Use …
…
…
[3]
(ii)
Identify one variable and one array you could have used for Task 1.
Explain the use of each one.
Variable …
Use …
…
…
Array …
Use …
…
…
[4]
(b) Explain how you should change your program in Task 1 to allow a tutor to enter up to eight
candidates for the election.
…
…
…
…
…
…
…
… [4]
(c) Write an algorithm using pseudocode, programming statements or a flowchart to show how
your program completes these parts of Task 2:
•
Allows students to enter their unique voter number before casting their vote.
•
Checks whether the student has already voted:
– if so, supplies a suitable message and does not allow them to vote.
– if not, stores the unique voter number, but not their vote, in a suitable data structure.
It is not necessary to show parts completed in Task 1, including counting of votes for each
candidate.
…
Question text
3
Name and describe the most appropriate programming data type for each of the examples of data
given. Each data type must be different.
Data: 37
Data type name …
Data type description …
…
…
Data: Cambridge2021
Data type name …
Data type description …
…
…
Data: 47.86
Data type name …
Data type description …
…
…
[6]
Question text
4
The pseudocode algorithm shown has been written by a teacher to enter marks for the students in
her class and then to apply some simple processing.
←
0
Count
REPEAT
INPUT Score[Count]
IF Score[Count] >= 70
THEN
←
"A"
Grade[Count]
ELSE
IF Score[Count] >= 60
THEN
←
"B"
Grade[Count]
ELSE
IF Score[Count] >= 50
THEN
←
"C"
Grade[Count]
ELSE
IF Score[Count] >= 40
THEN
←
"D"
Grade[Count]
ELSE
IF Score[Count] >= 30
THEN
←
"E"
Grade[Count]
ELSE
←
"F"
Grade[Count]
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
←
Count + 1
Count
UNTIL Count = 30
(a) Describe what happens in this algorithm.
…
…
…
…
…
…
…
… [3]
(b) Write the pseudocode to output the contents of the arrays Score[] and Grade[] along with
suitable messages.
…
…
…
…
…
…
…
…
…
…
…
… [3]
(c) Describe how you could change the algorithm to allow teachers to use it with any size of
class.
…
…
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) Identify and give the data type and use of one array that you could have used for Task 1.
Array …
Data type …
Use …
[3]
(b) Describe two validation checks that could be used when inputting the number of tickets to
buy for Task 2. For each validation check give one example of normal data and one example
of erroneous data.
Validation check 1 …
…
…
Normal data …
Erroneous data …
Validation check 2 …
…
…
Normal data …
Erroneous data …
[6]
(c) Write an algorithm for the part of Task 2 that inputs the tickets required, calculates the total
price for the ticket(s) purchased by a passenger including a group discount (if applicable) and
updates the data structures used for the totals.
Use either pseudocode, programming statements or a flowchart.
…
…
…
…
…
…
…
…
…
…
Question text
4
This algorithm checks passwords.
•
Each password must be 8 or more characters in length; the predefined function Length
returns the number of characters.
•
Each password is entered twice, and the two entries must match.
•
Either Accept or Reject is output.
•
An input of 999 stops the process.
REPEAT
OUTPUT "Please enter password"
INPUT Password
IF Length(Password) >= 8
THEN
INPUT PasswordRepeat
IF Password <> PasswordRepeat
THEN
OUTPUT "Reject"
ELSE
OUTPUT "Accept"
ENDIF
ELSE
OUTPUT "Reject"
ENDIF
UNTIL Password = 999
(a) Complete the trace table for the algorithm using this input data:
Secret, Secret, VerySecret, VerySecret, Pa55word, Pa55word, 999, 888
Password
PasswordRepeat
OUTPUT
[3]
(b) Explain how the algorithm could be extended to allow three attempts at inputting the matching
password. Any pseudocode statements used in your answer must be fully explained.
…
…
…
…
…
…
…
… [4]
Question text
5
A one-dimensional array dataArray[1:20] needs each element set to zero.
(a) Write a pseudocode routine that sets each element to zero. Use the most suitable loop
structure.
…
…
…
…
…
…
…
… [3]
(b) Explain why you chose this loop structure.
…
… [1]
Question text
1
(a) All variables, constants and other identifiers must have meaningful names.
(i)
Identify one constant you could have used for Task 1. Give the value that would be
assigned to the constant and explain its use.
Constant …
Value …
Use …
…
…
[3]
(ii)
Identify one variable you could have used for Task 1 and explain its use.
Variable …
Use …
…
…
[2]
(iii)
Describe one array you could have used for Task 1. Include the name, data type, length,
sample data and use for that array.
…
…
…
…
…
…
…
…
…
…
…
…
… [4]
(b) Write an algorithm for Task 2, using pseudocode, programming statements or a flowchart. It
is not necessary to show details completed in Task 1.
…
…
…
Question text
2
Draw a line to connect each Data Type to the most appropriate Description.
Data Type
Description
Must be a whole number
Real
Must be one of two values
String
Integer
May be any number
Boolean
May contain any combination of characters
[3]
Question text
4
The pseudocode algorithm should allow a user to input the number of scores to be entered and
then enter the scores. The scores are totalled, the total is output and the option to enter another
set of scores is offered.
←
0
1 Count
2 REPEAT
←
20
3
FullScore
4
INPUT Number
←
1 TO Number
5
FOR StoreLoop
6
INPUT Score
←
FullScore
7
FullScore
8
UNTIL StoreLoop = Number
9
OUTPUT "The full score is ", FullScore
10
OUTPUT "Another set of scores (Y or N)?"
11
OUTPUT Another
12
IF Another = "N"
13
THEN
←
1
14
Count
15
ENDIF
16 UNTIL Count = 1
(a) Identify the four errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Show how you could change the algorithm to store the individual scores in the array
ScoreArray[], then find and print the average score once the scores have all been entered.
…
…
…
…
…
…
…
…
…
…
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) Identify one array that you could have used for Task 1. Give the data type and state the use
of the array.
Array …
Data type …
Use …
…
…
[3]
(b) Data entered by a customer includes the age of the driver in Task 1.
Identify two different validation checks you could use for the age of the driver.
Justify your choice for each one.
Validation check 1 …
…
Justification …
…
…
…
Validation check 2 …
…
Justification …
…
…
…
[4]
(c) Write an algorithm for Task 2, using either pseudocode, programming statements or a
flowchart. Assume that Task 1 has been completed.
…
…
…
…
…
…
…
Question text
2
Describe the purpose of variables and constants. Use an example of each in your answer.
…
…
…
…
…
…
…
…
… [4]
Question text
4
This flowchart inputs five numbers and performs a calculation.
The predefined function MOD finds the remainder from integer division for example
←
25 MOD 11 gives R a value of 3
R
START
INPUT
V,W,X,Y,Z
Yes
IS
END
V = 0 ?
No
← V*2 + W*3 + X*4 + Y*5
A
← A MOD 11
B
Yes
IS
OUTPUT
B = Z ?
"Valid"
No
OUTPUT
"Invalid"
(a) Complete the trace table for this set of input data:
5, 4, 6, 2, 1, 9, 3, 2, 1, 6, 7, 6, 1, 5, 1, 0, 0, 0, 0, 0
V
W
X
Y
Z
A
B
OUTPUT
[4]
(b) Describe the purpose of this flowchart.
…
…
…
… [2]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one array you could have used for Task 1 and state its purpose.
Array …
Purpose …
…
…
[2]
(ii)
Identify one variable you could have used for Task 2 and state its purpose.
Variable …
Purpose …
…
…
[2]
(iii)
Identify one constant you could have used for Task 3 and state its purpose.
Constant …
Purpose …
…
…
[2]
(b) Explain the benefits of storing Price as a real data type.
…
…
…
…
…
…
… [2]
(c) Write an algorithm to show how you completed Task 1, using either pseudocode,
programming statements or a flowchart. It is not necessary to show initialisation or setting up
of arrays in your answer.
…
…
…
…
…
Question text
2
Tick (3) one box in each row to identify if the statement about subroutines is true or false.
true
false
Statement
(3)
(3)
A subroutine is called from within a program.
A subroutine is not a complete program.
A subroutine is a self-contained piece of code.
A subroutine must return a value to the code from which it was called.
[2]