Programming – IGCSE Computer Science (0478)

270 questions · page 14 of 18 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
196
0478/22/F/M/20 · Question 2Feb/March 2020Paper 228 marks
Loading question…
Question text

2
(a) An algorithm has been written in pseudocode to input 50 numbers. Positive numbers are
stored in the array PosNum[ ]. Negative numbers are stored in the array NegNum[ ].
Zeros are not included in the positive and negative counts.
←
0
Count
←
Count
PosCount
←
Count
NegCount
REPEAT
INPUT Number
IF Number > 0
THEN
←
PosCount + 1
PosCount
←
Number
PosNum[PosCount]
ELSE
←
NegCount + 1
NegCount
←
Number
NegNum[NegCount]
ENDIF
←
Count + 1
Count
UNTIL Count >= 50
OUTPUT "There are ", PosCount," positive numbers"
OUTPUT "There are ", NegCount," negative numbers"
Describe the error in the pseudocode and write the correction for this error.
Error …
…
…
…
Correction …
…
…
…
[4]
(b) The algorithm needs to be changed so there is no limit to how many numbers can be input.
When the number 9999 is input, the algorithm stops more numbers being input and outputs
the results. The number 9999 is not to be stored nor counted as a positive number.
Explain how you would change the algorithm.
…
…
…
…
…
…
…
…
…
… [4]

197
0478/21/O/N/19 · Question 1Oct/Nov 2019Paper 2120 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers must have meaningful names.
Name two variables that you could have used for Task 1. State the data type and purpose of
each variable.
Variable 1 name …
Data type …
Purpose …
…
Variable 2 name …
Data type …
Purpose …
…
[6]
(b) Describe how arrays could be used to store the data about the types and price per square
metre of the stone slabs for Task 1.
…
…
…
…
…
…
… [2]
(c) Write an algorithm to complete Task 2, using either pseudocode, programming statements
or a flowchart. Assume Task 1 has been completed.
…
…
…
…
…
…
…
…
…
…

198
0478/21/O/N/19 · Question 4Oct/Nov 2019Paper 2135 marks
Loading question…
Question text

4
(a) Complete the trace table for this algorithm using the given input data.
0
Index
0 TO 7
FOR Count
INPUT Value
IF Value > 50
THEN
Value
PassMarks[Index]
Index + 1
Index
ENDIF
NEXT Count
PRINT "Number passed ", Index
Input data: 58, 40, 67, 85, 12, 13, 75, 82
PassMarks
OUTPUT
Index Count Value [0] [1] [2] [3] [4] [5] [6] [7]
[6]
(b) Give the purpose of the algorithm shown in part (a).
…
…
… [1]

Advertisement
199
0478/22/O/N/19 · Question 1Oct/Nov 2019Paper 2220 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers must have meaningful names.
(i)
Describe the data structures that you have used to store the data for the concrete slabs
in Task 1, include the name, data type and use for each data structure.
…
…
…
…
…
…
…
…
…
…
… [5]
(ii)
State one variable that you have used in Task 3.
Give the data type for the variable. State what it is used for.
Variable name …
Data type …
Use …
…
[3]
(b) Explain how you calculated the volume of a concrete slab in Task 1.
…
…
…
…
…
… [3]
(c) Write an algorithm for Task 2, using either pseudocode, programming statements or a
flowchart. Assume that Task 1 has been completed.
…
…
…

200
0478/22/O/N/19 · Question 2Oct/Nov 2019Paper 224 marks
Loading question…
Question text

2
An algorithm has been written in pseudocode to select a random number using the function
RandInt(n), which returns a whole number between 1 and the argument n. The algorithm then
allows the user to guess the number.
RandInt(100)
Number
1
TotalTry
REPEAT
PRINT "Enter your guess now, it must be a whole number"
INPUT Guess
IF TotalTry > Number
THEN
PRINT "Too large try again"
ENDIF
IF Guess > Number
THEN
PRINT "Too small try again"
ENDIF
Guess + 1
TotalTry
UNTIL Guess <> Number
TotalTry - 1
TotalTry
PRINT "Number of guesses ", TotalTry
Find the four errors in the pseudocode and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]

201
0478/22/O/N/19 · Question 3Oct/Nov 2019Paper 227 marks
Loading question…
Question text

3
(a) The flowchart checks the lengths of a batch of 10 ropes. For the batch to be accepted 90% of
the lengths need to be between 24.9 and 25.1 metres.
START
Reject
0
Count
0
Yes
Is Count =
10 ?
No
No
Is Reject
Count
Count + 1
<= 1 ?
INPUT Length
Yes
OUTPUT "Batch
rejected"
Is Length <
Yes
25.1 AND
Length > 24.9 ?
No
Reject
Reject + 1
OUTPUT "Batch
accepted"
END
Complete the trace table for the input data:
24.88, 25.01, 24.98, 25.00, 25.05, 24.99, 24.97, 25.04, 25.19, 25.07
Reject
Count
Length
OUTPUT
[4]
(b) (i)
It has been decided to only reject batches of rope that contain ropes that are too short.
State the change required to the algorithm.
…
… [1]
(ii)
Explain how the algorithm to reject batches could be improved to make it more effective.
…
…
…
… [2]

