Algorithm:Data Structure QP
Algorithm:Data Structure QP
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]
(b) The programmer writes a program from the following pseudocode design.
x 0
FOR DayNumber 1 TO 7
IF SalesX[DayNumber] + SalesY[DayNumber] >= 10
THEN
x x + 1
OUTPUT SalesDate[DayNumber]
ENDIF
ENDFOR
OUTPUT x
(i) Trace the execution of this pseudocode by completing the trace table below.
x DayNumber OUTPUT
0
[4]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
(c) The company wants a program to output the total monthly sales for one of the selected
websites.
The function returns the total number of bicycles sold for the given month and website.
MonthlyWebSiteSales(1, "Y")
MonthlyWebSiteSales(12, 'X')
[3]
(d) The company decides to offer a discount on selected dates. A program is written to indicate
the dates on which a discount is offered.
The program creates a text file, DISCOUNT_DATES (with data as shown), for a number of
consecutive dates.
03/06/2015 TRUE
04/06/2015 FALSE
05/06/2015 FALSE
06/06/2015 FALSE
07/06/2015 FALSE
08/06/2015 FALSE
09/06/2015 FALSE
10/06/2015 TRUE
11/06/2015 FALSE
01/07/2015 FALSE
The use of the square brackets indicates that the parameter is optional.
INPUT ......................................................................................................................................
INPUT Discount
INPUT NextDate
...................................................................................................................................................
CLOSEFILE [4]
(i) Add to the identifier table to show the variables you need for this new program.
[3]
Do not include any declaration or comment statements for the variables used.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[7]
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]
(b) Complete the trace table for the pseudocode algorithm below.
FOR WorkerNum 1 TO 3
WorkerTotal[WorkerNum] 0
ENDFOR
FOR WorkerNum 1 TO 3
FOR DayNum 1 TO 4
WorkerTotal[WorkerNum] WorkerTotal[WorkerNum] +
ProductionData[DayNum, WorkerNum]
ENDFOR
ENDFOR
FOR WorkerNum 1 TO 3
WorkerAverage WorkerTotal[WorkerNum]/
(4 * DailyHoursWorked[WorkerNum])
IF WorkerAverage < 2
THEN
OUTPUT “Investigate“, WorkerNum
ENDIF
ENDFOR
WorkerTotal
WorkerNum DayNum WorkerAverage OUTPUT 1 2 3
[8]
(c) An experienced programmer suggests that the pseudocode would be best implemented as a
procedure AnalyseProductionData.
Assume that both arrays, DailyHoursWorked and ProductionData, are available to the
procedure from the main program and they are of the appropriate size.
DECLARE ........................................................................................................................................
DECLARE ...................................................................................................................................... .
DECLARE ....................................................................................................................................... .
DECLARE ...................................................................................................................................... .
FOR WorkerNum 1 TO 3
WorkerTotal[WorkerNum] 0
ENDFOR
FOR WorkerNum 1 TO 3
FOR DayNum 1 TO 4
WorkerTotal[WorkerNum] WorkerTotal[WorkerNum] +
ProductionData[DayNum, WorkerNum]
ENDFOR
ENDFOR
FOR WorkerNum 1 TO 3
WorkerAverage WorkerTotal[WorkerNum]/
(4 * DailyHoursWorked [WorkerNum])
IF WorkerAverage < 2
THEN
OUTPUT "Investigate", WorkerNum
ENDIF
ENDFOR
ENDPROCEDURE
(i) Complete the declaration statements showing the local variables. [4]
(ii) The original pseudocode has been ‘pasted’ under the procedure header.
Circle all the places in the original pseudocode where changes will need to be made.
Write the changes which need to be made next to each circle. [3]
(iii) Write the statement for a procedure call which processes data for 7 days for 13 workers.
.......................................................................................................................................[1]
BLANK PAGE
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will
be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
The integers are stored in an array, Num. The first N elements are to be processed.
FOR i ←1 TO (N - 1)
j ←
1
REPEAT
IF Num[j] > Num[j + 1]
THEN
Temp ←
Num[j]
Num[j] ←
Num[j + 1]
Num[j + 1] Temp ←
ENDIF
j ←
j + 1
UNTIL j = (N – i + 1)
ENDFOR
(a) (i) Trace the execution of the pseudocode for the value N = 5 and the given array of integers.
Num
N i j Temp 1 2 3 4 5
5 11 16 13 7 8
[8]
...........................................................................................................................................
.......................................................................................................................................[1]
(iii) Describe what evidence from the trace table suggests that the given pseudocode is
inefficient.
...........................................................................................................................................
.......................................................................................................................................[1]
(b) Complete the identifier table documenting the use of each of the variables.
Temp
[5]
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
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will
be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
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
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will
be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
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]
Appendix
In each function below, if the function call is not properly formed, the function returns an error.
MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will
be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
Write the equivalent pseudocode using a pre-condition loop, for this part of the amended
flowchart.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
2 You will need to refer to the list of pseudocode string-handling functions in the Appendix.
(a) Give the value of the variables x, y and z for the following sequence of statements.
y ............................ [1]
A computer program is to simulate the reading and processing of a string of characters from an
input device.
13*156*9*86*1463*18*#
(i) A statement which declares a global variable used to store a single character. ........... [1]
(iii) A statement which indicates the start of a ‘pre-condition’ loop. ........... [1]
(c) Copy the condition which is used to control the inner loop.
.............................................................................................................................................. [1]
© UCLES 2016 9608/22/O/N/16
7
(d) (i) Complete the trace table below for the given pseudocode as far as line 27.
Numbers
i j NextChar NextNumberString
1 2 3
1 1 '2'
""
"2"
2 '3' "23"
3 '*' 23
[5]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
© UCLES 2016 9608/22/O/N/16 [Turn over
QUESTION 15. 4
INPUT StartNumber
INPUT EndNumber
INPUT Divisor
NumberFound 0
For the built-in functions list, refer to the Appendix on page 14.
[3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
[10]
3 (a) State why a high-level language program must be translated before it can be run.
...................................................................................................................................................
...............................................................................................................................................[1]
(b) A program runs but does not give the expected output.
Method 1 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Method 2 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
(c) Two testing methods are black-box and white-box. A student is choosing test data for both
methods.
Tick one or more boxes in each row to identify the testing method each statement describes.
The student chooses data to test that the program meets the
specification.
[4]
2 Shop customers have a discount card with a unique card number. Customers collect points each
time they buy items. The number of points they collect depends on:
The function CalcPoints() takes the card number and the total amount spent as parameters. It
returns the number of new points collected. A flowchart for the function is shown.
START
Is YES
Total > 100 ?
OldPoints
NO GetPoints(CardNum)
Is NO
OldPoints > 2000 ?
YES
RETURN NewPoints
END
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[7]
(ii) The value of the total amount spent is calculated by an Electronic Point Of Sale (EPOS)
system. This system does not have the prices of all items. For these items, a valid total
amount has to be entered manually.
If the user enters a valid value greater than 0 and less than 10 000, the function returns
the value. The function prompts the user to re-enter the value each time the user enters
an invalid value.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
ENDFUNCTION
[5]
(b) The function CalcPoints() is written in a high-level language. It has been checked and it
does not contain any syntax or logic errors.
(i) Name and describe one other type of error that the high-level language code could
contain.
Name .................................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
State two different values of Total that could be used to test different paths through the
algorithm. Justify your choices.
Value .................................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Value .................................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
2 Shop customers have a discount card with a unique card number. Customers collect points when
they buy items. At the end of each year, customers are given bonus (extra) points related to the
total amount they have spent during the year, and the number of points they have on their card.
The function CalcBonus() takes the card number as a parameter. It returns the bonus points for
the customer. A flowchart for the function is shown.
START
Points
GetPoints(CardNum)
Spend
GetSpend(CardNum)
Is YES
Points > 2000 ?
NO
Is YES
Spend > 1000 ?
NO
RETURN Bonus
END
Your solution should follow the flowchart for the function as closely as possible.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[5]
(ii) The function GetCardNumber() prompts the user to input a card number until the
number input is valid.
A valid card number has 16 characters. Each character is a numeric character ('0' to
'9').
You should refer to the function IS_NUM() in the Appendix on page 16.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
ENDFUNCTION
[6]
© UCLES 2018 9608/23/O/N/18
7
(i) The function is tested using black-box testing and does not contain any syntax errors.
Name and describe one other type of error that black-box testing could find.
Name .................................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
State two different pairs of values for Spend and Points that can be used to test
different paths through the function. Justify your choices.
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
(c) Name two types of program maintenance and state the reason why each is needed.
Name ........................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Name ........................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
For the built-in functions list, refer to the Appendix on page 16.
AfterSpace FALSE
NewString ""
RETURN NewString
ENDFUNCTION
(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.
[6]
...........................................................................................................................................
..................................................................................................................................... [1]
(iii) The pseudocode is changed so that the variable AfterSpace is initialised to TRUE.
Result Clean("∇∇X∇∇∇Y∇and∇∇Z")
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
• 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"
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(c) State the term used for changes that are made to a program in response to a specification
change.
............................................................................................................................................. [1]
For the built-in functions list, refer to the Appendix on page 16.
NewString '0'
Selected 0
ENDFOR
RETURN Selected
ENDFUNCTION
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.
[5]
(ii) State the value returned by the function when it is called as shown in part (a)(i).
....................................... [1]
(b) There is an error in the algorithm. When called as shown in part (a)(i), the function did not
return the largest value as expected.
(i) Explain why this error occurred when the program called the function.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Describe how the algorithm could be amended to correct the error.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
5 A student is learning about text files. She wants to write a program to count the number of lines in
a file.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
5 Nigel is learning about string handling. He wants to write code to count the number of words in a
given string. A word is defined as a sequence of alphabetic characters that is separated by one or
more space characters.
NumWords 0
ENDPROCEDURE
For the built-in functions list, refer to the Appendix on page 18.
His first attempt is incorrect. He will use white-box testing to help him to identify the problem.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Dry running the code is often used in white-box testing. In this method, the programmer
records the values of variables as they change.
Identify what the programmer would normally use to record the changes.
..................................................................................................................................... [1]
(b) (i) Write a test string containing two words that gives the output:
Number of words : 2
Use the symbol '∇' to represent each space character in your test string.
String .................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[3]
String 1: "Red∇and∇Yellow"
String 2: "Green∇∇and∇∇Pink∇"
Describe the changes that would need to be made to the algorithm to give the correct
output in each case.
String 1 ..............................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
String 2 ..............................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[6]
Upper 0
Lower 0
Digit 0
Other 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]
© UCLES 2019 9608/21/O/N/19
11
(b) (i) Complete the trace table by dry running the function when it is called as follows:
Result CheckPassword("Jim+Smith*99")
[5]
(ii) State the value returned when the function is called using the expression shown. Justify
your answer.
Value .................................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
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("[email protected]")
[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.