A program is needed to take a string containing a full name and 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 abbreviated 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 a global variable FNString of type STRING to store the full name. It is assumed that: • words in the full name string are separated by a single space character • space characters will not occur at the beginning or the end of the full name string • the full name string contains at least one word. The programmer has started to define program modules as follows: Module | Description --- | --- GetStart() | • Called with an INTEGER as a parameter, representing the number of a | word in FNString. | • Returns the character start position of that word in FNString or | returns -1 if that word does not exist | • For example: if FNString contains the string "hot and cold", | GetStart (3) returns 9 GetWord() | • Called with a parameter representing the position of the first character | of a word in FNString | • Returns the word from FNString | • For example: if FNString contains the string "hot and cold", | GetWord(9) returns "cold"
- (a)Write pseudocode for the module GetStart().[7]
- (b)The programmer has decided to use a global ten-element 1D array IgnoreList of type STRING to store the ignored words. Unused elements contain the empty string ("") and may occur anywhere in the array. A new module AddWord() is needed as follows: Module | Description --- | --- AddWord() | • Called with a parameter representing a word | • Stores the word in an unused element of the IgnoreList array | and returns TRUE | • Returns FALSE if the array was already full or if the word was | already in the array Write a detailed description of the algorithm for AddWord(). Do not include pseudocode statements in your answer.[4]
- (c)As a reminder, the module description of GetWord () is repeated: Module | Description --- | --- GetWord() | • Called with a parameter representing the position of the first | character of a word in FNString | • Returns the word from FNString | • For example: if FNString contains the string "hot and cold", | GetWord(9) returns "cold" Write pseudocode for the module GetWord().[5]
Mark scheme
Marking points from the official mark scheme (May/June 2021). The mark or mark type is shown in brackets.
- [1] Function heading, including return type and function end
- [1] Loop counting spaces until word found or end of FNString
- [1] extract a character from FNString in a loop
- [1] compare with SPACECHAR and increment count if equal in a loop
- [1] compare count with WordNum - 1 (depending on initialisation value) in a loop
- [1] if equal then set flag or Index to ThisPos + 1 in a loop
- [1] Return Index (correctly in all cases / following a reasonable attempt)
- [1] Works for special case when looking for word 1
- [1] Mention of variable for use as array index
- [1] Use of a loop (to check through the array)
- [1] If word is the same as the current array element then return FALSE / set flag
- [1] If word not already in array, loop to find unused element (second loop)
- [1] Store word in unused element and return TRUE, otherwise return FALSE
- VARIATION:
- [1] Mention of variable for use as array index
- [1] Use of a loop (to check through the array)
- [1] Save index of (first) unused element found
- [1] If word is the same as the current array element then return FALSE / set flag
- [1] If word not already in array and unused element available, store word in unused element and return TRUE otherwise return FALSE
- [1] Conditional loop
- [1] Extract char from FNString and compare with SPACECHAR in a loop
- [1] Concatenate with NextWord if not SPACECHAR in a loop
- [1] Exit loop when SPACECHAR encountered or when end of FNString reached
- [1] Return NextWord (after reasonable attempt at forming, and must have been initialised)
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →