UA03 - Structured Programming
UA03 - Structured Programming
Paper | 2
FlagA = TRUE
FlagB = FALSE
FlagC = TRUE
Evaluate the expressions given in the following table:
Expression Evaluates to
NOT FlagB AND FlagC
NOT (FlagB OR FlagC)
(FlagA AND FlagB) OR FlagC
NOT (FlagA AND FlagB) OR NOT FlagC
[4]
(b) Fill in the blank for appropriate definition for subroutine related terms.
--------------- a subroutine that does not return a value to the program that is called
--------------- a subroutine that does not return a value to the program that is called
(b) The end of term examinations are now marked out of twenty. Provide the following:
(i) Two sets of normal data and their expected results: ----------------------------------------------------------------
(ii) Some erroneous/abnormal data and their expected results: -------------------------------------------------------
(iii) Two sets of boundary data and their expected results :--------------------------------------------------------[3]
(c) Tick (✓) the box to match up the problem to the type error.
Problem Syntax Runtime Logical
Missing bracket error
Program won’t compile error
Incorrect output error
Missing file error
Data type error
Programmer types > instead of <=
Misspelt keyword error
[5]
(d) Give one difference between a logic error and a syntax error.
…………………..……………...…………………………………………….……..….…….
………………………..……………...…………………………………………….…...…….
……………………………..……………..……..…………………………………………[2]
© HEGICT 2023 2210 / P2 / Unit Assessment 05 / Summer 2023
5
3. The variables A, B and C are used to store data in a program:
• A: a string • B: a position in the string • C: the number of characters in the string.
(a) Write pseudocode statements to declare the variables X, Y and Z.
…………………..……………...…………………………………………….……..….…….
………………………..……………...…………………………………………….…...…….
……………………………..……………..……..…………………………………………[3]
Paper | 2
(b) The function Length(A) finds the length of a string X.
The function SubString(A,B,C) finds a substring of A starting at position B and C characters long.
The first character in A is in position 1.
Complete the pseudocode statements to and
Show the value of the variable after each pseudocode statement has been executed:
• store the string "I Love Programming" in A
• find the length of the string and output it
• extract the word fun from the string and output it.
(i) --------- ← "I Love Programming"
(ii) B ← (LENGTH(A)) – 15 Return : -------------
(iii) -------- ← 4
(iv) OUTPUT SUBSTRING(A,B,C) Return : ------------- [4]
(c) Write a pseudocode statement to extract the word Programming from A and store it in the variable R.
………………………..……………...…………...………………………………….……….
……………………………..……………..………………..………………………………[3]
4. Complete the pseudocode statements to store the a line of text form user in the file 'MyText.txt'
DECLARE TextLine : -----------
DECLARE -------- : STRING
MyFile ← ---------------------
OPEN MyFile FOR ----------------
---------- "Please enter a line of text"
INPUT -----------------
WRITEFILE ---- --------------
CLOSEFILE(------------) [5]
(b) Draw a flowchart for an algorithm to:
o allow numbers to be input in a array called MyArray
o count how many numbers are positive
o output the count of positive numbers when zero is input and end the algorithm.
…………………….……………...……………….………...……………………….……….
…………………….……………...……………….………...……………………….……….
…………………..…………...…………………………..………..…………….……..….….
…………………….……………...……………….………...……………………….……….
…………………..…………...…………………………..………..…………….……..….….
…………………….……………...……………….………...……………………….……….
…………………..…………...…………………………..………..…………….……..….….
…………………….……………...……………….………...……………………….……….
…………………..…………...…………………………..………..…………….……..….….
…………………….……………...……………….………...……………………….……….
…………………………..……………..………..………………..………..………………[5]