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

Question 7(b) 2015 · October-November · Paper 21 · 6 marks

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

Official answer for Question 7

Part (b)

Part (b)

Input of string …

✓
Correct syntax (for both prompt and assignment)
✓
Uses MyString identifier
[1]
✓
StringTotal set to 0
[1]
✓
FOR loop:
✓
FOR - NEXT keywords // (Python) correct indentation
[1]
✓
Correct start and /end boundaries
[1]
✓
Note: the end boundary must use the language length
✓
function/method // alternative Python syntax
✓
Isolate single character number
[1]
✓
Followed by the use of Asc (VB) // Ord ( Python)
✓
Assigned to NextNum
[1]
✓
Added to StringTotal
[1]
✓
Correct syntax for the output of the string and number
[1]
✓
[MAX 6]
✓
Python …
✓
MyString = input('key in string')
✓
StringTotal = 0
✓
for i in range (0, len(MyString)):
✓
NextNum = ord(MyString[i])
✓
StringTotal = StringTotal + NextNum
✓
print(MyString, StringTotal)
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – October/November 2015
✓
9608

Question 21

✓
Visual Basic…
✓
Dim MyString As String
✓
Dim StringTotal As Integer
✓
Dim i As Integer
✓
Dim NextNum As Integer
✓
Console.Write("key in string")
✓
MyString = Console.ReadLine
✓
StringTotal = 0
✓
For i = 1 To Len(MyString) // MyString.Length
✓
NextNum = Asc(Mid(MyString, i, 1))
✓
StringTotal = StringTotal + NextNum
✓
Next
✓
Console.WriteLine(MyString & "
✓
" & Str(StringTotal))
✓
Pascal …
✓
VAR MyString
✓
:
✓
String ;
✓
VAR StringTotal
✓
:
✓
Integer ;
✓
VAR i
✓
:
✓
Integer ;
✓
VAR NextNum
✓
:
✓
Integer ;
✓
VAR SingleChar
✓
:
✓
Char;
✓
begin
✓
Writeln('key in string');
✓
readln(MyString) ;
✓
StringTotal := 0 ;
✓
For i := 1 To Length(MyString) do
✓
begin
✓
SingleChar := MyString[i] ;
✓
NextNum := Ord(SingleChar) ;
✓
StringTotal := StringTotal + NextNum
✓
;
✓
end ;
✓
WriteLn(MyString, StringTotal) ;
✓
ReadLn() ;
✓
End.

Mark scheme 9608_w15_ms_21.pdf →

Show text version of question

Question 7

Part (b)

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 the built-in functions below:

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("Barcelona", 3) returns 'r'.

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER returns the number of characters in the string ThisString. For example: CHARACTERCOUNT("BRAZIL") returns 6.

CHR(ThisInteger : INTEGER) RETURNS CHAR returns the character with ASCII code ThisInteger. For example: CHR(65) returns character 'A'.

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

Part (b)

A program is to be written which accepts a string and then calculates a numeric value from

this string. The input string and the calculated value are then to be sent to a remote computer over a communications link.

Study the following pseudocode:

OUTPUT "Enter string" INPUT MyString StringTotal 0 ← FOR i ← 1 TO CHARACTERCOUNT(MyString) NextNum ← ASC(ONECHAR(MyString, i)) StringTotal ← StringTotal + NextNum ENDFOR

OUTPUT MyString, StringTotal

Write the above pseudocode algorithm as program code.

There is no need to show the declaration of variables or comment statements.

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

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

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

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

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

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

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

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

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

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

...............................................................................................................................................[6]

Topic relevance

Why this question appears here

72% 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_w15_qp_21.pdf

Keep practising this topic