SDD HW Comp Constructs 1 Qs
SDD HW Comp Constructs 1 Qs
Question 1
Line 1 PROCEDURE sub1()
Line 2 DECLARE value INITIALLY 10
Line 3 SEND value TO DISPLAY
Line 4 END PROCEDURE
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 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
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
Sam is learning about the scope of variables and parameter passing. Sam writes the above code.