Past-paper question · 2016 October-November · Paper 22 · Q6

Question 6 2016 · October-November · Paper 22 · 5 marks

Original past-paper question for 6
Original past-paper question for 6
Original past-paper question for 6
Original past-paper question for 6
Reveal official mark-scheme answer Official mark-scheme answer for 6

Official answer for Question 6

(i)

10 / 10.0

[1]

(ii)

18.4

[1]

(iii)

41

[1]

(iv)

TRUE

[1]

(v)

12.4

[1]
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – October/November 2016
✓
9608

Question 22

✓
Appendix – Program code example solutions
✓
Q4 (b): Visual Basic
✓
Randomize()
✓
Dim i As Integer
✓
Dim NextNumber As Integer
✓
For i = 1 To 4
✓
NextNumber = 1 + Int(Rnd() * 150)
✓
Console.WriteLine(NextNumber)
✓
Next
✓
OR
✓
Randomize()
✓
Dim Num1, Num2, Num3, Num4 As Integer
✓
Num1 = 1 + Int(Rnd() * 150)
✓
Num2 = 1 + Int(Rnd() * 150)
✓
Num3 = 1 + Int(Rnd() * 150)
✓
Num4 = 1 + Int(Rnd() * 150)
✓
Console.WriteLine(Num1, Num2, Num3, Num4)
✓
Q4 (b): Pascal
✓
Var i : Integer;
✓
NextNumber : Integer;
✓
Begin
✓
Randomize;
✓
For i := 1 To 4 Do
✓
Begin
✓
NextNumber := 1 + Random(150);
✓
Writeln(NextNumber);
✓
End;
✓
Readln;
✓
End.
✓
OR
✓
Var Num1, Num2, Num3, Num4 : Integer;
✓
Begin
✓
Randomize;
✓
Num1 := 1 + Random(150);
✓
Num2 := 1 + Random(150);
✓
Num3 := 1 + Random(150);
✓
Num4 := 1 + Random(150);
✓
Writeln(Num1, Num2, Num3, Num4);
✓
Readln;
✓
End.
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – October/November 2016
✓
9608

Question 22

✓
Q4 (b): Python
✓
import random
✓
# i : Integer
✓
# NextNumber : Integer
✓
for i in range(1, 5) :
✓
NextNumber = 1 + int(150 * random.random())
✓
print(NextNumber)
✓
Alternative:
✓
import random
✓
# i Integer
✓
# NextNumber Integer
✓
for i in range(1, 5) :
✓
NextNumber = random.randint(1, 150)
✓
print(NextNumber)
✓
OR
✓
import random
✓
# i Integer
✓
# Num1, Num2, Num3, Num4 Integer
✓
Num1
✓
=
✓
random.randint(1,
✓
150)
✓
Num2
✓
=
✓
random.randint(1,
✓
150)
✓
Num3
✓
=
✓
random.randint(1,
✓
150)
✓
Num4
✓
=
✓
random.randint(1,
✓
150)
✓
print(Num1, Num2, Num3, Num4)
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – October/November 2016
✓
9608

Question 22

✓
Q5 (b) (ii): Visual Basic
✓
Dim PlayerName(8) As String
✓
Dim i As Integer
✓
FileOpen(1, "Names.txt", OpenMode.Input)
✓
i = 1
✓
Do
✓
PlayerName(i) = LineInput(1)
✓
i = i + 1
✓
Loop Until EOF(1)
✓
FileClose(1)
✓
Alternative:
✓
Dim PlayerName(8) As String
✓
Dim i As Integer
✓
FileOpen(1, "Names.txt", OpenMode.Input)
✓
For i = 1 To 8
✓
PlayerName(i) = LineInput(1)
✓
Next
✓
FileClose(1)
✓
Alternative:
✓
Dim sr As StreamReader = New StreamReader("Names.txt")
✓
Dim line As String
✓
line = sr.ReadLine()
✓
i = 1
✓
Do While (line <> Nothing)
✓
PlayerName(i) = line
✓
i = i + 1
✓
line = sr.ReadLine()
✓
Loop
✓
sr.Close()

Mark scheme 9608_w16_ms_22.pdf →

Show text version of question

Question 6

Study the sequence of pseudocode statements.

CONST a = 3.2 : REAL DECLARE x, y, z, Answer1, Answer2, Answer3 : REAL DECLARE p, q : BOOLEAN x 3 x x + 7 y 6 Answer1 2 * (a + y) z 6 Answer2 y ^ 2 + 5 p TRUE q NOT(NOT(p)) Answer3 y + a * 2

Give the final value assigned to each variable.

(i)

x .............................................

[1]

(ii)

Answer1 .............................................

[1]

(iii)

Answer2 .............................................

[1]

(iv)

q .............................................

[1]

(v)

Answer3 .............................................

[1]

Question 18

Appendix Built-in functions (pseudocode)

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR

returns the single character at position Position (counting from the start of the string with value 1) from the string ThisString.

For example: ONECHAR("New York", 5) returns 'Y'

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER

returns the number of characters in ThisString.

For example: CHARACTERCOUNT("New York") returns 8

SUBSTR(ThisString : STRING, Value1 : INTEGER, Value2 : INTEGER) RETURNS STRING

returns a sub-string from within ThisString. Value1 is the start index position (counting from the left, starting with 1). Value2 is the final index position.

For example: SUBSTR("art nouveau", 5, 11) returns "nouveau"

TONUM(ThisString : STRING) RETURNS INTEGER or REAL

returns the integer or real equivalent of the string ThisString.

For example: TONUM("502") returns the integer 502 TONUM("56.36") returns the real number 56.36

ASC(ThisCharacter : CHAR) RETURNS INTEGER

returns an integer which is the ASCII character code for the character ThisCharacter.

For example: ASC('A') returns integer 65

Question 19

CHR(Value : INTEGER) RETURNS CHAR

returns the character that ASCII code number Value represents.

For example: CHR(65) returns 'A'

RND() RETURNS REAL

returns a random number in the range 0 to 0.99999

For example: RND() returns 0.67351

INT(ThisNumber : REAL) RETURNS INTEGER

returns the integer part of ThisNumber.

For example: INT(12.79) returns 12

Errors

For any function, if the program calls the function incorrectly, the function returns an error.

Concatenation operator

& operator – Concatenates two expressions of STRING or CHAR data type.

For example: "South" & " " & "Pole" produces "South Pole" 'B' & "000654" produces "B000654"

Question 20

effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series.

Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.

Topic relevance

Why this question appears here

99% assigned-topic match · Data types and structures › Data types and records

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_w16_qp_22.pdf

Keep practising this topic