0% found this document useful (0 votes)
3 views

String Handlers

The document provides pseudocode exercises related to string manipulation, including operations like SUBSTRING and LENGTH. It includes tasks such as storing strings, extracting substrings, converting cases, and calculating string lengths. The exercises are designed to test understanding of string handling in programming.

Uploaded by

0534muntahaa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

String Handlers

The document provides pseudocode exercises related to string manipulation, including operations like SUBSTRING and LENGTH. It includes tasks such as storing strings, extracting substrings, converting cases, and calculating string lengths. The exercises are designed to test understanding of string handling in programming.

Uploaded by

0534muntahaa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Topic: String Handlers

2210/23/O/N/22
7 The string operation SUBSTRING(Quote, Start, Number) returns a string from Quote
beginning at position Start that is Number characters long. The first character in Quote is in
position 1.

Write pseudocode statements to:


• store the string "Learning Never Exhausts The Mind" in Quote
• extract and display the words "The Mind" from the string
• output the original string in lower case.

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

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

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

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

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

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

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

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

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

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

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

.................................................................................................................................................... [5]
2210/23/M/J/22
11 The variables P and Q are used to store data in a program. P stores a string. Q stores a character.

(a) Write pseudocode statements to declare the variables P and Q, store "The world" in P
and store 'W' in Q
...................................................................................................................................................

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

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

............................................................................................................................................. [2]

(b) Write a pseudocode algorithm to:


• convert P to upper case
• find the position of Q in the string P (the first character in this string is in position 1)
• store the position of Q in the variable Position

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [4]

(c) Give the value of Position after the algorithm has been executed with the data in
question 11(a).

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

............................................................................................................................................. [1]
2210/23/M/J/21
8 The function LENGTH(Phrase) calculates the length of a string Phrase

(a) Write the pseudocode statements to:


• store the string "The beginning is the most important part" in Phrase
• calculate and output the length of the string
• output the string in upper case.

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

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

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

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

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

............................................................................................................................................. [3]

(b) Write the output your pseudocode should produce.

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

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

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

............................................................................................................................................. [2]
Specimen paper 2B
10 A function LENGTH(X) finds the length of a string X and a function SUBSTRING(X,Y,Z) finds a
substring of X starting at position Y and Z characters long. The first character in the string is
position 1.

(a) Show the value of the variable after each pseudocode statement has been executed.

01 P ← "Computer Science" .........................................................................................

02 Q ← LENGTH(P) ............................................................................................................

03 R ← SUBSTRING(P,10,7) ...........................................................................................

04 S ← LENGTH(R) ............................................................................................................

05 T ← SUBSTRING(R,1,3) .............................................................................................
[5]

(b) Write a pseudocode statement to extract the word Computer from P and store it in the
variable F.
...................................................................................................................................................

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

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

.............................................................................................................................................. [2]
Specimen paper 2A
1 The variables X, Y and Z are used to store data in a program:

 X stores a string
 Y stores a position in the string (e.g. 2)
 Z stores the number of characters in the string.

(a) Write pseudocode statements to declare the variables X, Y and Z.

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

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

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

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

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

......................................................................................................................................
........ [3]

(b) The function LENGTH(X) finds the length of a string X.

The function SUBSTRING(X,Y,Z) finds a substring of X starting at position Y


and Z
characters long. The first character in X is in position 1.

Write pseudocode statements to:


 store the string "Programming is fun" in X
 find the length of the string and output it
 extract the word fun from the string and output it.

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

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

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

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

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

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

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

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

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

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

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

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

You might also like