11.1 Programming Basics
AS Level · 13 questions found
What this topic covers
Section titled “What this topic covers”- Implement pseudocode from a flowchart or structured English
- Declare/initialise constants and variables; assign values
- Arithmetic and logical expressions; keyboard input and console output
- Use built-in functions and library routines; string manipulation
Past paper questions
Section titled “Past paper questions” Q1


1
An algorithm is developed in pseudocode before being coded in a programming language.
(a) The following table shows four valid pseudocode assignment statements.
Complete the table by giving an appropriate data type to declare each of the variables A, B, C
and D.
Assignment statement
Data type
A
LEFT(MyName, 1)
B
Total * 2
C
INT(ItemCost) / 3
D
"Odd OR Even"
[4]
(b) Other variables in the program have example values as shown:
Variable
Value
Sorted
False
Tries
9
ID
"ZGAC001"
Complete the table by evaluating each expression, using the example values.
Expression
Evaluates to
Tries < 10 AND NOT Sorted
Tries MOD 4
TO_LOWER(MID(ID, 3, 1))
LENGTH(ID & "xx") >= Tries
[4]
(c) The variable names A, B, C and D in part (a) are not good programming practice.
(i) State why these variable names are not suitable.
..................................................................................................................................... [1]
(ii) Identify one problem that these variable names might cause.
..................................................................................................................................... [1]
(iii) The choice of suitable variable names is one example of good programming practice.
Give one other example.
..................................................................................................................................... [1]
Show mark scheme
1(a) [4 marks]
Assignment statement
Data type
CHAR / STRING
A
LEFT(MyName, 1)
INTEGER / REAL
B
Total * 2
REAL
C
INT(ItemCost) / 3
STRING
D
"Odd OR Even"
One mark per row
Data type
CHAR / STRING
A
LEFT(MyName, 1)
INTEGER / REAL
B
Total * 2
REAL
C
INT(ItemCost) / 3
STRING
D
"Odd OR Even"
One mark per row
1(b)
Expression
Evaluates to
Tries < 10 AND NOT Sorted
TRUE
Tries MOD 4
1
TO_LOWER(MID(ID, 3, 1))
'a' // "a"
LENGTH(ID & "xx") >= Tries
TRUE
One mark per row
Evaluates to
Tries < 10 AND NOT Sorted
TRUE
Tries MOD 4
1
TO_LOWER(MID(ID, 3, 1))
'a' // "a"
LENGTH(ID & "xx") >= Tries
TRUE
One mark per row
1(c)(i) [1 mark]
The names do not reflect / indicate the purpose of the variable // the names
are not meaningful
are not meaningful
1(c)(ii) [1 mark]
They make the program more difficult to understand / debug / maintain
1(c)(iii)
One mark from:
Indentation / use of white space
Capitalisation of keywords
Use of comments
Use of modular programming
Use of local variables
Note: max 1 mark
Indentation / use of white space
Capitalisation of keywords
Use of comments
Use of modular programming
Use of local variables
Note: max 1 mark
Q5


