CS SRG Paper-2B-answers

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Cambridge IGCSE™ and O Level Computer Science

Practice Paper 2B answers


1 a)

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

Testing of the program to make sure that it works under all conditions

✓ Writing of the program or suite of programs

Using the program specification to show to how the program should be


developed

c) Which statement is used for iteration?


✓ NEXT

PROCEDURE

DECLARE

CASE
d) Which statement describes a database primary key?

A collection of fields about the same item

A collection of related records


✓ A field that uniquely identifies a record

A single piece of data


[4]

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 1
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

2 a) i) Validation: an automatic check that data input is reasonable.


[2]
a) ii) Any three from:
o Range check
o Length check
o Type check
o Format check
o Check digit
[3]
b) Verification is used to check that the data has been accurately copied from one place to another
without introducing any errors. For example, using a visual check by showing the data input on the
screen and asking the user to check that it is as required before accepting that data.
[3]
3 a) Structure chart

[4]
b) Flowchart

[6]

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 2
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

c) Pseudocode:

REPEAT
OUTPUT "Please enter the weight of your parcel in grams, 10gm to 10kg"
INPUT Weight
UNTIL Weight >= 10 AND Weight <= 10000
IF Weight < 250
THEN
OUTPUT "Small cost $1"
ELSE
IF Weight > 2500<
THEN
OUTPUT "Large cost $5"
ELSE
OUTPUT "Medium cost $3"
ENDIF
ENDIF
[6]
4 In order to be able to maintain a program it needs to be easily understood by other programmers. All
the identifiers used in the program should have meaningful names. For example when declaring
constants. and variables. Any code reused in the program should be part of function or procedure The
programmer should include comments to explain how the solution works and the syntax used.
[8]
5 a) Finding the average of several numbers.
[1]
b)
X Y Z W OUTPUT
0 0
1 20 20
2 50 30
3 105 55
4 170 65
5 160 -10
-999 32 32

[4]
c) Suggest meaningful names for:

W Total

X Counter

Y Average

Z Number
[2]
6 FOR Index  1 TO 24
INPUT Temperature[Index]
Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 3
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

IF Temperature[Index] > 30
THEN
OUTPUT "too high"
ELSE
IF Temperature[Index] < 20
THEN
OUTPUT "too low"
ENDIF
ENDIF
NEXT Index
[6]
7

[4]
8
1 01 For Index  0 TO 100
For Index  1 TO 100
2 01 For Index  0 TO 100
For Index  1 TO 50

3 04 WHILE Number >= 0 OR Number <= 50


WHILE Number >= 0 OR Number <= 100
4 04 WHILE Number >= 0 OR Number <= 100
WHILE Number >= 0 AND Number <= 100

5 06 Index  Index + 1
Remove line
6 07 NEXT Number
NEXT Index
[6]

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 4
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

9 a)
HouseType, text as a short description is required
Bedrooms, integer as a whole number is required, and this may be used for sorting
Bathrooms, integer as a whole number is required, and this may be used for sorting
Address, text as several words and numbers are required
Garage, Boolean as this can be true or false
Price, Currency as the price should be displayed in dollars
[6]
b)

Name: HouseID

Data type: Text

Example: P370

Reason for use: To uniquely identify each property for rent

[4]
c)

SELECT HouseType, Address, Price

FROM HouseRent

WHERE Garage;
[4]
10 a) T = (G AND NOT R AND NOT O) OR (R AND O AND NOT G)
[4]
b)
Inputs Working space Output
R O G T
0 0 0 0 0 0
0 0 1 1 0 1
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 0 0 0
1 1 1 0 0 0
[4]

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 5
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

c)

[6]
11
Python:
# set up starting conditions
Name = input("Please enter your name ")
Table = 0
while (Table < 1 or Table > 12):
Table = int(input("Please enter a table between 1 and 12 "))
Questions = 0
while (Questions < 5 or Questions > 10):
Questions = int(input("Please enter the number of questions between 5 and 10 "))

Retest = True

# conduct the test


while Retest:
Right = 0
for QuestionNumber in range(1, Questions + 1):
print("Question ", QuestionNumber)
print (Table, " X ", QuestionNumber)
Answer = int(input("Answer "))
if Answer == Table*QuestionNumber:
print(Name, " you are right, well done")
Right +=1
else:
print(Name, " you are wrong the answer is ", Table*QuestionNumber)
print("Test over ", Name, " you got ", Right, " out of ", Questions)

Choice = input(" Do you want a retest Y or N? ")# check for a retest


if Choice != "Y":
Retest = False

[14]

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 6
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

Visual Basic:

Module Module1

Sub Main()
Dim Name, Choice As String
Dim Table, Questions, QuestionNumber, Right, Answer As Integer
Dim ReTest As Boolean
' set up staring conditions
Console.Write("Please enter your name ")
Name = Console.ReadLine()
Do
Console.Write("Please enter a table between 1 and 12 ")
Table = Int(Console.ReadLine())
Loop Until Table >= 1 And Table <= 12

Do
Console.Write("Please enter the number between 5 and 10 ")
Questions = Int(Console.ReadLine())
Loop Until Questions >= 5 And Questions <= 10

ReTest = True

' conduct the test


Do
Right = 0
For QuestionNumber = 1 To Questions
Console.WriteLine("Question " & QuestionNumber)
Console.WriteLine(Table & " X " & QuestionNumber)
Answer = Int(Console.ReadLine())
If Answer = QuestionNumber * Table Then
Console.WriteLine(Name & " you are right well done")
Right = Right + 1
Else
Console.WriteLine(Name & " you are wrong the answer is " & Table *
QuestionNumber)
End If
Next
Console.WriteLine("Test over " & Name & " you got " & Right & " out of " & Questions)
Console.WriteLine("Do you want a retest Y or N?")
Choice = Console.ReadLine()
If Choice <> "Y" Then
ReTest = False
End If

Loop Until Not ReTest

[14]

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 7
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

Java:
import java.util.Scanner;
class ExamQ11Java
{

public static void main(String args[])


{
// set up starting conditions
Scanner myObj = new Scanner(System.in);
String Name;
System.out.print("Please enter your name ");
Name = myObj.next();
int Table;
do
{
System.out.print("Please enter a table between 1 and 12 ");
Table = myObj.nextInt();
}
while (Table < 1 || Table > 12);

int Questions;
do
{
System.out.print("Please enter the number of questions between 5 and 10 ");
Questions = myObj.nextInt();
}
while (Questions < 5 || Questions > 12);

boolean Retest = true;

int QuestionNumber, Answer, Right;

// conduct the test


do
{
Right = 0;
for (QuestionNumber= 1; QuestionNumber <= Questions; QuestionNumber ++)
{

System.out.println("Question " + QuestionNumber);


System.out.println(Table + " X " + QuestionNumber);
Answer = myObj.nextInt();
if (Answer == Table * QuestionNumber)
{
System.out.println(Name + " you are right, well done");
Right ++;
}
else
{
System.out.println(Name + " you are wrong the answer is " + Table * QuestionNumber);
}
}
System.out.println("Test over " + Name + " you got " + Right + " out of " + Questions );
System.out.print("Do you want a retest Y or N? ");
String Choice;
Choice = myObj.next();
if(!Choice.equals("Y"))
{
Retest = false;
}
}
while (Retest);

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 8
© Hodder & Stoughton Ltd 2022
Cambridge IGCSE™ and O Level Computer Science

}
[14]

Cambridge IGCSE™ and O Level Computer Science Second Edition Study and Revision Guide 9
© Hodder & Stoughton Ltd 2022

You might also like