String Handling Operations Question Paper
String Handling Operations Question Paper
Date: ________________________
Time: 19 minutes
Marks: 19 marks
Comments:
Page 1 of 4
Q1.
The subroutine CHAR_TO_CODE(character) returns the integer ASCII value of a
character. For example,
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 7 marks)
Q2.
The variables a, b and c in the figure below are assigned string values.
a ‘bitmap’
b ‘pixel’
c ‘bit’
(a) Shade one lozenge which shows the concatenation of the variables a and b shown
in the figure above.
concatenation of the variables a and b
Page 2 of 4
A bitmap pixel
B bitmappixel
C ab
(1)
Strings can also be represented as arrays of characters. For instance, the three
statements below are an alternative to the statements shown in the figure above where
those strings are now being represented as arrays of characters.
a [‘b’,‘i’,‘t’,‘m’,‘a’,‘p’]
b [‘p’,‘i’,‘x’,‘e’,‘l’]
c [‘b’,‘i’,‘t’]
(b) Shade two lozenges which correspond to the two true statements about these
arrays.
B LENGTH(b) ≥ LENGTH(a)
D a = a[5]
(2)
(c) Develop a subroutine called Prefix, using either pseudo-code or a flowchart, which
takes two character arrays called word and pre as parameters and determines
whether the start of the character array word is the same as all of the character
array pre.
a [‘b’,‘i’,‘t’,‘m’,‘a’,‘p’]
b [‘p’,‘i’,‘x’,‘e’,‘l’]
c [‘b’,‘i’,‘t’]
• a starts with the same sequence of characters as c so Prefix(a, c) would
return true
• b does not start with the same sequence of characters as c so Prefix(b, c)
would return false.
___________________________________________________________________
Page 3 of 4
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(9)
(Total 12 marks)
Page 4 of 4