Name: ________________________
String handling operations
Class: ________________________
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,
CHAR_TO_CODE('a') returns the value 97
CHAR_TO_CODE('z') returns the value 122
CHAR_TO_CODE('`') returns the value 96
CHAR_TO_CODE('{') returns the value 123
Develop an algorithm, using either pseudo-code or a flowchart, that:
• asks the user to enter a character
• outputs 'LOWER' if the user has entered a lowercase character
• outputs 'NOT LOWER' if the user has entered any other character.
You must use the built-in CHAR_TO_CODE subroutine in your answer.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(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’]
• For the following questions, array indexing starts at 1.
(b) Shade two lozenges which correspond to the two true statements about these
arrays.
A a[1] = b[1] OR a[1] = c[1]
B LENGTH(b) ≥ LENGTH(a)
C NOT (a[6] = b[1] AND a[3] = c[3])
D a = a[5]
E a[LENGTH(a) − LENGTH(c)] = c[3]
(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.
For example using the character arrays:
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.
Your subroutine should also:
• work for character arrays of all lengths greater than 0
• not assume that the length of pre is less than the length of word .
The start of your subroutine has been completed for you.
SUBROUTINE Prefix(word, pre)
___________________________________________________________________
Page 3 of 4
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(9)
(Total 12 marks)
Page 4 of 4