DP Computer Science · HL / SL · B2 Programming

B2.3 Programming constructs

Get started
Notes Quiz
Free preview 2/15
  1. Question 1

    A function `calculateDiscount` is defined in pseudocode as follows: ``` FUNCTION calculateDiscount(price, rate) discount ← price × rate / 100 RETURN discount END FUNCTION result ← calculateDiscount(200, 15) ``` What value is stored in `result` after this code executes?
    No clue? Show me the answer
    Correct answerCorrect!Incorrect
    B30

    Step-by-step walkthrough

    Choose a solution method

    Method #1Approach 1

    Step 1: Identify the function call and arguments

    The function calculateDiscount is called with price = 200 and rate = 15. These are substituted into the function body.

    Step 2: Execute the calculation

    The expression evaluates as: discount=200×15/100=3000/100=30

    Step 3: Trace the RETURN statement

    The function returns discount, which is 30. This value is assigned to result.

    Step 4: Select the correct answer

    The value stored in result is 30.

    Method #2Approach 2

    Step 1: Identify what the question is asking

    We need to trace the function call and determine what value is returned and stored in result.

    Step 2: Eliminate 15

    15 is the rate argument passed in — it is an input to the function, not the computed result.

    Step 3: Eliminate 185

    185 would be the price after the discount is applied (200−30=185), but the function only returns the discount amount, not the final price.

    Step 4: Eliminate 200

    200 is the original price argument — the function does not return the original price unchanged.

    Step 5: Select the correct answer

    30 is correct: 200×15/100=30, which is the discount amount returned by the function.

  2. Question 2

    Which of the following best describes the difference between a function and a procedure in IB pseudocode?
    No clue? Show me the answer
    Correct answerCorrect!Incorrect
    BA function returns a value using RETURN; a procedure does not return a value

    Step-by-step walkthrough

    Choose a solution method

    Method #1Approach 1

    Step 1: Recall the definitions

    In IB Computer Science, a function is a subprogram that performs a task and returns a value to the caller using RETURN. A procedure performs a task but does not return a value.

    Step 2: Check each option against the definitions

    Both functions and procedures can have parameters, so the first option is incorrect. Both can be called multiple times, so the third option is incorrect. Neither is restricted to a particular location by definition, so the fourth is incorrect.

    Step 3: Select the correct answer

    The key distinguishing feature is the RETURN statement and the production of a value — only a function does this.

    Method #2Approach 2

    Step 1: Identify what is being asked

    The question asks for the defining difference between a function and a procedure in IB pseudocode.

    Step 2: Eliminate 'A function can have parameters; a procedure cannot'

    Both functions and procedures can accept parameters. For example, PROCEDURE printGreeting(name) uses a parameter, so this distinction is false.

    Step 3: Eliminate 'A procedure can be called multiple times; a function can only be called once'

    There is no such restriction — both functions and procedures can be called any number of times. This option is entirely incorrect.

    Step 4: Eliminate 'A function is defined outside the main program; a procedure is defined inside it'

    In IB pseudocode, the definition location does not determine whether a subprogram is a function or procedure. This distinction does not exist.

    Step 5: Select the correct answer

    'A function returns a value using RETURN; a procedure does not return a value' is the precise IB definition of the distinction.

Free preview

13 more questions in this topic

← Previous topicB2.2 Data structuresNext topic →B2.4 Programming algorithms
Koncepts

Learn it properly. Then practise like it's the real paper.

Start free

Features

  • Lessons
  • Past papers
  • Library
  • Homework Help
  • Duels

More

  • For parents
  • Compare
  • Plans & pricing
  • DP for students

Legal

  • Privacy
  • Terms
  • Account deletion

© 2026 Koncepts (product of PrepAiro, Inc). All rights reserved.
DP, IB, EE and TOK are terms of the International Baccalaureate Organization.

Made for IB DP students.