Paper 2 - Sample MS
Paper 2 - Sample MS
4 a i) est data is needed to ensure that the program completes all parts of the solution without error and that the
T
solution is robust.
ii) Any three from: normal; abnormal; extreme; boundary.
It is illegal to photocopy this page
b) Sample answer:
Normal data for, example 37, to ensure that the program accepts this value and provides an acceptable
solution.
Boundary data, for example 29 and 30, to ensure that 29 is rejected as out of the required range and 30 is
accepted as just in the required range.
Abnormal data, for example 67 or 35, to ensure that these values are rejected.
5 a i) To check if a password is 10 characters or more and contains at least one symbol.
ii) Assignment: 08
Selection: 04
Iteration: 01 to 22
188 Cambridge IGCSE™ and O Level Computer Science Study and Revision Guide Second Edition
318489_Ans_Paper_2A_188-195.indd Page 189 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd
ii)
Password PasswordUp Symbol Counter Output
MyWord! Please enter your password
Reject too short
6 a i) A
variable is a value that can be changed during the execution of a program whereas a constant does not
change its value during the execution of a program.
ii) Any three from: integer; real; char; string; Boolean.
b DECLARE ClassSize : INTEGER
MaxClassSize = 30
7 Mathematical for calculations, for example:
Num3 ← Num1 + Num2
Logical for selection of different paths through a program when a condition is true or false, for example:
IF Num3 > Num1
THEN
Num2 ← Num3
ENDIF
Boolean to combine (AND OR) or reverse (NOT) conditions, for example:
IF Num1 > Num2 AND Num1 > Num3
It is illegal to photocopy this page
Hodder & Stoughton Limited © David Watson and Helen Williams 2022 189
318489_Ans_Paper_2A_188-195.indd Page 190 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd
8
Returns the remainder of DIV
a division.
LCASE
LENGTH
ROUND
Returns a string where all
letters are upper case.
SUBSTRING
9 a i) A
n array is a data structure containing several elements of the same data type; these elements can be
accessed using the same identifier name.
ii) An integer variable is used as an array with an index as it can be increased or decreased according to the
position of the data in the array, for example to set all the elements of an array to blank:
FOR Index ← 1 TO 10
MyName[Index] ← ""
NEXT Index
iii) A 1D array is a list with a single column and a 2D is a table with rows and columns.
b FOR RowIndex ← 1 TO 20
FOR ColumnIndex 1 TO 4
MyArray[RowIndex, ColumnIndex] ← 0
NEXT ColumnIndex
NEXT RowIndex
c Advantage: arrays can be populated or searched using repetition as only the value of the index will change to
access each element.
Disadvantage: as arrays have a fixed size, space may be wasted if there are unused elements.
10 1 01 Large ← 9999
It is illegal to photocopy this page
Large ← -9999
2 02 Counter ← 50
Counter ← 00
190 Cambridge IGCSE™ and O Level Computer Science Study and Revision Guide Second Edition
318489_Ans_Paper_2A_188-195.indd Page 191 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd
5 08 Counter = Counter - 1
Counter = Counter + 1
11 a PlantPrice – currency as it needs to be shown in dollars.
PlantHeight – real as it may be used for calculations or comparisons.
Position – Boolean as there are only two possible values.
b PlantID as it would uniquely identify the plant.
c SELECT PlantName, Price, StockAvailable
FROM PlantSale
b
A
B X
13 Python:
def YoungBabies(): # procedure to find babies under 3 months
print("Names of babies under 3 months")
for Counter in range(Length):
if BabyAge[Counter] < 3:
print (BabyName[Counter])
print("Baby’s details")
for Counter in range(Length):
if BabyName[Counter] == Baby:
print (BabyName[Counter], BabyAge[Counter], ParentPhone[Counter])
Hodder & Stoughton Limited © David Watson and Helen Williams 2022 191
318489_Ans_Paper_2A_188-195.indd Page 192 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd
YoungBabies()
SortBabys()
print (BabyName, BabyAge, ParentPhone)
Visual Basic:
It is illegal to photocopy this page
Module Module1
Dim GamerHighScore(4), Counter As Integer
Dim GamerName(4) As String
'input routine
Sub Main()
For Counter = 0 To 49
Console.Write("Enter next gamer's name ")
GamerName(Counter) = Console.ReadLine()
192 Cambridge IGCSE™ and O Level Computer Science Study and Revision Guide Second Edition
318489_Ans_Paper_2A_188-195.indd Page 193 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd
Hodder & Stoughton Limited © David Watson and Helen Williams 2022 193
318489_Ans_Paper_2A_188-195.indd Page 194 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd
Next
Last = Last - 1
Loop Until Not Swap Or Last = 1
End Sub
End Module
Notes: global declarations at start of program subroutine and function declarations at end of program
Java:
import java.util.Scanner;
class Ch8Q6Java {
static int GamerHighScore [] = new int[5];
static String GamerName [] = new String[5];
TempName = GamerName[Counter];
GamerName[Counter] = GamerName[Counter + 1];
GamerName[Counter + 1] = TempName;
Swap = true;
}
}
Last = Last - 1;
} while (!Swap || Last > 1);
}
194 Cambridge IGCSE™ and O Level Computer Science Study and Revision Guide Second Edition
318489_Ans_Paper_2A_188-195.indd Page 195 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd
Hodder & Stoughton Limited © David Watson and Helen Williams 2022 195