Programming – IGCSE Computer Science (0478)
282 questions · page 14 of 19
Question text
2
Most programming languages include basic data types. Ahmad is describing the basic data types
he has used.
State the data type that Ahmad is describing in each sentence.
Choose the data type from this list of programming terms.
Array
Boolean
Char
Constant
Function
Integer
Iteration
Procedure
Real
String
Variable
A number with a fractional part that can be positive or negative and used in calculations
Data type …
A whole number that can be positive, negative or zero and used in calculations
Data type …
A single number, symbol or letter
Data type …
A sequence of characters
Data type …
A data type with two values, True or False
Data type …
[5]
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 why a student would be advised not to store the Healthy? data as a real data type
and identify the most suitable data type for the Healthy? data.
…
…
…
…
…
… [2]
(c) Write an algorithm for Task 1 using either pseudocode, programming statements or a
flowchart. It is not necessary to show initialisation or setting up of arrays.
…
…
…
…
…
…
Question text
2
Draw a line to connect each Description to the most appropriate Pseudocode example.
Description
Pseudocode example
A loop that will iterate
CASE … OF … OTHERWISE … ENDCASE
at least once
A loop that will not be
Number + 1
Number
executed on the first test
if the condition is false
WHILE … DO … ENDWHILE
A conditional statement
Sum
Sum + NewValue
Totalling
REPEAT … UNTIL
Counting
[4]
Question text
5
This algorithm finds prime numbers.
The pre-defined function DIV gives the value of the result of integer division,
9 DIV 4 gives y a value of 2
for example, y
False
Flag
INPUT Number
WHILE Number <> 0
2
Divisor
WHILE Divisor <= Number / 2
Number DIV Divisor
Value
IF Number / Divisor = Value
THEN
True
Flag
ENDIF
Divisor + 1
Divisor
ENDWHILE
IF Flag = False
THEN
OUTPUT Number, " is prime"
ENDIF
INPUT Number
False
Flag
ENDWHILE
Complete the trace table for the algorithm using the input data:
5, 6, 8, 0, 11, 13
Flag
Number Divisor Value
OUTPUT
[5]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) State the name of one constant that you could have used for Task 1. Give the value that
would be assigned to the constant. State the use of this constant.
Constant name …
Value …
Use …
…
[3]
(b) State the name of the variable that you used to store the amount offered for the trade-in of
an old car in Task 1. Give the most appropriate data type for this variable. Explain how your
program ensured that any data entered for the trade-in offer was valid.
Variable name …
Data type …
Validation …
…
…
…
[4]
(c) Snazzy Autos has decided to add another model to the cars available in Task 1. The new
model is a convertible, price Rs 6.75 lakh. Explain the changes required to your program for
Task 1.
…
…
…
…
…
…
…
…
…
…
…
…
…
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]
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.
…
…
…
…
…
…
…
…
…
…
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]
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.
…
…
…
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]
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]
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]
Question text
6
Explain why constants, variables and arrays are used in programming.
Constants …
…
…
…
Variables …
…
…
…
Arrays …
…
…
…
[6]
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.
…
…
…
…
…
…
…
…
Question text
2
Describe the use of a subroutine in a program.
…
…
…
…
… [2]