Past-paper question · 2015 October-November · Paper 22 · Q7(b)(i)

Question 7(b)(i) 2015 · October-November · Paper 22 · 8 marks

Original past-paper question for 7(B)(I)
Original past-paper question for 7(B)(I)
Original past-paper question for 7(B)(I)
Reveal official mark-scheme answer Official mark-scheme answer for 7(B)(I)Official mark-scheme answer for 7(B)(I)

Official answer for Question 7

Part (b)

(i)

Part (b)

(i)

Use of correct identifiers only to score

✓
Declaration/Commenting of variables
✓
MyMessage As String
✓
EncryptString As String
✓
i As Integer
✓
NextNum As Integer
✓
At least two variables correctly documented
[1]
✓
Input of string …
✓
Correct syntax (for both prompt and assignment) and …
✓
Uses the MyMessage identifier
[1]
✓
EncryptString set to ‘empty string’
[1]
✓
Note: Must suggest ‘empty’ string
✓
For loop …
✓
FOR – NEXT keywords // (Python) correct indentation
[1]
✓
Correct start/end boundaries
[1]
✓
Note: the end boundary must use the language length
✓
function/method //alternative Python syntax
✓
Isolate single character
[1]
✓
Use of language functions to calculate new number and ….
✓
Assigned to NextNum
[1]
✓
Conversion of NextNum to a character and concatenated
✓
to EncryptString
[1]
✓
Correct syntax for output of EncryptString
[1]
✓
[MAX 8]
✓
SAMPLE CODE
✓
PYTHON
✓
MyMessage = input("Enter message : ")
✓
EncryptString = ""
✓
for i in range(0, len(MyMessage)) :
✓
NextNum = ord(MyMessage[i]) + 3
✓
EncryptString = EncryptString + chr(NextNum)
✓
print(EncryptString)
✓
Alternative solution:
✓
MyMessage = input("Enter message : ")
✓
EncryptString = ""
✓
for NextChar in MyMessage :
✓
NextNum = ord(NextChar) + 3
✓
EncryptString = EncryptString + chr(NextNum)
✓
print(EncryptString)
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – October/November 2015
✓
9608

Question 22

✓
VB
✓
Dim MyMessage, EncryptString As String
✓
Dim NextNum, i As Integer
✓
Console.Write("Enter message : ") Alternatives:
✓
MyMessage = Console.ReadLine()
✓
GetChar(MyMessage, i)
✓
EncryptString = ""
✓
MyMessage.Substring(i, 1)
✓
For i = 1 To Len(MyMessage)
✓
NextNum = Asc(Mid(MyMessage, i, 1)) + 3
✓
EncryptString = EncryptString +//& Chr(NextNum)
✓
Next
✓
Console.WriteLine(EncryptString)
✓
Alternative solution :
✓
Dim MyMessage, EncryptString As String
✓
Dim NextNum, i As Integer
✓
Console.Write("Enter message : ")
✓
MyMessage = Console.ReadLine()
✓
EncryptString = ""
✓
For i = 0 To Len(MyMessage) - 1
✓
NextNum = Asc(MyMessage.Chars(i)) + 3
✓
EncryptString = EncryptString + Chr(NextNum)
✓
Next
✓
Console.WriteLine(EncryptString)
✓
PASCAL
✓
var
✓
MyMessage, EncryptString : string;
✓
NextNum, i : integer;
✓
begin
✓
write('Enter message : ');
✓
readln(MyMessage);
✓
EncryptString := '';
✓
for i := 1 to length(MyMessage) do
✓
begin
✓
NextNum := ord(MyMessage[i]) + 3;
✓
EncryptString := EncryptString + chr(NextNum);
✓
end;
✓
writeln(EncryptString);
✓
end.

Mark scheme 9608_w15_ms_22.pdf →

Show text version of question

Question 7

Part (b)

(i)

Question 7

ASCII character codes are used to represent a single character.

Part of the code table is shown below.

ASCII code table (part) Character Decimal Character Decimal Character Decimal <Space> 32 I 73 R 82

A
65 J 74 S 83
B
66 K 75 T 84
C
67 L 76 U 85
D
68 M 77 V 86

E 69 N 78 W 87 F 70 O 79 X 88 G 71 P 80 Y 89 H 72 Q 81 Z 90

Some pseudocode statements follow which use these built-in functions:

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER returns the number of characters in the string ThisString. For example: CHARACTERCOUNT("South Africa") returns 12.

CHR(ThisInteger : INTEGER) RETURNS CHAR returns the character with ASCII value ThisInteger. For example: CHR(66) returns 'B'.

ASC(ThisCharacter : CHAR) RETURNS INTEGER returns the ASCII value for character ThisCharacter. For example: ASC('B') returns 66.

A
program is to be written to input a message string and then encrypt the message.

Study the following pseudocode:

OUTPUT "Enter message" INPUT MyMessage EncryptString "" ← FOR i ← 1 TO CHARACTERCOUNT(MyMessage) NextNum ← ASC(ONECHAR(MyMessage, i) + 3) EncryptString ← EncryptString & CHR(NextNum) ENDFOR

OUTPUT EncryptString

(i)

Write the above pseudocode algorithm as program code.

Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type.

Programming language .....................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[8]

Topic relevance

Why this question appears here

91% assigned-topic match · Programming › Programming basics

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_w15_qp_22.pdf

Keep practising this topic