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 subroutine addBonus(score) that must add 10 to the score and return the new score

  1. Use the parameters already given, with no extra inputs: use score
  2. Write the missing statement: score ← score + 10
  3. Return the updated value: RETURN score

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 of tickets at £5 each

  1. Define it with a parameter: SUBROUTINE calculatePrice(tickets)
  2. Calculate using the parameter: price ← tickets * 5
  3. Return the value and close: RETURN price then ENDSUBROUTINE

How do you call a subroutine and keep the value it returns?

e.g. use calculatePrice for 3 tickets and store the result in totalPrice

totalPrice ← 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 greet that outputs a welcome for a name

  1. Define it with any parameters: SUBROUTINE greet(name)
  2. Write the task, then close it: OUTPUT 'Welcome ' + name … ENDSUBROUTINE
  3. Call it by name: greet('Sam')

How do you pass an array into a subroutine?

e.g. pass the array scores into a subroutine printAll

Use 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.