0% found this document useful (0 votes)
44 views3 pages

SDD HW Comp Constructs 1 Qs

sqa higher computing exam questions

Uploaded by

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

SDD HW Comp Constructs 1 Qs

sqa higher computing exam questions

Uploaded by

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

SDD Homework

Implementation: Computational Constructs 1

Question 1
Line 1 PROCEDURE sub1()
Line 2 DECLARE value INITIALLY 10
Line 3 SEND value TO DISPLAY
Line 4 END PROCEDURE

Line 5 PROCEDURE sub2()


Line 6 DECLARE value INITIALLY 20
Line 7 SEND value TO DISPLAY
Line 8 END PROCEDURE

Line 9 PROCEDURE sub3(INTEGER v)


Line 10 SEND v TO DISPLAY
Line 11 END PROCEDURE

Line 12 FUNCTION sub4(INTEGER v) RETURNS INTEGER


Line 13 DECLARE newV INITIALLY 0
Line 14 SET newV TO v + 15
Line 15 RETURN newV
Line 16 END FUNCTION

Line 17 #main program


Line 18 DECLARE value INITIALLY 30
Line 19 DECLARE newvalue INITIALLY 0
Line 20 sub1()
Line 21 sub2()
Line 22 sub3(3)
Line 23 sub3(value)
Line 24 SET newvalue TO sub4(value)
Line 25 SEND newvalue TO DISPLAY

Read the program above and answer the following questions:

a. The program uses both procedures and functions. Explain one difference between a procedure
and a function. 1
b. State the scope of value at line 18 1
c. State the scope of value at line 6 1
d. Identify an actual parameter in the code. 1
e. State the output produced by the code. 1
Question 2

Line 1 FUNCTION getnumber() RETURNS INTEGER


Line 2 DECLARE number INITIALLY 0
Line 3 RECEIVE number FROM KEYBOARD
Line 4 RETURN number
Line 5 END FUNCTION

Line 6 FUNCTION fillarray(ARRAY OF INTEGER nums, INTEGER length) RETURNS ARRAY OF INTEGER
Line 7 FOR index FROM 0 TO length DO
Line 8 SET nums[index] TO <random number between 1 and 6>
Line 9 END FOR
Line 10 RETURN nums
Line 11 END FUNCTION

Line 12 PROCEDURE displayarray(ARRAY OF INTEGER nums, INTEGER length)


Line 13 FOR index FROM 0 TO length DO
Line 14 SEND nums[index] TO DISPLAY
Line 15 END FOR
Line 16 END PROCEDURE

Line 17 #main program


Line 18 DECLARE throws INITIALLY 0
Line 19 DECLARE dice INITIALLY []
Line 20 SET throws TO getnumber()
Line 21 SET dice TO fillarray(dice, throws)
Line 22 displayarray(dice, throws)

Read the program above and answer the following questions:

a. Identify the formal parameters of the fillarray function 1

b. Explain what happens when Line 4 is executed (Use line numbers to help explain your answer) 2
c. State the scope of dice (Line 19) 1
d. State the scope of nums (Line 8) 1
e. Write down sample output if the number 5 is entered at Line 3 when the program is tested 1
Question 3

Line 1 FUNCTION mySubProgram(INTEGER value) RETURNS INTEGER


Line 2 DECLARE c INITIALLY 2
Line 3 DECLARE d INITIALLY 6
Line 4 DECLARE a INITIALLY 3
Line 5 DECLARE b INITIALLY 4
Line 6 DECLARE c INITIALLY 5
Line 7 SEND [a,b,c,d] TO DISPLAY
Line 8 RETURN value
Line 9 END FUNCTION

Line 10 DECLARE a INITIALLY 0


Line 11 DECLARE b INITIALLY 0
Line 12 DECLARE c INITIALLY 0
Line 13 DECLARE d INITIALLY 0
Line 14 DECLARE e INITIALLY 0

Line 15 SEND [a,b,c] TO DISPLAY

Line 16 SET b TO mySubProgram(b)

Line 17 SET e TO b+5


Line 18 SET d TO 8
Line 19 SEND [a,b,c,d,e] TO DISPLAY

Sam is learning about the scope of variables and parameter passing. Sam writes the above code.

Sam expected the following output:

Line 15: 000


Line 7: 3456
Line 19: 04089

a. Write down the actual output produced at line 19 1

b. Explain the error Sam has made 2


c. Describe how to correct the error so the program produces the expected output 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy