Trace Table Questions
Trace Table Questions
B
IF NextChar <> Space
THEN
NewString NewString & NextChar
ENDIF
ELSE
AfterSpace FALSE
AI
H
NewString NewString & NextChar
IF NextChar = Space
THEN
ZO
AfterSpace TRUE
ENDIF
ENDIF
ENDFOR
RETURN NewString
S
ENDFUNCTION
C
Page 1 of 13
9
(a) (i) Complete the trace table by performing a dry run of the function when it is called as
follows:
Result Clean("X∇∇∇Y∇and∇∇Z")
The symbol '∇' represents a space character. Use this symbol to represent a space
character in the trace table.
B
AI
H
ZO
S
C
[6]
...........................................................................................................................................
..................................................................................................................................... [1]
(iii) The pseudocode is changed so that the variable AfterSpace is initialised to TRUE.
Result Clean("∇∇X∇∇∇Y∇and∇∇Z")
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
B
FOR Index 1 TO 100
Code[Index] ""
ENDFOR
•
AI
H
the array needs to be two dimensional, with 500 rows and 4 columns
• the elements of the array need to be initialised to the string "Empty"
ZO
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
S
...................................................................................................................................................
C
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(c) State the term used for changes that are made to a program in response to a specification
change.
............................................................................................................................................. [1]
Page 3 of 13
8
For the built-in functions list, refer to the Appendix on page 16.
NewString '0'
Selected 0
B
THEN
NewValue STRING_TO_NUM(NewString)
IF NewValue > Selected
THEN
ENDIF
Selected NewValue AI
H
NewString '0'
ELSE
NewString NewString & NextChar
ZO
ENDIF
ENDFOR
RETURN Selected
ENDFUNCTION
S
C
Page 4 of 13
9
Result Search("12∇34∇5∇∇39")
Complete the following trace table by performing a dry run of this function call.
The symbol '∇' represents a space character. Use this symbol to represent a space
character in the trace table.
B
AI
H
ZO
S
C
[5]
(ii) State the value returned by the function when it is called as shown in part (a)(i).
....................................... [1]
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
B
19 NumLower 0
20 NumNonAlpha 0
21
22
23
24
StrLen LENGTH(InString)
IF StrLen < 7
THEN
AI
H
25 RETURN FALSE
26 ELSE
27 FOR Index 1 TO StrLen
ZO
35 NumUpper NumUpper + 1
36 ELSE
C
37 NumNonAlpha NumNonAlpha + 1
38 ENDIF
39 ENDIF
40 ENDFOR
41 ENDIF
42
43 IF (NumUpper >= 1) AND (NumLower >= 1) AND (NumNonAlpha >= 1)
44 THEN
45 RETURN TRUE
46 ELSE
47 RETURN FALSE
48 ENDIF
49
50 ENDFUNCTION
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
Page 6 of 13
5
A dry run performed on the function Check(), with the string "crAsh99", produced the
following trace table.
The string is a valid password, but the pseudocode would return the value FALSE.
Trace
StrLen Index NextChar NumUpper NumLower NumNonAlpha
table row
1 7 0 0 0
2 1 'c'
3 1
4 2 'r'
5 2
6 3 'A'
7 1
B
8 4 's'
9 3
10
11
5 'h' AI 4
H
12 6 '9'
13 2
ZO
14 7 '9'
15 3
(i) Describe how the completed trace table may be used to identify the error in the
pseudocode. In your answer, refer to the trace table row number(s).
S
...........................................................................................................................................
C
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) State the pseudocode line number that has to be changed to correct the error and write
the correct pseudocode for the complete line.
...........................................................................................................................................
[2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
B
AI
H
ZO
S
C
Page 8 of 13
8
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
B
19 NumDigit 0
20
21 StrLen LENGTH(InString)
22
23
24
IF StrLen < 6
THEN
RETURN FALSE
AI
H
25 ELSE
26 FOR Index 1 TO StrLen - 1
27 // loop for each character
ZO
37 ENDIF
38 ENDFOR
39 ENDIF
40
41 NumOther StrLen – (NumDigit – NumUpper)
42 IF NumDigit >= 1 AND NumUpper >= 1 AND NumOther >= 1
43 THEN
44 RETURN TRUE
45 ELSE
46 RETURN FALSE
47 ENDIF
48
49 ENDFUNCTION
Page 9 of 13
9
The function was dry run with the string "1234AP" and the following trace table was
produced. The string is an invalid password, but the pseudocode returned the value
TRUE.
Trace
StrLen Index NextChar NumUpper NumDigit NumOther
table row
1 6 0 0
2 1 '1'
3 1
4 2 '2'
5 2
6 3 '3'
7 3
B
8 4 '4'
9
10
11
5 'A' AI 1
4
H
12 3
ZO
State how the given trace table indicates the existence of each error.
Error 1 ...............................................................................................................................
S
...........................................................................................................................................
...........................................................................................................................................
C
...........................................................................................................................................
Error 2 ...............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
(ii) Give the line number of each error in the pseudocode algorithm and write the modified
pseudocode to correct each error.
...........................................................................................................................................
...........................................................................................................................................
[2]
(c) The term adaptive maintenance refers to amendments that are made in response to
changes to the program specification. These changes usually affect the program algorithm.
B
Name one other part of the design that can change as a result of adaptive maintenance.
............................................................................................................................................. [1]
AI
H
ZO
S
C
Page 11 of 13
10
4 Study the following pseudocode. Line numbers are for reference only.
B
27 IF ThisChar <> SPACECHAR THEN
28 Flag FALSE
29 ENDIF
30
31
32
ELSE
NewName
ENDIF
NewName & ThisChar AI
H
33 IF ThisChar = SPACECHAR THEN
34 Flag TRUE
35 ENDIF
ZO
36 Index Index + 1
37 ENDWHILE
38
39 RETURN NewName
40
41 ENDFUNCTION
S
C
Page 12 of 13
11
(a) Complete the trace table below by dry running the function when it is called as follows:
Result Convert("∇in∇a∇∇Cup")
Note: The symbol '∇' has been used to represent a space character.
Use this symbol for any space characters in the trace table.
"∇in∇a∇∇Cup"
B
AI
H
ZO
S
C
[5]