202
0478/22/O/N/19 · Question 5Oct/Nov 2019Paper 224 marks
Loading question…
Question text

5
A programmer writes a program to weigh baskets of fruit in grams, keeping a total of the weight
and counting the number of baskets. The total weight is stored in a variable Total and the number
of baskets is stored in a variable BasketCount.
Explain, including examples of programming statements, how totalling and counting could be used
in this program.
Totalling …
…
…
…
…
…
Counting …
…
…
…
…
…
[4]

203
0478/22/O/N/19 · Question 6Oct/Nov 2019Paper 226 marks
Loading question…
Question text

6
Explain why constants, variables and arrays are used in programming.
Constants …
…
…
…
Variables …
…
…
…
Arrays …
…
…
…
[6]

Advertisement
204
0478/23/O/N/19 · Question 1Oct/Nov 2019Paper 2320 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers must have meaningful names.
Name two arrays you could use for Task 1. State the data type and purpose of each one.
Array 1 …
Data type 1 …
Purpose …
…
Array 2 …
Data type 2 …
Purpose …
…
[4]
(b) Name a variable that you used for Task 2. State the data type and purpose of this variable.
Explain why you chose to use a variable rather than a constant.
Variable …
Data type …
Purpose …
…
…
Reason for use of a variable …
…
…
[4]
(c) Write an algorithm for Task 1, using either pseudocode, programming statements or a
flowchart. Assume that the first part of Task 1, the storage and display of tile descriptions,
prices per box and identification codes has already been done.
…
…
…
…
…
…
…
…

205
0478/23/O/N/19 · Question 2Oct/Nov 2019Paper 232 marks
Loading question…
Question text

2
Describe the use of a subroutine in a program.
…
…
…
…
… [2]

206
0478/23/O/N/19 · Question 4Oct/Nov 2019Paper 235 marks
Loading question…
Question text

4
The following pseudocode algorithm uses nested IF statements.
IF Response = 1
THEN
X + Y
X
ELSE
IF Response = 2
THEN
X – Y
X
ELSE
IF Response = 3
THEN
X * Y
X
ELSE
IF Response = 4
THEN
X / Y
X
ELSE
OUTPUT "No response"
ENDIF
ENDIF
ENDIF
ENDIF
(a) Name the type of statement demonstrated by the use of IF … THEN … ELSE … ENDIF
…
… [1]
(b) Re-write the pseudocode algorithm using a CASE statement.
…
…
…
…
…
…
…
…
…
… [4]

207
0478/23/O/N/19 · Question 5Oct/Nov 2019Paper 23146 marks
Loading question…
Question text

5
The algorithm performs an operation on the array named MyData
DIV means integer division, so only the whole number part of the result is returned
e.g. 7 DIV 2 returns a value of 3
0
First
16
Last
FALSE
Found
INPUT UserIn
WHILE (First <= Last) AND (Found = FALSE) DO
(First + Last) DIV 2
Middle
IF MyData[Middle] = UserIn
THEN
TRUE
Found
ELSE
IF UserIn < MyData[Middle]
THEN
Middle - 1
Last
ELSE
Middle + 1
First
ENDIF
ENDIF
ENDWHILE
OUTPUT Found
This table shows the contents of the array: MyData e.g. MyData[2] stores the value 5
MyData
Index [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]
Value
2
3
5
6
8 10 12 13 14 16 18
20
25
27
29
34
36
(a) Complete the trace table for the input data: 10
First
Last
UserIn
Middle
Found
OUTPUT
[6]
(b) Describe the function being performed by the algorithm.
…
…
…
… [2]

208
0478/21/M/J/19 · Question 1May/June 2019Paper 2120 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers must have meaningful names.
(i)
State one array you used for Task 1. State the data type and purpose of this array.
Array …
Data type …
Purpose …
…
…
[3]
(ii)
State one variable you used for Task 2 and one variable you used for Task 3. In each
case, state the data type and purpose of the variable.
Task 2 variable name …
Data type …
Purpose …
…
…
Task 3 variable name …
Data type …
Purpose …
…
…
[6]
(b) Write an algorithm to show how you calculated and output the number of late arrivals and the
average number of minutes late for each bus route (part of Task 2), using either pseudocode,
programming statements or a flowchart.
…
…
…
…
…
…
…
…
…
…

Advertisement
209
0478/21/M/J/19 · Question 2May/June 2019Paper 216 marks
Loading question…
Question text

2
Describe each of the following data types used in programming. In each case, give an example of
a piece of data to illustrate your answer. Each example must be different.
Char
…
…
…
String
…
…
…
Boolean
…
…
…
[6]

210
0478/22/M/J/19 · Question 1May/June 2019Paper 2220 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers must have meaningful names.
Describe the data structures you have used in Task 1 to record the items for sale. Include
some sample data for each data structure you have described.
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Explain how your program for Task 1 ensures the item number is unique.
…
…
…
… [2]
(c) Write an algorithm for the part of Task 2 that allows the buyer to add a new bid, using
either pseudocode, programming statements or a flowchart. Assume that Task 1 has been
completed and that the item details have already been found.
…
…
…
…
…
…
…
…
…

Advertisement