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 answer
Correct!
IncorrectStep-by-step walkthrough
Choose a solution method
Method #1Approach 1Step 1: Identify the function call and arguments
The function
calculateDiscountis called with price = 200 and rate = 15. These are substituted into the function body.Step 2: Execute the calculation
The expression evaluates as:
Step 3: Trace the RETURN statement
The function returns
discount, which is 30. This value is assigned toresult.Step 4: Select the correct answer
The value stored in
resultis 30.Method #2Approach 2Step 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
rateargument 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 (), but the function only returns the discount amount, not the final price.
Step 4: Eliminate 200
200 is the original
priceargument — the function does not return the original price unchanged.Step 5: Select the correct answer
30 is correct: , which is the discount amount returned by the function.
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 answer
Correct!
IncorrectStep-by-step walkthrough
Choose a solution method
Method #1Approach 1Step 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
RETURNstatement and the production of a value — only a function does this.Method #2Approach 2Step 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.