PROCEDURES & FUNCTIONS, LIBRARY ROUTINES & STRING HANDLING, BUBBLE
SORT, LINEAR SEARCH, PDLC QUESTIONS
Procedures and Functions
1.
Tick ( ) one box to show the named section of a program that performs a specific task.
A file ⬜
B function ⬜
C parameter ⬜
D process ⬜ [1] (Q3/2210/02/SP/23)
2. A function is declared using pseudocode.
FUNCTION ConvertToCm(Inches: REAL) RETURNS REAL RETURN Inches * 2.4 ENDFUNCTION Tick
( ) one box which accurately describes the use of the variable Inches
A answer ⬜
B call ⬜
C parameter ⬜
D response ⬜ [1] (2210/02/SP/23)
3. Tick ✔ one box to show which word accurately describes the scope of a variable declared in a
procedure. A Function ⬜
B Global ⬜
C Local ⬜
D Subroutine ⬜ [1] (Q1/0478/22/F/M/23)
4. a) Write a procedure that takes two values as parameters and finds the remainder of value 1
divided by value 2. You must also write the main program to allow input of the values and the line of
code needed to call your procedure.
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
b) Write the program you created in part (a) as a function instead of a procedure. When you call the
procedure, store the value returned in a variable.
__________________________________________________________________________________
__________________________________________________________________________________
1|Page
__________________________________________________________________________________
__________________________________________________________________________________
5. Write a function that
• Takes as a parameter the users first name
• Takes as a parameter the users last name
• Extracts the first two characters of the users first name
•Extracts the first three characters of the users last name
• Concatenates the two extractions along with the value 01 (first extract then second extract then 01)
as a username
• returns the username
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
6. The following pseudocode uses the subroutine DoSomething().
Answer <-- 23 + DoSomething("Yellow")
State whether the subroutine is a function or a procedure. Justify your answer. [2].
__________________________________________________________________________________
__________________________________________________________________________________
2|Page
Library Routines & String Handling
1. The variables X, Y and Z are used to store data in a program:
• X stores a string
• Y stores a position in the string (e.g. 2)
• Z stores the number of characters in the string.
a) Write pseudocode statements to declare the variables X, Y and Z. [3]
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
b) The function Length(X) finds the length of a string X. The function SubString(X, Y, Z) finds a
substring of X starting at position Y and Z characters long. The first character in X is in position 1.
Write pseudocode statements:
• store the string "Programming is fun" in X
• find the length of the string and output it
• extract the word fun from the string and output it. [6]
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
(Q12/2210/02/SP/23)
2(a) A function LENGTH(X) finds the length of a string X and a function SUBSTRING(X,Y,Z) finds a
substring of X starting at position Y and Z characters long. The first character in the string is position
1.
(a) Show the value of the variable after each pseudocode statement has been executed.
01 P ← "Computer Science”..................................................................
02 Q ← LENGTH (P)................................................................................
03 R ← SUBSTRING (P, 10, 7)...................................................................
04 S ← LENGTH(R)................................................................................
05 T ← SUBSTRING(R, 1, 3)..................................................................... [5]
b) Write a pseudocode statement to extract the word Computer from P and store it in the variable F.
[2]
__________________________________________________________________________________
__________________________________________________________________________________
(Q10/2210/02B/SP/23)
3|Page
3. The variables X, Y and Z are used in a program: X stores a whole number, Y stores a decimal number
and Z stores a flag that can be set to TRUE or FALSE
a) Write pseudocode statements to declare the variables X, Y and Z [3]
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
b) The function Same(A,B) returns TRUE if the value of A is the same as the value of B when B is
rounded to the nearest whole number and FALSE otherwise.
Write pseudocode statements to:
• define the function
• call the function with X and Y and store the return value in Z [6]
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
(Q10/0478/22/F/M/23)
c) State the difference between defining and calling a function. [1]
__________________________________________________________________________________
4. Explain the purpose of the library routines DIV and ROUND. [4]
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
(0478/21/M/J/23)
5. The function LENGTH(Phrase) calculates the length of a string Phrase
a) Write the pseudocode statements to:
• store the string "The beginning is the most important part" in Phrase
• calculate and output the length of the string
• output the string in upper case. [3]
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
b) Write the output your pseudocode should produce. [2]
__________________________________________________________________________________
__________________________________________________________________________________
(0478/21/M/J/23)
4|Page
Bubble Sort
1. This pseudocode represents an algorithm.
REPEAT
Flag <-- 0
FOR Count <-- 0 to 3
IF Num[Count] < Num[Count + 1]
THEN
Store <-- Num[Count]
Num[Count] <--Num[Count + 1]
Num[Count + 1] <-- Store
Flag <-- 1
ENDIF
NEXT Count
UNTIL Flag = 0 a)
5|Page
[5]
b) Describe the purpose of the algorithm. [2] (Q5/22/O/N/20)
__________________________________________________________________________________
__________________________________________________________________________________
2. This flowchart represents an algorithm.
6|Page
a) The array Name[1:4] used in the flowchart contains the following data:
7|Page
b) Describe what the algorithm represented by the flowchart is doing. [2] (Q7/2210/02/SP/23)
__________________________________________________________________________________
__________________________________________________________________________________
3. A multi-user computer system stores information about users. It uses a 1D array, UserNameArray,
of type STRING.
There are 100 elements in the array. The format of the string in each element of the array is as
follows: <UserID><UserName>
• UserID is a six-character string of numerals.
• UserName is a variable-length string.
Write pseudocode for a procedure, BubbleSort, to perform an efficient bubble sort on
UserNameArray. The array is to be sorted in ascending order of UserID. You should assume that
UserNameArray has been declared as a global variable. [8] (Q3a/9608/21/O/N/17)
__________________________________________________________________________________
8|Page
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
Linear Search
1. Write the pseudocode to find the names in an Array Names [ ] of length 100, which start with the
letter 'A' and output the names. Also output the number of names starting with the letter 'A'.[2]
__________________________________________________________________________________
__________________________________________________________________________________
Program Development Life Cycle
1. a) Four descriptions of stages in the program development life cycle are shown.
Draw one line to link each description to its most appropriate program development life cycle
stage.Not all program development life cycle stages will be used.
b) Identify three of the component parts after a problem has been decomposed. [3]
(Q1/0478/21/M/J/23)
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
9|Page
2. Four descriptions of programming concepts and five programming concepts are shown. (a) Draw
one line to link each description to the most appropriate programming concept. Not all programming
concepts will be used.
(b) Write the pseudocode to use a procedure named Average that passes the values 25 and 50 to the
procedure.
..................................................................................................................................................
. ............................................................................................................................................. [2]
(c) Outline the role of procedures and functions in creating a program that is easier to maintain.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
3. Identify three different tasks in the analysis stage of the program development life cycle.
1 .......................................................................................................................................................
10 | P a g e
..........................................................................................................................................................
2 .......................................................................................................................................................
..........................................................................................................................................................
3 .......................................................................................................................................................
..........................................................................................................................................................
[3]
11 | P a g e