Programming – IGCSE Computer Science (0478)

282 questions · page 12 of 19

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
166
0478/21/O/N/21 · Question 1Oct/Nov 2021Paper 2120 marks
Loading question…
Question text

1
All variables, constants and other identifiers must have meaningful names.
(a) Identify one constant that you could have used for Task 1. Give the value that would be
assigned to this constant. State the use of this constant.
Constant …
Value …
Use …
…
[3]
(b) Describe the arrays that you have set up in Task 1 to record today’s data about the squash
courts.
…
…
…
…
…
…
…
… [4]
(c) Explain how your program generates a unique 4-digit code for each booking.
…
…
…
…
…
… [3]
(d) Write an algorithm for Task 2. You do not need to display updated court availability. Use
either pseudocode, programming statements or a flowchart. Assume that Task 1 has been
completed.
…
…
…
…
…

167
0478/21/O/N/21 · Question 2Oct/Nov 2021Paper 218 marks
Loading question…
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 random integers are stored in the array RandNum[ ]
The function Rand(X, Y) generates a random integer greater than or equal to X and less than Y.
For example, Rand(1, 4) generates 1 or 2 or 3.
0
1 Count
2 REPEAT
Rand(1, 100)
3
RandNum[Counter]
Count + 2
4
Count
5 UNTIL Count <= 50
(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]
(c) Identify another loop structure available in pseudocode.
… [1]

168
0478/22/O/N/21 · Question 1Oct/Nov 2021Paper 2220 marks
Loading question…
Question text

1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one variable you could have used for Task 2 and state its use.
Variable …
Use …
…
…
[2]
(ii)
Describe the arrays you could have used in Task 1. Include the name, data type, use
and sample data for each array.
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Describe how you could validate the data entry for the input of the codes for the different
stages of the journey in Task 2.
…
…
…
…
…
… [3]
(c) Write an algorithm to show how your program carries out Task 3, using either pseudocode,
programming statements or a flowchart. Assume Tasks 1 and 2 have already been completed.
…
…

Advertisement
169
0478/22/O/N/21 · Question 4Oct/Nov 2021Paper 2210 marks
Loading question…
Question text

4
The pseudocode algorithm should work as a calculator and output the result.
1
1 Continue
2 WHILE Continue = 0
3
OUTPUT "Enter 1 for +, 2 for -, 3 for * or 4 for /"
4
INPUT Operator
5
OUTPUT "Enter the first value"
6
INPUT Value1
7
OUTPUT "Enter the second value"
8
OUTPUT Value2
9
IF Operator
Value1 + Value2
10
1: Answer
Value1 - Value2
11
2: Answer
Value1 * Value2
12
3: Answer
Value1 / Value2
13
4: Answer
14
ENDCASE
15
OUTPUT "The answer is ", Value1
16
OUTPUT "Do you wish to enter more values (Yes or No)?"
17
INPUT MoreValues
18
IF MoreValues = "No"
19
THEN
1
20
Continue
21
ENDIF
22 UNTIL Continue = 0
(a) Find the five errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
Error 5 …
Correction …
…
[5]
(b) The algorithm needs changing to allow only the numbers 1, 2, 3, or 4 to be entered for the
input variable Operator.
Write the pseudocode to perform this task and state where in the algorithm it would be
located.
Pseudocode …
…
…
…
…
…
…

170
0478/23/O/N/21 · Question 1Oct/Nov 2021Paper 2320 marks
Loading question…
Question text

1
All variables, constants and other identifiers must have meaningful names.
(a) Identify one constant that you could have used for Task 1. Give the value that would be
assigned to this constant. State the use of this constant.
Constant …
Value …
Use …
…
[3]
(b) Describe the arrays that you have set up in Task 1 to record today’s data about the restaurant
tables.
…
…
…
…
…
…
…
… [4]
(c) Sometimes the restaurant has fewer tables available for a session.
Explain how you would change your Task 1 program to allow input of the number of tables
available for a session.
…
…
…
…
…
… [3]
(d) Part of Task 2 is to check if a table is available. Write an algorithm to do this, using either
pseudocode, programming statements or a flowchart. Assume that Task 1 has been
completed.
…
…
…
…
…

171
0478/23/O/N/21 · Question 2Oct/Nov 2021Paper 237 marks
Loading question…
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]

172
0478/21/M/J/21 · Question 1May/June 2021Paper 2120 marks
Loading question…
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.
…

173
0478/21/M/J/21 · Question 3May/June 2021Paper 216 marks
Loading question…
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]

Advertisement
174
0478/21/M/J/21 · Question 4May/June 2021Paper 219 marks
Loading question…
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.
…
…

175
0478/22/M/J/21 · Question 1May/June 2021Paper 2220 marks
Loading question…
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.
…
…
…
…
…
…
…
…
…
…

176
0478/22/M/J/21 · Question 4May/June 2021Paper 227 marks
Loading question…
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]

177
0478/22/M/J/21 · Question 5May/June 2021Paper 224 marks
Loading question…
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]

178
0478/23/M/J/21 · Question 1May/June 2021Paper 2320 marks
Loading question…
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.
…
…
…

Advertisement
179
0478/23/M/J/21 · Question 2May/June 2021Paper 233 marks
Loading question…
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]

180
0478/23/M/J/21 · Question 4May/June 2021Paper 238 marks
Loading question…
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.
…
…
…
…
…
…
…
…
…
…

Advertisement