The final CASE condition (> 200) in the pseudocode example could be replaced with a keyword.
Give the keyword.
Did this page help you?
Exam code: 9618
The final CASE condition (> 200) in the pseudocode example could be replaced with a keyword.
Give the keyword.
How did you do?
Did this page help you?
One type of run-time error can cause a program to stop responding (‘freezing’).
Identify a particular type of programming construct that can generate this type of error and explain why it occurs.
Construct .......................................................................................................
Explanation.....................................................................................................
How did you do?
The function Process() contains a selection construct using a CASE structure.
Write pseudocode using a single selection construct with the same functionality without using a CASE structure.
How did you do?
Did this page help you?
Refer to the insert (opens in a new tab) for the list of pseudocode functions and operators.
The following table contains pseudocode examples.
Each example may contain statements that relate to one or more of the following:
selection
iteration (repetition)
subroutine (procedure or function).
Complete the table by placing one or more ticks ('✓') in each row.
Pseudocode example | Selection | Iteration | Subroutine |
| |||
| |||
| |||
|
How did you do?
Did this page help you?
An algorithm will:
prompt and input a sequence of 100 integer values, one at a time
sum the positive integers
output the result of the sum.
The algorithm requires the use of basic constructs. One of these is sequence.
Identify one other basic construct required by the algorithm and describe how it is used.
Construct....................................................................................................
Use..............................................................................................................
How did you do?
Did this page help you?
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 CMID(Format, Count, 1) LSTR_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
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]
How did you do?
Did this page help you?
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
The procedure contains a statement that is not needed.
Identify the pseudocode statement and explain why it is not needed.
Statement ..........................................................................................
Explanation .........................................................................................
How did you do?
Did this page help you?
A program uses a global 1D array of type string and a text file.
An algorithm that forms part of the program is expressed as follows:
copy the first line from the file into the first element of the array
copy the second line from the file into the second element of the array
continue until all lines in the file have been copied into the array.
Sequence is one programming construct. Identify one other programming construct that will be required when the algorithm from part (a) is converted into pseudocode and explain its use.
Construct..........................................................................................................
Use....................................................................................................................
How did you do?
Did this page help you?
A record structure is declared to hold data relating to components being produced in a factory:
TYPE Component DECLARE Item_ID : STRING DECLARE Reject : BOOLEAN DECLARE Weight : REAL ENDTYPE
The factory normally produces a batch (or set) of 1000 components at a time. A global array is declared to store 1000 records for a batch:
DECLARE Batch : ARRAY [1:1000] OF Component
Two global variables contain the minimum and maximum acceptable weight for each component. The values represent an inclusive range and are declared as:
DECLARE Min, Max : REAL
A program uses a variable ThisIndex as the array index to access a record.
Write a pseudocode clause to check whether or not the weight of an individual component is within the acceptable range.
How did you do?
Did this page help you?
A program is being designed in pseudocode.
The program contains the following declaration:
DECLARE Data : ARRAY[1:1000] OF STRING
A procedure ArrayInitialise() is written to initialise the values in the array:
PROCEDURE ArrayInitialise(Label : STRING) DECLARE Index : INTEGER Index1 WHILE Index <= 1000 CASE OF (Index MOD 2) 0 : Data[Index] FormatA(Label) Index Index + 1 1 : Data[Index] FormatB(Label) Index Index + 1 ENDCASE ENDWHILE ENDPROCEDURE
Functions FormatA() and FormatB() apply fixed format case changes to the parameter string.
The design of the procedure does not use the most appropriate loop construct.
Suggest a more appropriate construct that could be used and explain your choice.
Construct ........................................................................................................
Explanation ......................................................................................................
How did you do?
Did this page help you?
Refer to the insert (opens in a new tab)for the list of pseudocode functions and operators.
The following pseudocode represents part of the algorithm for a program:
CASE OF ThisValue
< 30 : Level "Low" // less than 30
Check 1
< 20 : Level "Very Low" // less than 20 Check ThisValue / 2 30 TO 40 : Level "Medium" // between 30 and 40 Check ThisValue / 3 Data[ThisValue] Data[ThisValue] + 1
> 40 : Level "High" ENDCASE
Complete the table by writing the answer for each row:
Answer | |
The value assigned to | |
The value assigned to | |
The value assigned to | |
The number of elements in array |
How did you do?
The pseudocode contains four assignments to variable Level. One of these assignments will never be performed.
Identify this assignment and explain why this is the case.
How did you do?
The following line is added immediately before the ENDCASE statement:
OTHERWISE : Level "Undefined"
State why this assignment is never performed.
How did you do?
Did this page help you?
Sequence is one programming construct.
Identify two other programming constructs that will be required when the algorithm is converted into pseudocode.
Construct 1 ..........................................................................................................
Construct 2 .........................................................................................................
How did you do?
Did this page help you?
An algorithm will:
input a sequence of integer values, one at a time
ignore all values until the value 27 is input, then sum the remaining values in the sequence
stop summing values when the value 0 is input and then output the sum of the values.
The solution to the algorithm includes iteration.
Give the name of a suitable loop structure that could be used.
Justify your answer.
Name .....................................................................................................................
Justification ............................................................................................................
How did you do?
Did this page help you?
A program contains six modules:
Pseudocode module header | |
| |
| |
| |
| |
| |
|
Module-X() calls Reset() Module-Y() calls Restore()

Explain the meaning of the diamond symbol as used in the diagram in part (a).
How did you do?
Did this page help you?
A global 1D array of integers contains four elements, which are assigned values as shown:
Mix[1] 4 Mix[2] 2 Mix[3] 3 Mix[4] 5
A procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Start : INTEGER)
DECLARE Value, Index, Total : INTEGER
Index Start Total 0
WHILE Total < 20 Value Mix[Index] Total Total + Value
IF Index < 4 THEN Mix[Index] Mix[Index] + Mix[Index+1] ELSE Mix[Index] Mix[Index] + Mix[1] ENDIF Index (Value MOD 4) + 1
ENDWHILE
Mix[1] Total * Index
ENDPROCEDURE
Complete the trace table on the opposite page by dry running the procedure when it is called as follows:
CALL Process(2)
Index | Value | Total | Mix[1] | Mix[2] | Mix[3] | Mix[4] |
How did you do?
Did this page help you?