Programming – A Level Computer Science (9618)
153 questions · page 11 of 11
Question text
6
A procedure CountVowels() will:
•
be called with a string containing alphanumeric characters as its parameter
•
count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
•
count and output the number of occurrences of the other alphabetic characters (as a single
total).
The string may contain both upper and lower case characters.
Each count value will be stored in a unique element of a global 1D array CharCount of type
INTEGER. The array will contain six elements.
Write pseudocode for the procedure CountVowels().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
7
A procedure, FormatName():
•
is called with a string containing words and spaces as its parameter. In this context, a word is
any sequence of characters that does not contain a space character.
•
creates a new formatted string from this string with the following requirements:
1.
Any leading spaces removed (spaces before the first word).
2.
Any trailing spaces removed (spaces after the last word).
3.
Any multiple spaces between words converted to a single space.
4.
All characters converted to lower case.
The FormatName() procedure has been written in a programming language and is to be tested
using the black-box method.
(a) Give a test string that could be used to show that all four formatting requirements have been
applied correctly.
Use the symbol ‘∇’ to represent a space character.
… [3]
(b) The FormatName() procedure should assign a value to the global variable FString.
There is a fault in the program, which means that the assignment does not always take place.
Explain two ways of exposing the fault.
…
…
…
…
… [2]
Question text
8
A program is needed to take a string containing a full name and to produce a new string of initials.
Some words in the full name will be ignored. For example, “the”, “and”, “of”, “for” and “to” may all
be ignored.
Each letter of the new string must be upper case.
For example:
Full name
Initials
Integrated Development Environment
IDE
The American Standard Code for Information Interchange
ASCII
The programmer has decided to use the following global variables:
•
a ten element 1D array IgnoreList of type STRING to store the ignored words
•
a string FNString to store the full name string.
Assume that:
•
each alphabetic character in the full name string may be either upper or lower case
•
the full name string contains at least one word.
The programmer has started to define program modules as follows:
Module
Description
• Called with an INTEGER as its parameter, representing the number of
a word in FNString
• Returns the character start position of that word in FNString or
GetStart()
returns -1 if that word does not exist
• For example: GetStart(3) applied to "hot and cold" returns 9
• Called with the position of the first character of a word in FNString
as its parameter
• Returns the word from FNString
GetWord()
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"
• Called with a STRING parameter representing a word
• Searches for the word in the IgnoreList array
IgnoreWord()
• Returns TRUE if the word is found, otherwise returns FALSE
• Processes the sequence of words in the full name one word at a time
• Calls GetStart(), GetWord() and IgnoreWord() to process
GetInitials()
each word to form the new string
• Outputs the new string
(a) Write pseudocode for the module IgnoreWord().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…