CSDFF
CSDFF
12
5 A company creates two new websites, Site X and Site Y, for selling bicycles.
These programs will use data about daily sales made from Site X (using variable SalesX) and
Site Y (using variable SalesY).
28 01/07/2015 14 8
...............................................................................................................................................[2]
5 A firm employs workers who assemble amplifiers. Each member of staff works an agreed number
of hours each day.
The firm records the number of completed amplifiers made by each employee each day.
Daily hours
worked Production data
Worker 1 5 Worker 1 Worker 2 Worker 3
Worker 2 10 Day 1 10 20 9
Worker 3 10 Day 2 11 16 11
Day 3 10 24 13
Day 4 14 20 17
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
.......................................................................................................................................[2]
.......................................................................................................................................[1]
...........................................................................................................................................
.......................................................................................................................................[2]
Write the program code. Do not attempt to include any validation checks.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................[10]
8 In this question you will need to use the given pseudocode built-in function:
A program reads a string entered by the user. The string represents the addition or subtraction
of two fractions. Each part of the fraction within the string is always a single digit only and the
top digit is always less than the bottom digit.
Op
é
N4Char
N3Char
N2Char
N1Char
The identifier table shows the variables to be used to store the characters in the string as
shown in the diagram.
FractionString ← "3/7+2/9"
N3Char ← ONECHAR(FractionString, 5) (i) N3Char .................................... [1]
Op ← ONECHAR(FractionString, 4) (ii) Op .............................................. [1]
(iii) Complete the function call to isolate the character '9' from FractionString.
FractionString ← "3/7+2/9"
Complete the three dry runs for the three given values of FractionString.
BottomAnswer ← N2 * N4
Op ← ONECHAR(FractionString, 4)
IF Op = '+'
THEN
// add fractions
TopAnswer ←
(BottomAnswer / N2) * N1 + (BottomAnswer / N4) * N3
ELSE
// subtract fractions
TopAnswer ←
(BottomAnswer / N2) * N1 - (BottomAnswer / N4) * N3
ENDIF
IF TopAnswer = BottomAnswer
THEN
OUTPUT '1'
ELSE
IF TopAnswer > BottomAnswer
THEN
TopAnswer ←
TopAnswer MOD BottomAnswer
// the & operator joins strings or character values
OUTPUT "1 " & TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer)
ELSE
OUTPUT TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer)
ENDIF
ENDIF
[2]
[2]
[3]
(d) The programmer writes code from the given pseudocode design. The program works, but the
design is limited.
.......................................................................................................................................[1]
(ii) Describe three specification changes which will make the program more useful.
1 .......................................................................................................................................
...........................................................................................................................................
2 .......................................................................................................................................
...........................................................................................................................................
3 .......................................................................................................................................
.......................................................................................................................................[3]
6 Some pseudocode statements follow which use the following built-in functions:
NewString ""←
INPUT InputString
j ← CHARACTERCOUNT(InputString)
FOR i ←
1 TO j
NextChar ←
ONECHAR(InputString, i)
IF NextChar <> " "
THEN
// the & character joins together two strings
NewString ←
NewString & NextChar
ENDIF
ENDFOR
OUTPUT NewString
[4]
© UCLES 2015 9608/22/O/N/15 [Turn over
14
The function:
• has identifier RemoveSpaces
• has a single parameter
• will include the declaration for any local variables used by the function
// main program
INPUT MyString
ChangedString ← RemoveSpaces(.........................................................................................)
OUTPUT ChangedString
// function definition
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
j ← CHARACTERCOUNT(InputString)
FOR i ← 1 TO j
NextChar ← ONECHAR(InputString, i)
IF NextChar <> " "
THEN
// the & character joins together two strings
NewString ← NewString & NextChar
ENDIF
ENDFOR
.................................................................................................................................................
ENDFUNCTION
[7]
6 A string-handling function has been developed. The pseudocode for this function is shown below.
For the built-in functions list, refer to the Appendix on page 18.
n 0
f 0
REPEAT
n n + 1
x n
y 1
WHILE MID(String1, x, 1) = MID(String2, y, 1)
IF y = LENGTH(String2)
THEN
f n
ELSE
x x + 1
y y + 1
ENDIF
ENDWHILE
RETURN f
ENDFUNCTION
(a) Complete the trace table below by performing a dry run of the function when it is called as
follows:
SSM("RETRACE", "RAC")
n f x y MID(String1, x, 1) MID(String2, y, 1)
0 0
[6]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) One of the possible return values from function SSM has a special meaning.
Value .................................................................................................................................
Meaning ............................................................................................................................
[2]
(iii) There is a problem with the logic of the pseudocode. This could generate a run-time
error.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
Appendix
Built-in functions
In each function below, if the function call is not properly formed, the function returns an error.
String operator
& operator
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
BLANK PAGE
For the built-in functions list, refer to the Appendix on the last page.
Flag TRUE
NewString ""
m LENGTH(ThisString)
FOR n 1 TO m
IF Flag = TRUE
THEN
x UCASE(MID(ThisString, n, 1))
Flag FALSE
ELSE
x LCASE(MID(ThisString, n, 1))
ENDIF
IF x = " "
THEN
Flag TRUE
ENDIF
ENDFOR
RETURN NewString
ENDFUNCTION
(a) (i) Complete the trace table below by performing a dry run of the function when it is called
as follows:
SF("big BEN")
n x Flag m NewString
[4]
© UCLES 2016 9608/23/M/J/16
15
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(i) State what happens when the function is called with an empty string.
...........................................................................................................................................
.......................................................................................................................................[1]
In each case explain why the test string has been chosen.
String .................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
String .................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
String .................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
[3]
A program reads the signal from Channel 2 after every six values from Channel 1.
01 BitCount 0
02 Status2 READ(2)
03 WHILE Status2 = 1
04
05 FOR ReadingCount 1 TO 6
06 ThisBit READ(1)
07 IF ThisBit = 1
08 THEN
09 BitCount BitCount + 1
10 ENDIF
11 IF BitCount = 5
12 THEN
13 OUTPUT "Error – Investigate"
14 BitCount 0
15 ENDIF
16 ENDFOR
17
18 Status2 READ(2)
19 ENDWHILE
(a) Trace the execution of the program for the following sequence of bits.
Channel 1 1 0 1 1 1 0 1 1 0 0 1 1
Channel 2 1 1 0
1 1 1 1
[7]
(b) Identify the following constructs in the given program, using line numbers.
Assignment
Selection
Iteration
[3]
5 A team keeps a record of the scores made by each of their eight players in a number of games.
1 2 3 8
1 12 17 67 31
2 35 82 44 29
3 61 39 80 17
4 81 103 21 11
5 56 0 98 4
19 45 6 81 77
20 12 11 3 6
1 Vorma
2 Ravi
3 Chada
4 Nigam
5 Bahri
6 Smith
7 Goyal
8 Lata
The team wants a computer program to input and record the player data.
(a) A programmer designs the following pseudocode for the input of a player’s score from one
game.
01 INPUT GameNumber
02 INPUT PlayerNumber
03 INPUT PlayerGameScore
04 PlayerScore[GameNumber, PlayerNumber] PlayerGameScore
Describe the data structure the programmer has used for the storage of all player scores.
.............................................................................................................................................. [2]
(b) The player names are permanently stored in a text file NAMES.TXT, with one name on each
line. The player names will be read by the program and stored in a 1D array.
The design given in part (a) will be expanded so that the user is prompted for the player
name instead of the player number. Step 02 now becomes:
02.1 Read the player names from file NAMES.TXT into the array PlayerName
02.2 INPUT ThisPlayerName
02.3 Search the PlayerName array for ThisPlayerName to find the PlayerNumber
(i) State the computing term for the expansion of one or more steps in the original design.
...................................................................................................................................... [1]
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
Write program code to carry out the linear search for step 02.3
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
(c) The team wants the program to produce a report, with the following specification.
The program outputs the total number of player scores that are:
You can assume that before the section runs, the program has assigned all eight player scores to
the PlayerScore data structure.
01 Total50 0
02 Total100 0
03 FOR PlayerIndex 1 TO 8
04 FOR GameIndex 1 TO 20
05 IF PlayerScore[GameIndex, PlayerIndex] > 100
06 THEN
07 Total100 Total100 + 1
08 ELSE
09 IF PlayerScore[GameIndex, PlayerIndex] > 50
10 THEN
11 Total50 Total50 + GameIndex
12 ENDIF
13 ENDIF
14 ENDFOR
15 ENDFOR
16 OUTPUT Total50
17 OUTPUT Total100
(i) Describe the control structure used in lines 03 and 04 and lines 14 and 15.
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
Explanation .......................................................................................................................
...................................................................................................................................... [1]
6 A firm employs five staff who take part in a training programme. Each member of staff must
complete a set of twelve tasks which can be taken in any order. When a member of staff
successfully completes a task, this is recorded.
A program is to be produced to record the completion of tasks for the five members of staff.
To test the code, the programmer makes the program generate test data.
Each pair of numbers simulates the completion of one task by one member of staff.
(a) Explain why the generation of 60 (5 staff x 12 tasks) pairs of random numbers will not simulate
all tasks completed by all staff.
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
The table shows that two members of staff have each successfully completed one task.
The program must use a suitable data structure to store, for all staff:
The program will output the staff number and task number in the order in which tasks are
completed.
(iii) The incrementing of a variable used as a counter, but not to control a ‘count controlled’
loop.
.................... [1]
.................... [1]
.......................................................................................................................................[1]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
(iv) Give the global variable that needs to be declared at line 03.
.......................................................................................................................................[2]
(d) Line 17 in the pseudocode outputs the staff number and the task number.
Staff number Staff name
A new requirement is to display the name of the
member of staff given in the table. 1 Sadiq
2 Smith
Write a CASE structure using variable StaffNum. 3 Ho
Assign to a new variable StaffName the appropriate 4 Azmah
staff name. 5 Papadopoulos
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
4 The standard pack of playing cards has four suits – called Clubs, Diamonds, Hearts and Spades.
Each card has a value shown by its number or a name: 1 (Ace), 2, 3, … 10, 11 (Jack), 12 (Queen),
13 (King). The pack of cards has one combination for each suit and value.
A program is to be written which simulates a magician dealing all 52 cards from the card pack.
(a) Explain why the generation of 52 (4 suits x 13 card values) pairs of random numbers will not
simulate the dealing of the complete pack.
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
Card value
Suit
number 1 2 3 4 5 6 7 8 9 10 11 12 13
1 (Clubs) F F F F F F F F F F T F F
2 (Diamonds) F F F F F F F F F F F F F
3 (Hearts) F F T F F F F F F F F F F
4 (Spades) F F F F F F F F F F F F F
The table shows two cards have been dealt so far; the 3 of Hearts and the Jack of Clubs.
The program will output the suit and the card value in the order in which the cards are dealt.
.......................................................................................................................................[1]
.......................................................................................................................................[1]
(iii) The initialisation of a variable used as a counter, but not to control a ‘count controlled’
loop.
.......................................................................................................................................[1]
.......................................................................................................................................[1]
...............................................................................................................................................[1]
...............................................................................................................................................[1]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
(g) Line 18 in the design shows which new card is dealt each time.
When an Ace, Jack, Queen or King is dealt, the output displays the number for that card, not
the name of the card.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
A function, ValidatePassword, is needed to check that a given password follows these rules.
This function takes a string, Pass, as a parameter and returns a Boolean value:
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................[10]
Give a valid string to check that the function returns TRUE under the correct conditions.
String1: ..............................................................................................................................
Modify the valid string given for String1 to test each rule separately.
String2: ..............................................................................................................................
Explanation: ......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
String3: ..............................................................................................................................
Explanation: ......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
String4: ..............................................................................................................................
Explanation: ......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
String5: ..............................................................................................................................
Explanation: ......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[5]
(ii) When testing a module, it is necessary to test all possible paths through the code.
.......................................................................................................................................[1]
(iii) A program consisting of several modules may be tested using a process known as
stub testing.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
Appendix
Built-in functions (pseudocode)
In each function, if the function call is not properly formed, the function returns an error.
returns the character value representing the lower case equivalent of ThisChar.
If ThisChar is not an upper-case alphabetic character then it is returned unchanged.
Example: LCASE('W') returns 'w'
returns the integer value representing the remainder when ThisNum is divided by ThisDiv.
Example: MOD(10,3) returns 1
returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv.
Example: DIV(10,3) returns 3
Operators (pseudocode)
Operator Description
Concatenates (joins) two strings.
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND of two Boolean values.
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR of two Boolean values.
OR
Example: TRUE OR FALSE produces TRUE
BLANK PAGE
1 (a) (i) Procedural high-level languages usually support different data types.
Give an appropriate data type for each data value in the following table.
(ii) State an appropriate data structure to store the individual test scores for a class of
students.
.......................................................................................................................................[1]
(iii) Describe how characters are represented using the ASCII character set.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
Explain why you should use subroutines when designing a program solution.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
IF MyVar = 1
THEN
CALL Proc1()
ELSE
IF MyVar = 2
THEN
CALL Proc2()
ELSE
IF MyVar = 3
THEN
CALL Proc3()
ELSE
OUTPUT "Error"
ENDIF
ENDIF
ENDIF
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
You are given program code written in a high-level language that you have not studied.
State two different features of the code that you should be able to recognise.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
1 (a) (i) Procedural high-level languages usually support different data types.
Give an appropriate data type for each data value in the following table:
03/03/2013
35
"INTEGER"
3.5
"35"
[6]
...................................................................................................................................... [1]
State two features of the code that the programmer should be able to recognise.
1 .......................................................................................................................................
...........................................................................................................................................
2 .......................................................................................................................................
...........................................................................................................................................
[2]
(b) (i) In the ASCII character set ‘A’ is represented by the value 65. The values representing the
other characters of the alphabet follow in sequence, so ‘B’ is represented by 66, ‘C’ by 67
and so on.
The following table represents consecutive memory locations. Each memory location
stores one byte.
Complete the table to show how the string "CAGE" may be stored in memory using the
ASCII set.
Address Data
100
101
102
103
104
105
[2]
(ii) In a high-level language, a LENGTH function is used to return the number of characters in
a string.
Explain what is stored in addition to the string characters to allow this function to
determine this number.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
CASE OF MyMark
75 to 100: MyGrade "Distinction"
35 to 74: MyGrade "Pass"
0 to 34: MyGrade "Fail"
OTHERWISE: OUTPUT "Invalid value entered"
ENDCASE
(i) Describe what will happen if the pseudocode is tested when MyMark has the following
values:
27 ......................................................................................................................................
...........................................................................................................................................
101 ....................................................................................................................................
...........................................................................................................................................
[2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [5]
Repetition
Statement Assignment Selection
(Iteration)
CASE OF TempSensor1
ELSE
REPEAT
ENDFOR
DayNumber DayNumber + 1
Error TRUE
[6]
Give the most appropriate data type for the variable used in each statement.
Complete the table by evaluating each expression using the values from part (b)(i).
For the built-in functions list, refer to the Appendix on page 16.
Expression Evaluates to
"Month: " & MID(ModelRef, 5, 3)
INT(MinValue * 2)
ASC(Revision)
Revision > 500
ServiceDue = TRUE OR FuelType = 'P'
[5]
6 Account information for users of a library is held in one of two text files; UserListAtoM.txt and
UserListNtoZ.txt
The format of the data held in the two files is identical. Each line of the file is stored as a string that
contains an account number, name and telephone number separated by the asterisk character
('*') as follows:
"GB1234*Kevin Mapunga*07789123456"
The account number string may be six or nine characters in length and is unique for each
person. It is made up of alphabetic and numeric characters only.
An error has occurred and the same account number has been given to different users in the two
files. There is no duplication of account numbers within each individual file.
A program is to be written to search the two files and to identify duplicate entries. The account
number of any duplicate found is to be written to an array, Duplicates, which is a 1D array of
100 elements of data type STRING.
The program is to be implemented as several modules. The outline description of three of these is
as follows:
ClearArray()
• Initialise the global array Duplicates. Set all elements to the
empty string.
• Read each line from the file UserListAtoM.txt
• Check whether the account number appears in file
UserListNtoZ.txt using SearchFileNtoZ()
FindDuplicates() • If the account number does appear then add the account
number to the array.
• Output an error message and exit the module if there are more
duplicates than can be written to the array.
• Search for a given account number in file UserListNtoZ.txt
SearchFileNtoZ()
• If found, return TRUE, otherwise return FALSE
(a) State one reason for storing data in a file rather than in an array.
...................................................................................................................................................
............................................................................................................................................. [1]
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2019 9608/21/O/N/19 [Turn over
14
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
(d) ClearArray() is to be modified to make it general purpose. It will be used to initialise any
1D array of data type STRING to any value.
1. The array
2. The number of elements
3. The initialisation string
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(ii) Write program code for a statement that calls the modified ClearArray() procedure
to clear the array Duplicates to "Empty".
Program code
...........................................................................................................................................
...........................................................................................................................................
[2]
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
Operators (pseudocode)
Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
BLANK PAGE
BLANK PAGE
4 The following pseudocode algorithm checks whether a string is a valid email address.
NumDots 0
NumAts 0
NumOthers 0
ENDFOR
ENDFUNCTION
(a) Describe the validation rules that are implemented by this pseudocode. Refer only to the
contents of the string and not to features of the pseudocode.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) (i) Complete the trace table by dry running the function when it is called as follows:
Result Check("Jim.99@skail.com")
[5]
(ii) State the value returned when function Check is called as shown in part (b)(i).
..................................................................................................................................... [1]
State two different invalid string values that could be used to test the algorithm. Each string
should test a different rule.
Value .........................................................................................................................................
Justification ...............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Value .........................................................................................................................................
Justification ...............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
5 Abbreviations are often used in place of a full name. Concatenating the first letter of each word in
the name makes an abbreviation.
For example:
Name Abbreviation
United Nations UN
A function, Abbreviate(), will take a string representing the full name and return a string
containing the abbreviated form.