5
A global 1D array of strings contains three elements which are assigned values as shown:
Data[1]
"aaaaaa"
Data[2]
"bbbbbb"
Data[3]
"cccccc"
Procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Format : STRING)
DECLARE Count, Index, L : INTEGER
DECLARE Result : STRING
DECLARE C : CHAR
Result
"****"
FOR Count
1 TO LENGTH(Format) STEP 2
C
MID(Format, Count, 1)
L
STR_TO_NUM(MID(Format, Count + 1, 1))
Index
(Count + 1) DIV 2
CASE OF C
'X' : Result
TO_UPPER(Data[Index])
'Y' : Result
TO_LOWER(Data[Index])
'Z' : Result
"**" & Data[Index]
ENDCASE
Data[Index]
LEFT(Result, L)
NEXT Count
ENDPROCEDURE
(a) Complete the trace table by dry running the procedure when it is called as follows:
CALL Process("X3Y2W4")
Count
C
L
Index
Result
Data[1]
Data[2]
Data[3]
[6]
(b) The procedure is to be modified. If variable C is assigned a value other than 'X', 'Y' or 'Z',
then procedure Error() is called and passed the value of variable C as a parameter.
This modification can be implemented by adding a single line of pseudocode.
(i) Write the single line of pseudocode.
..................................................................................................................................... [1]
(ii) State where this new line should be placed.
..................................................................................................................................... [1]
Show mark scheme
5(a) [6 marks]
One mark per zone.
OTHERWISE : CALL Error(C)
OTHERWISE : CALL Error(C)
5(b)(ii) [6 marks]
After the '
' clause in the
construct // before the
Z
CASE
ENDCASE
FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS
' clause in the
construct // before the
Z
CASE
ENDCASE
FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS
Q6
6
Three points on a grid form a triangle with sides of length A, B and C as shown in the example:
y
Show mark scheme
6(a)
BOOLEAN
DECLARE Len1, Len2, Len3 : INTEGER
Len1
(x1 - x2) ^ 2 + (y1 - y2) ^ 2
Len2
(x1 - x3) ^ 2 + (y1 - y3) ^ 2
Len3
(x2 - x3) ^ 2 + (y2 - y3) ^ 2
IF (Len1 = Len2 + Len3) OR__
(Len2 = Len1 + Len3) OR__
(Len3 = Len1 + Len2) THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
Mark as follows:
1
Calculate the square of the length of at least one side
2
Calculation of all three lengths squared correctly
3
One
correct comparison of square of three lengths
4
All three
comparisons…
5
combined using logical operators / nested
// completely correct
IF
selection
6
Return result correctly in both cases
DECLARE Len1, Len2, Len3 : INTEGER
Len1
(x1 - x2) ^ 2 + (y1 - y2) ^ 2
Len2
(x1 - x3) ^ 2 + (y1 - y3) ^ 2
Len3
(x2 - x3) ^ 2 + (y2 - y3) ^ 2
IF (Len1 = Len2 + Len3) OR__
(Len2 = Len1 + Len3) OR__
(Len3 = Len1 + Len2) THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
Mark as follows:
1
Calculate the square of the length of at least one side
2
Calculation of all three lengths squared correctly
3
One
correct comparison of square of three lengths
4
All three
comparisons…
5
combined using logical operators / nested
// completely correct
IF
selection
6
Return result correctly in both cases
6(b) [2 marks]
1 mark for statement of problem:
Problem:
The function will return an incorrect value // the test will fail
1 mark for solution:
Solution:
Round the calculated values (to a known number of decimal places)
Define a threshold below which any difference can be ignored
Problem:
The function will return an incorrect value // the test will fail
1 mark for solution:
Solution:
Round the calculated values (to a known number of decimal places)
Define a threshold below which any difference can be ignored
Q7












