Study the following pseudocode. FUNCTION Double(N : INTEGER) RETURNS INTEGER RETURN N * 2 ENDFUNCTION FUNCTION AddThree(N : INTEGER) RETURNS INTEGER ...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

Question 1 Report

Study the following pseudocode.

FUNCTION Double(N : INTEGER) RETURNS INTEGER
    RETURN N * 2
ENDFUNCTION

FUNCTION AddThree(N : INTEGER) RETURNS INTEGER
    RETURN N + 3
ENDFUNCTION

DECLARE A : INTEGER
DECLARE B : INTEGER
A ← 4
B ← Double(A)
A ← AddThree(B)
B ← Double(AddThree(A))
OUTPUT A, " ", B

(a) State the output. [1]

Answer Details

(a) This question tests the ability to trace through nested function calls. [1]

Step-by-step evaluation:

  1. A ← 4
  2. B ← Double(4): the function returns 4 * 2 = 8, so B = 8
  3. A ← AddThree(8): the function returns 8 + 3 = 11, so A = 11
  4. B ← Double(AddThree(11)): first evaluate the inner call, AddThree(11) = 14; then Double(14) = 28, so B = 28

OUTPUT: 11 28 [1]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning