Parameters & Return Values Flashcards
All 7 cards in this deck
What are the steps to complete a missing line in a given subroutine?
e.g. a subroutineaddBonus(score)that must add 10 to the score and return the new score- Use the parameters already given, with no extra inputs: use
score - Write the missing statement:
score ← score + 10 - Return the updated value:
RETURN score
- Use the parameters already given, with no extra inputs: use
What is the difference between a function and a procedure?
A function is a subroutine that returns a value to the calling routine; a procedure is a subroutine that carries out a task but returns no value.
How is a subroutine that takes a parameter and returns a value written in AQA pseudo-code?
e.g.
calculatePrice, giving the cost ofticketsat £5 each- Define it with a parameter:
SUBROUTINE calculatePrice(tickets) - Calculate using the parameter:
price ← tickets * 5 - Return the value and close:
RETURN pricethenENDSUBROUTINE
- Define it with a parameter:
How do you call a subroutine and keep the value it returns?
e.g. use
calculatePricefor 3 tickets and store the result intotalPricetotalPrice ← calculatePrice(3). The parameter goes in the brackets and the returned value is assigned with←.How is a subroutine that returns no value (a procedure) written and called in AQA pseudo-code?
e.g. a subroutine
greetthat outputs a welcome for a name- Define it with any parameters:
SUBROUTINE greet(name) - Write the task, then close it:
OUTPUT 'Welcome ' + name…ENDSUBROUTINE - Call it by name:
greet('Sam')
- Define it with any parameters:
How do you pass an array into a subroutine?
e.g. pass the array
scoresinto a subroutineprintAllUse the array's identifier as the parameter in the call:
printAll(scores). Inside the subroutine, the parameter is used like an array.What is a parameter?
e.g. the 3 in
calculatePrice(3)A value passed into a subroutine when it is called, so the subroutine can use data from the calling routine. AQA uses 'parameter' for both the value passed in and the variable that receives it.