x
7
6
5
4
1
0
2
3
4
5
6
7
8
9 10
A
C
B
3
2
1
A triangle is said to be right-angled if the following test is true (where A is the length of the longest
side):
A2 = B2 + C2
A2 means A multiplied by A, for example 32 means 3 × 3 which evaluates to 9
You can calculate A2, B2 and C2 by using the coordinates of the endpoints of each line.
For example, B2 is calculated as follows:
10
y
x
9
8
7
6
5
4
1
0
2
3
4
5
6
7
8
9 10
B
P2
P2
P1
P1
3
2
1
(x1, y1)
(x1, y1)
(x2, y2)
(x2, y2)
The endpoints, P1 and P2, have the coordinates (3, 2) and (6, 6).
The value B2 is given by the formula:
B2 = (x1 − x2)2 + (y1 − y2)2
In this example:
B2 = (3 − 6)2 + (2 − 6)2
B2 = (–3)2 + (–4)2
B2 = 9 + 16
B2 = 25
(a) A function IsRA() will:
•
take three sets of integers as parameters representing the coordinates of the three
endpoints that form a triangle
•
return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE.
In pseudocode, the operator ‘^’ represents an exponent, which is the number of times a value
is multiplied by itself. For example, the expression Value2 may be written in pseudocode as
Value ^ 2
Complete the pseudocode for the function IsRA().
FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN
ENDFUNCTION
[6]
(b) The test used to check if a triangle is right-angled can be written in two ways:
A2 = B2 + C2
or
A = √(B2 + C2)
The symbol √ represents the square root operation. For example, √81 = 9
A new function SQRT() is written to perform the square root operation. The function takes an
integer number as a parameter and returns a positive real value representing the square root
of the number.
During testing it is found that the SQRT() function returns a value that is only accurate to
4 decimal places.
For example, SQRT(25) returns 5.0000125 rather than the correct value of 5.0
The function IsRA() from part (a) is modified to use the new SQRT() function to test if a
triangle is right-angled.
Describe a problem that might occur when using the modified IsRA() function and suggest
a solution that still allows the SQRT() function to be used.
Problem ....................................................................................................................................
Solution .....................................................................................................................................
[2]
BLANK PAGE
7
A fitness club has a computerised membership system. The fitness club offers a number of
different exercise classes.
The following information is stored for each club member: name, home address, email address,
mobile phone number, date of birth and the exercise(s) they are interested in.
(a) When an exercise class is planned, a new module will send personalised text messages to
each member who has expressed an interest in that exercise. Members wishing to join the
class send a text message back. Members may decide not to receive future text messages
by replying with the message ‘STOP’.
The process of abstraction is used to filter out unnecessary information.
(i) State one advantage of applying abstraction to this problem.
..................................................................................................................................... [1]
(ii) Identify three items of information that will be required by the new module.
Justify your choices with reference to the given scenario.
Item 1 required ..................................................................................................................
Justification .......................................................................................................................
Item 2 required ..................................................................................................................
Justification .......................................................................................................................
Item 3 required ..................................................................................................................
Justification .......................................................................................................................
[3]
(iii) Identify two operations that would be required to process data when the new module
receives a text message back from a member.
Operation 1 .......................................................................................................................
Operation 2 .......................................................................................................................
[2]
(b) The structure chart illustrates part of the membership program:
Sub-A
Sub-B
P1
T1
P2
Name
Update
Sub-C
A
Data item notes:
•
Name contains the name of a club member
•
P1 and T1 are of type real.
(i) Explain the meaning of the diamond symbol (labelled with the letter A) in the chart.
..................................................................................................................................... [2]
(ii) Write the pseudocode module headers for Sub-A and Sub-B.
Sub-A
Sub-B
[4]
8
A teacher is designing a program to process pseudocode projects written by her students.
Each student project is stored in a text file.
The process is split into a number of stages. Each stage performs a different task and creates a
new file named as shown:
File name
Comment
MichaelAday_src.txt
student project file produced by student Michael Aday
MichaelAday_S1.txt
file produced by stage 1
MichaelAday_S2.txt
file produced by stage 2
The teacher has defined the first program module as follows:
Module
Description
DeleteComment()
• called with a parameter of type string representing a line of
pseudocode from a student’s project file
• returns the line after removing any comments
Note on comments:
A comment starts with two forward slash characters and includes all the
remaining characters on the line.
The following example shows a string before and after the comment has
been removed:
Before: IF X2 > 13 THEN //check if limit exceeded
After: IF X2 > 13 THEN
(a) Complete the pseudocode for module DeleteComment().
FUNCTION DeleteComment(Line : STRING) RETURNS STRING
ENDFUNCTION
[8]
(b) A second module is defined:
Module
Description
Stage_1()
• called with a parameter of type string representing a student name
• creates a new stage 1 file
• copies each line from the student’s project file to the stage 1 file after
removing any comment from each line
• does not write blank lines to the stage 1 file
• returns the number of lines written to the stage 1 file
Write pseudocode for module Stage_1().
Module DeleteComment() must be used in your solution.
............................................................................................................................................. [7]
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
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
BLANK PAGE
Show mark scheme
7(a)(i) [3 marks]
To make the solution easier to design / implement / solve
7(a)(ii)
One mark per item
and
justification
Item: mobile phone number
Justification: to send the text message
Item: name
Justification: to personalise the text message
Item: exercise interest
Justification: to determine whether this member would be interested
and
justification
Item: mobile phone number
Justification: to send the text message
Item: name
Justification: to personalise the text message
Item: exercise interest
Justification: to determine whether this member would be interested
7(a)(iii) [2 marks]
Examples include:
Add a member to a list of those interested in the new class
Remove the member from future SMS messages
Read/process Message
Identify who from
One mark for each.
Max 2 marks
Add a member to a list of those interested in the new class
Remove the member from future SMS messages
Read/process Message
Identify who from
One mark for each.
Max 2 marks
7(b)(i) [4 marks]
Means that
calls (one of) either
or
Update
Sub-A, Sub-B
Sub-C
One mark for each point:
reference to selection / decision / if
naming all four modules correctly
PROCEDURE Sub-A (Name : STRING, BYREF P2 : BOOLEAN)
calls (one of) either
or
Update
Sub-A, Sub-B
Sub-C
One mark for each point:
reference to selection / decision / if
naming all four modules correctly
PROCEDURE Sub-A (Name : STRING, BYREF P2 : BOOLEAN)
7(b)(ii) [8 marks]
FUNCTION Sub-B (P1 : REAL) RETURNS REAL
One mark per underlined part in each case
FUNCTION DeleteComment(Line : STRING) RETURNS STRING
One mark per underlined part in each case
FUNCTION DeleteComment(Line : STRING) RETURNS STRING
Q9
9
Q10
10
Q2



