0% found this document useful (0 votes)
6 views5 pages

Procedures Answers

The document outlines key programming concepts including procedures, functions, library routines, string handling, bubble sort, linear search, and the program development life cycle. It provides examples of code snippets and explanations for various programming tasks and algorithms. Additionally, it includes a marking scheme for evaluating understanding of these topics.

Uploaded by

Simrah Maqbool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Procedures Answers

The document outlines key programming concepts including procedures, functions, library routines, string handling, bubble sort, linear search, and the program development life cycle. It provides examples of code snippets and explanations for various programming tasks and algorithms. Additionally, it includes a marking scheme for evaluating understanding of these topics.

Uploaded by

Simrah Maqbool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Procedures & functions, library routines & string handling, Bubble sort, linear

search, PDLC topicals


(Answers)
PROCEDURES AND FUNCTIONS
1. B
2. C
3.

4. C

LIBRARY ROUTINES & STRING HANDLING

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)

3a) One mark for each correct line


DECLARE X : INTEGER DECLARE Y : REAL DECLARE Z : BOOLEAN
b) One mark BOOLEAN One mark One mark One mark One mark One mark
for using FUNCTION and END FUNCTION and RETURNS
for naming the function Same
for defining the two parameters correctly
for comparing the two parameters using ROUND for correctly returning TRUE and FALSE
for correct function call
Example definition:
FUNCTION Same(A : INTEGER, B : REAL) RETURNS BOOLEAN
IF A = ROUND(B,0) THEN
RETURN TRUE ELSE
RETURN FALSE ENDIF END FUNCTION Example call:
Z <-- Same(X,Y)
c) A function is defined once and called many times or
Define – setting up the function and call is using a function

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

5.a) One mark per mark point, max three


Storing string in Phrase
Correct use of LENGTH function Correct use of UCASE function
Correct outputs of LENGTH and UCASE
For example:
Phrase <-- "The beginning is the most important part" OUTPUT LENGTH(Phrase)
OUTPUT UCASE(Phrase)
b) One mark for each correct line, max two 40
THE BEGINNING IS THE MOST IMPORTANT PART
BUBBLE SORT
1a)

b) Any two from:


• The algorithm sorts/orders numbers
• ... into descending order / from largest to smallest

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

You might also like