Procedures Answers
Procedures Answers
4. C
1.
2.
a) P Computer Science
Q 16
R Science S7
T Sci
b) One mark correct function assigned to F one mark correct parameters F ← SUBSTRING(P,1,8)
4. One mark per mark point, max four DIV, max two
To perform integer division
Meaning only the whole number part of the answer is retained
Example of DIV For example DIV(9,4) = 2
ROUND, max two
To return a value rounded to a specified number of digits / decimal places
The result will either be rounded to the next highest or the next
lowest value
... depending on whether the value of the preceding digit is >=5 or <5
Example of ROUND for example, ROUND(4.56, 1) = 4.6
2.
3.PROCEDURE BubbleSort
DECLARE Temp : STRING
DECLARE FirstID, SecondID : INTEGER DECLARE NoSwaps : BOOLEAN DECLARE Boundary : INTEGER
Declare J : INTEGER
Boundary ← 99
REPEAT
NoSwaps ← TRUE
FOR J ← 1 TO Boundary
FirstID ← UserNameArray[J] SecondID ← UserNameArray[J + 1] IF FirstID > SecondID
THEN
Temp ← UserNameArray[J] UserNameArray[J] ← UserNameArray[J + 1] UserNameArray[J + 1] ←
Temp
NoSwaps ← FALSE
ENDIF
ENDFOR
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE
END PROCEDURE
Mark as follows:
1. Procedure heading and ending (allow array as input parameter)
2. Variable declaration for counter / index (integer) or temp (string)
3. Outer working loop
4. Inner loop with suitable range
5. Correct comparison in a loop
6. Correct swap of complete array element in a loop
7. Set flag to indicate swap in inner loop and resetting in outer loop
8. Reducing Boundary in a loop
LINEAR SEARCH
1.
Found <-- FALSE
FOR i <-- 1 TO 100
IF LEFT(Names[i], 1) = 'A'
THEN
OUTPUT Names[I]
Found <-- TRUE
ACount <-- ACount + 1 ENDIF
NEXT
IF Found = FALSE
THEN
OUTPUT "No names starting with 'A' found"
ELSE
OUTPUT count
ENDIF
PROGRAM DEVELOPMENT LIFE CYCLE
1a)
b) One mark for naming or describing each component part, max three For example:
inputs // what is put into the system
processes // actions taken to achieve a result outputs // what is taken out of the system storage //
what needs to be kept for future use