0% found this document useful (0 votes)
39 views8 pages

Paper 2 - Sample MS

This document contains answers to a practice exam paper for a computer science course. It includes sample code, explanations of programming concepts, and short answers to questions about programming topics like validation, testing, variables, and standard algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views8 pages

Paper 2 - Sample MS

This document contains answers to a practice exam paper for a computer science course. It includes sample code, explanations of programming concepts, and short answers to questions about programming topics like validation, testing, variables, and standard algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

318489_Ans_Paper_2A_188-195.

indd Page 188 12/07/22 1:48 PM F-0250 /145/HO02580/work/indd

Answers to Practice Paper 2A


1 a

b Investigating to provide the specification of what a program is required to do.


c CASE
d A collection of related records.
2 a i)  standard method of solution is one that is needed on a regular basis and can be used a part of many
A
different algorithms.
ii) Any three from:
– Totalling
– Linear search
– Bubble sort
– Finding average
– Finding maximum
– Finding minimum
b Counting is used to add one to a running total every time an event occurs, for example:
TeenCount ← 0
FOR Counter ← 1 TO 50
INPUT Age
IF Age > 12 AND AGE < 20
THEN
TeenCount ← TeenCount + 1
ENDIF
NEXT Counter
3
Method used
Description Validation Verification Name of check
Data must be entered twice and match ✔ Double entry
Data must be eight characters long ✔ Length
Data is displayed on the screen to be confirmed ✔ Visual
Data must have a value between 8 and 12 ✔ Range
Data must only contain numbers ✔ Type

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

Answers to Practice Paper 2A

b i) Password PasswordUp Symbol Counter Output


MyPassword! MYPASSWORD! FALSE Please enter your password
1
2
3
4
5
6
7
8
9
10
True 11 Accept

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

Answers to Practice Paper 2A

8
Returns the remainder of DIV
a division.

LCASE

Returns a random number.

LENGTH

Returns the number of


characters. MOD

Returns a string where all RANDOM


letters are lower case.

ROUND
Returns a string where all
letters are upper case.
SUBSTRING

Returns the quotient of a


division. UCASE

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

3 03 WHILE Counter > 50 DO

WHILE Counter < 50 DO

4 06 UNTIL NegNum > 0

UNTIL NegNum < 0

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

Answers to Practice Paper 2A

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

WHERE PlantHeight > 1.8;

Inputs Working space Output


12 a
A B C X
0 0 0 0 1 1
0 0 1 0 0 0
0 1 0 0 0 0
0 1 1 0 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 0 1
1 1 1 1 0 1

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])

def FindBaby(Baby): # procedure to find a baby


It is illegal to photocopy this page

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

Answers to Practice Paper 2A

def UpdateBaby(Baby): # procedure to update a baby's details


print("Baby’s details")
for Counter in range(Length):
if BabyName[Counter] == Baby:
BabyAge[Counter] = int(input("Enter baby’s age in months "))
ParentPhone[Counter] = input("Enter parents’ phone number ")

def SortBabys(): # procedure to sort babies in ascending order of age


Swap = True
First = 0
Last = 5
while Swap and Last > 0:
Swap = False
for Counter in range(Last - 1):
if BabyName[Counter] > BabyName[Counter + 1]:
TempBabyName = BabyName[Counter]
BabyName[Counter] = BabyName[Counter + 1]
BabyName[Counter + 1] = TempBabyName
TempAge = BabyAge[Counter]
BabyAge[Counter] = BabyAge[Counter + 1]
BabyAge[Counter + 1] = TempAge
TempPhone = ParentPhone[Counter]
ParentPhone[Counter] = ParentPhone[Counter + 1]
ParentPhone[Counter + 1] = TempPhone
Swap = True
Last = Last − 1

YoungBabies()

FindBaby(input("Enter baby's name "))

UpdateBaby(input("Enter baby's name "))

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

Answers to Practice Paper 2A

Console.Write("Enter next gamer's high score ")


GamerHighScore(Counter) = Integer.Parse(Console.ReadLine())
Next
For Counter = 0 To 49
Console.WriteLine(GamerName(Counter) & " " &
GamerHighScore(Counter))
Next
Console.WriteLine(“Average is " & FindAverage())
SortGamers()
For Counter = 0 To 49
Console.WriteLine(GamerName(Counter) & " " &
GamerHighScore(Counter))
Next
Console.ReadKey()
End Sub

' function to find average


Function FindAverage() As Decimal
Dim Total As Integer
Total = 0
For Counter = 0 To 49
Total = Total + GamerHighScore(Counter)
Next
Return Total / 50
End Function
' procedure to sort names and scores in descending order
Sub SortGamers()
Dim Swap As Boolean
Dim TempHighScore, First, Last As Integer
Dim TempName As String
First = 0
Last = 49
Do
Swap = False
For Counter = 0 To Last - 1
It is illegal to photocopy this page

If GamerHighScore(Counter) < GamerHighScore(Counter + 1) Then


TempHighScore = GamerHighScore(Counter)
GamerHighScore(Counter) = GamerHighScore(Counter + 1)
GamerHighScore(Counter + 1) = TempHighScore
TempName = GamerName(Counter)
GamerName(Counter) = GamerName(Counter + 1)
GamerName(Counter + 1) = TempName
Swap = True
End If

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

Answers to Practice Paper 2A

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];

static double FindAverage(){


int Counter, Total;
Total = 0;
for ( Counter = 0; Counter <= 4; Counter ++) {
Total = Total + GamerHighScore[Counter];
}
return Total / 5;
}

static void SortGamers(){


int TempHighScore, First, Last, Counter;
First = 0;
Last = 4;
boolean Swap;
String TempName;
do{
Swap = false;
for (Counter = 0; Counter<= Last - 1; Counter ++){
if (GamerHighScore[Counter] < GamerHighScore[Counter + 1])
{
TempHighScore = GamerHighScore[Counter];
GamerHighScore[Counter] = GamerHighScore[Counter + 1];
GamerHighScore[Counter + 1] = TempHighScore;
It is illegal to photocopy this page

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

Answers to Practice Paper 2A

public static void main(String args[]){


Scanner myObj = new Scanner(System.in);
int Counter;
for (Counter = 0; Counter <= 4; Counter ++) {
System.out.print("Enter next gamer’s name ");
GamerName[Counter] = myObj.next();
System.out.print("Enter next gamer’s high score ");
GamerHighScore[Counter] = myObj.nextInt();
}
for (Counter = 0; Counter <= 4; Counter ++) {
System.out.println(GamerName[Counter] + " " + GamerHighScore[Counter]);
}
System.out.println(“Average is " + FindAverage());
SortGamers();
for (Counter = 0; Counter <= 4; Counter ++) {
System.out.println(GamerName[Counter] + " " + GamerHighScore[Counter]);
}
}

It is illegal to photocopy this page

Hodder & Stoughton Limited © David Watson and Helen Williams 2022 195

You might also like