2
A program is being developed.
(a) An algorithm for part of the program will:
•
input three numeric values and assign them to identifiers Num1, Num2 and Num3
•
assign the largest value to variable Ans
•
output a message giving the largest value and the average of the three numeric values.
Assume the values are all different and are input in no particular order.
Complete the program flowchart on page 5 to represent the algorithm.
START
END
INPUT Numl, Num2, Num3
Yes
No
[5]
(b) A different part of the program contains an algorithm represented by the following program
flowchart:
START
END
Set Flag to GetStat()
Set Port to 1
Is Flag =
TRUE ?
Is Port = 4 ?
Yes
No
No
Yes
CALL Reset(Port)
Set Port to Port + 1
Write pseudocode for the algorithm.
............................................................................................................................................. [5]
Show mark scheme
2(a) [5 marks]
Mark points
1
Condition for selecting one of the input numbers as largest value
2
… and assign to
Ans
3
Condition for selecting largest number for all three number input and
assigning to
Ans
4
Average calculated using
,
and
and stored in a variable.
Num1
Num2
Num3
Reject use of DIV
5
Output of
and average in output symbol / parallelogram
Ans
1
Condition for selecting one of the input numbers as largest value
2
… and assign to
Ans
3
Condition for selecting largest number for all three number input and
assigning to
Ans
4
Average calculated using
,
and
and stored in a variable.
Num1
Num2
Num3
Reject use of DIV
5
Output of
and average in output symbol / parallelogram
Ans
2(b) [4 marks]
Example solutions:
Flag
GetStat()
WHILE Flag <> TRUE
FOR Port
1 TO 3
CALL Reset(Port)
NEXT Port
Flag
GetStat()
ENDWHILE
Alternative:
REPEAT
Flag
GetStat()
IF Flag <> TRUE THEN
FOR Port
1 TO 3
CALL Reset(Port)
NEXT Port
ENDIF
UNTIL Flag = TRUE
One mark per point:
1
(Outer) conditional loop testing
Flag
2
Correct assignment of
from
in a loop
Flag
GetStat()
3
(Inner) loop checking / counting port // Check if
is different to 4
Port
4
… loop for 3 iterations
5
a call to
in a loop
Reset()
Flag
GetStat()
WHILE Flag <> TRUE
FOR Port
1 TO 3
CALL Reset(Port)
NEXT Port
Flag
GetStat()
ENDWHILE
Alternative:
REPEAT
Flag
GetStat()
IF Flag <> TRUE THEN
FOR Port
1 TO 3
CALL Reset(Port)
NEXT Port
ENDIF
UNTIL Flag = TRUE
One mark per point:
1
(Outer) conditional loop testing
Flag
2
Correct assignment of
from
in a loop
Flag
GetStat()
3
(Inner) loop checking / counting port // Check if
is different to 4
Port
4
… loop for 3 iterations
5
a call to
in a loop
Reset()
Q4


4
A triangle has sides of length A, B and C.
C
A
B
In this example, A is the length of the longest side.
This triangle is said to be right‑angled if the following equation is true:
A × A = (B × B) + (C × C)
A procedure will be written to check whether three lengths represent a right‑angled triangle.
The lengths will be input in any sequence.
The procedure IsRA() will:
•
prompt and input three integer values representing the three lengths
•
test whether the three lengths correspond to the sides of a right‑angled triangle
•
output a suitable message.
The length of the longest side may not be the first value input.
Write pseudocode for the procedure IsRA().
.................................................................................................................................................... [5]
Show mark scheme
4
Example solution:
PROCEDURE IsRA()
DECLARE a, b, c : INTEGER
OUTPUT "Input length of the first side"
INPUT a
OUTPUT "Input length of the second side"
INPUT b
OUTPUT "Input length of the third side"
INPUT c
IF (a * a = (b * b) + (c * c)) OR__
(b * b = (a * a) + (c * c)) OR__
(c * c = (a * a) + (b * b)) THEN
OUTPUT "It is right-angled"
ELSE
OUTPUT "Not right-angled"
ENDIF
ENDPROCEDURE
Mark as follows:
1. Procedure heading and ending
and
declaration of all variables used
2. Appropriate prompt and input for each length
3.
One
correct length test
4.
All three
length tests // selection of which test is required
5. Output one of two messages following a reasonable attempt at MP3
PROCEDURE IsRA()
DECLARE a, b, c : INTEGER
OUTPUT "Input length of the first side"
INPUT a
OUTPUT "Input length of the second side"
INPUT b
OUTPUT "Input length of the third side"
INPUT c
IF (a * a = (b * b) + (c * c)) OR__
(b * b = (a * a) + (c * c)) OR__
(c * c = (a * a) + (b * b)) THEN
OUTPUT "It is right-angled"
ELSE
OUTPUT "Not right-angled"
ENDIF
ENDPROCEDURE
Mark as follows:
1. Procedure heading and ending
and
declaration of all variables used
2. Appropriate prompt and input for each length
3.
One
correct length test
4.
All three
length tests // selection of which test is required
5. Output one of two messages following a reasonable attempt at MP3
Q5


5
A program is being designed in pseudocode.
The program contains a global 1D array Data of type string containing 200 elements.
The first element has the index value 1.
A procedure Process() is written to initialise the values in the array:
PROCEDURE Process(Label : STRING)
DECLARE Index : INTEGER
Index
0
INPUT Data[Index]
WHILE Index < 200
Index
Index + 1
CASE OF (Index MOD 2)
0 : Data[Index]
TO_UPPER(Label)
1 : Data[Index]
TO_LOWER(Label)
OTHERWISE : OUTPUT "Alarm 1201"
ENDCASE
NEXT Index
OUTPUT "Completed " & Index & " times"
ENDPROCEDURE
(a) (i) The pseudocode contains two syntax errors and one other error.
Identify the errors.
Syntax error 1 ....................................................................................................................
Syntax error 2 ....................................................................................................................
Other error .........................................................................................................................
[3]
(ii) The procedure contains a statement that is not needed.
Identify the pseudocode statement and explain why it is not needed.
Statement ..........................................................................................................................
Explanation .......................................................................................................................
[2]
(b) After correcting all syntax errors, the pseudocode is translated into program code which
compiles without generating any errors.
When the program is executed it unexpectedly stops responding.
Identify the type of error that has occurred.
............................................................................................................................................. [1]
Show mark scheme
5(a)(i) [2 marks]
One mark per error:
Syntax:
1.
(should be
NEXT Index
ENDWHILE)
2. '&' used to concatenate an integer (in
statement)
OUTPUT
Other:
3.
Accesses element outside range // Accesses element 0
Syntax:
1.
(should be
NEXT Index
ENDWHILE)
2. '&' used to concatenate an integer (in
statement)
OUTPUT
Other:
3.
Accesses element outside range // Accesses element 0
5(a)(ii)
One mark per point:
Statement:
The
statement
OTHERWISE
Explanation:
The result of MOD 2 can only be 0 or 1
Statement:
The
statement
OTHERWISE
Explanation:
The result of MOD 2 can only be 0 or 1
5(b) [7 marks]
Run-time
Q6




6
A music player stores music in a digital form and has a display which shows the track being
played.
(a) Up to 16 characters can be displayed. Track titles longer than 16 characters will need to be
trimmed as follows:
•
Words must be removed from the end of the track title until the resulting title is less than
14 characters.
•
When a word is removed, the space in front of that word is also removed.
•
Three dots are added to the end of the last word displayed when one or more words
have been removed.
The table below shows some examples:
Original title
Display string
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Bat out of Hull
B
a
t
o
u
t
o
f
H
u
l
l
Bohemian Symphony
B
o
h
e
m
i
a
n
.
.
.
Paperbook Writer
P
a
p
e
r
b
o
o
k
W
r
i
t
e
r
Chris Sings the Blues
C
h
r
i
s
S
i
n
g
s
.
.
.
Green Home Alabama
G
r
e
e
n
H
o
m
e
.
.
.
A function Trim() will:
•
take a string representing the original title
•
return the string to be displayed.
Assume:
•
Words in the original title are separated by a single space character.
•
There are no spaces before the first word or after the last word of the original title.
•
The first word of the original title is less than 14 characters.
Write pseudocode for the function Trim().
............................................................................................................................................. [7]
(b) Music is stored as a sequence of digital samples.
Each digital sample is a denary value in the range 0 to 99999999 (8 digits).
The samples are to be stored in a text file. Each sample is converted to a numeric string and
32 samples are concatenated (joined) to form a single line of the text file.
Each numeric string is 8 characters in length; leading ‘0’ characters are added as required.
Example:
Sample
1
2
3
32
Denary value
String
456
48
37652
"00000456"
"00000048"
"00037652"
673
"00000673"
The example samples will be stored in the text file as a single line:
"000004560000004800037652...00000673"
(i) Identify one drawback of adding leading ‘0’ characters to each numeric string.
..................................................................................................................................... [1]
(ii) Suggest an alternative method of storing the samples which does not involve adding
leading ‘0’ characters but which would still allow each individual sample to be extracted.
..................................................................................................................................... [1]
(iii) State one drawback of the alternative method given in part (b)(ii).
..................................................................................................................................... [1]
BLANK PAGE
Show mark scheme
6(a)
Example solution:
Function Trim(Name : STRING) RETURNS STRING
CONSTANT Dots = "..."
CONSTANT Space = " "
IF LENGTH(Name) <= 16 THEN
RETURN Name
ENDIF
// Otherwise it has to be trimmed
WHILE LENGTH(Name) > 13
REPEAT
Name
LEFT(Name, LENGTH(Name) - 1) // strip
last char
UNTIL RIGHT(Name, 1) = Space // back to SPACE
ENDWHILE
Name
LEFT(Name, LENGTH(Name) - 1) // remove the
space
Name
Name & Dots
RETURN Name
ENDFUNCTION
Mark as follows:
1. Function heading, ending, parameter and return type
2. If length of original string <= 16 then return original string
3. Any Conditional loop...
4. until string is short enough
5. Inner conditional loop / second condition to identify word(s) to
remove from the end of string // Check to identify word(s) to remove
from the end of string
6. Attempt to strip characters back to space
7. Correct removal of word/words from end of string
and
remove final
space
8. Concatenate
and return result
Dots
Max 7 marks
Function Trim(Name : STRING) RETURNS STRING
CONSTANT Dots = "..."
CONSTANT Space = " "
IF LENGTH(Name) <= 16 THEN
RETURN Name
ENDIF
// Otherwise it has to be trimmed
WHILE LENGTH(Name) > 13
REPEAT
Name
LEFT(Name, LENGTH(Name) - 1) // strip
last char
UNTIL RIGHT(Name, 1) = Space // back to SPACE
ENDWHILE
Name
LEFT(Name, LENGTH(Name) - 1) // remove the
space
Name
Name & Dots
RETURN Name
ENDFUNCTION
Mark as follows:
1. Function heading, ending, parameter and return type
2. If length of original string <= 16 then return original string
3. Any Conditional loop...
4. until string is short enough
5. Inner conditional loop / second condition to identify word(s) to
remove from the end of string // Check to identify word(s) to remove
from the end of string
6. Attempt to strip characters back to space
7. Correct removal of word/words from end of string
and
remove final
space
8. Concatenate
and return result
Dots
Max 7 marks
6(b)(i) [1 mark]
A (very) large
file
is created // redundant zeroes are stored in the file
file
is created // redundant zeroes are stored in the file
6(b)(ii) [1 mark]
One mark for:
Values are delimited by a special character / a separator character
First character indicates
sample
length
Max 1 mark
Values are delimited by a special character / a separator character
First character indicates
sample
length
Max 1 mark
6(b)(iii) [3 marks]
The
algorithm
to
store / extract / separate
the individual values is more
complex / takes longer to execute / run / process
NE Algorithm is more complicated
algorithm
to
store / extract / separate
the individual values is more
complex / takes longer to execute / run / process
NE Algorithm is more complicated
Q6
6
A program displays a progress bar to inform the user of the progress of tasks that take a significant
time to complete, such as those involving file transfer operations.
Task progress is divided into 11 steps. Each step represents the amount of progress as a
percentage. An image is associated with each step and each image is stored in a different file.
Different progress bar images may be selected. For a given image, files all have the same filename
root, with a different suffix.
The table illustrates the process for using the image with filename root BargraphA
Step
Image filename
Image
1
2
3
< 10
>= 10 and < 20
>= 20 and < 30
Percentage
progress
BargraphA-1.bmp
BargraphA-2.bmp
BargraphA-3.bmp
BargraphA-9.bmp
Show mark scheme
6(a)
Example Selection Solution:
PROCEDURE Progress(Percent : INTEGER, Root : STRING)
DECLARE Filename, StepValue : STRING
CASE OF Percent
< 10 : StepValue
"1"
< 20 : StepValue
"2"
< 30 : StepValue
"3"
< 40 : StepValue
"4"
< 50 : StepValue
"5"
< 60 : StepValue
"6"
< 70 : StepValue
"7"
< 80 : StepValue
"8"
< 90 : StepValue
"9"
< 100 : StepValue
"10"
OTHERWISE : StepValue
"11"
ENDCASE
Filename
Root & "-" & StepValue & ".bmp"
CALL Display(Filename)
ENDPROCEDURE
Mark as follows for loop solution:
1
Procedure heading, parameters and ending
2
Correct selection construct(s) structure
3
Use of selection statement to obtain two file numbers
4
Use of selection statement to obtain all the file numbers
5
Concatenate
, hyphen, file number and ".bmp" suffix
Root
6
Call
once with filename as parameter following a reasonable
Display()
attempt
PROCEDURE Progress(Percent : INTEGER, Root : STRING)
DECLARE Filename, StepValue : STRING
CASE OF Percent
< 10 : StepValue
"1"
< 20 : StepValue
"2"
< 30 : StepValue
"3"
< 40 : StepValue
"4"
< 50 : StepValue
"5"
< 60 : StepValue
"6"
< 70 : StepValue
"7"
< 80 : StepValue
"8"
< 90 : StepValue
"9"
< 100 : StepValue
"10"
OTHERWISE : StepValue
"11"
ENDCASE
Filename
Root & "-" & StepValue & ".bmp"
CALL Display(Filename)
ENDPROCEDURE
Mark as follows for loop solution:
1
Procedure heading, parameters and ending
2
Correct selection construct(s) structure
3
Use of selection statement to obtain two file numbers
4
Use of selection statement to obtain all the file numbers
5
Concatenate
, hyphen, file number and ".bmp" suffix
Root
6
Call
once with filename as parameter following a reasonable
Display()
attempt
6(b)(i) [2 marks]
Example answer:
FUNCTION Progress2(Percent, Steps : INTEGER, Root :
STRING) RETURNS STRING
One mark for each:
Keyword
and
three parameters of correct type
FUNCTION
Progress2
Keyword
and type string
RETURNS
FUNCTION Progress2(Percent, Steps : INTEGER, Root :
STRING) RETURNS STRING
One mark for each:
Keyword
and
three parameters of correct type
FUNCTION
Progress2
Keyword
and type string
RETURNS
6(b)(ii) [1 mark]
The progress display will more accurately show the progress of the task
Q9
>= 80 and < 90
9
Q10
>= 90 and < 100
100
10
BargraphA-10.bmp