Function header in Software Development pseudocode

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This Function header in Software Development pseudocode worksheet is part of the VCE Pseudo Code journey. Print it as a booklet?

Function header in Software Development pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does a function header specify the data type of each parameter?
A True
B False
2. Does a function header include the data type of its return value?
A True
B False
3. Should the parameters and return type be separated by a colon?
A False
B True
4. Should data types like INTEGER be written in uppercase?
A False
B True
5. Would a function returning TRUE or FALSE use INTEGER as its return type?
A False
B True

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1define addNumbers(a: INTEGER, b: INTEGER): INTEGER AThe header is missing the colon before the return type
2: BOOLEAN BA function header with two integer parameters and an integer return type
3The data type describing a parameter or return value in a function header Cdefine greet(name: STRING): STRING
4A colon used just before the return type in a function header DIndicates the function returns a TRUE or FALSE value
5define greet(name: STRING) STRING return "Hello " + name end function EThe parameter num is missing its data type
6define square(num): REAL return num * num end function FINTEGER

Definitions

addNumbers(a: INTEGER, b: INTEGER): INTEGER

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
define addNumbers(a: _______, b: INTEGER): INTEGER
2.
define addNumbers(a: INTEGER, b: INTEGER): _______
3.
define greet(name: STRING)_ STRING
4.
define isEven(num: INTEGER): _______
5.
define square(num: REAL)______

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A define greet(name: STRING) STRING
B return "Hello " + name
C end function
Question 2
A define calculateArea(length: REAL, width: REAL): REAL
B total <- length * width
C return total
D end function
Question 3
A define addNumbers(a: INTEGER, b: INTEGER): INTEGER
B return a + b
C end func
Question 4
A return num * num
B end function
C // square function
D define square(num): REAL
Question 5
A define subtract(a: INTEGER, b: integer): INTEGER
B return a - b
C end function

Answer Key

Function header in Software Development pseudocode
Section A: Quick Questions
Q1
A — True
Q2
A — True
Q3
B — True
Q4
B — True
Q5
A — False
Section B: Match the Pairs
Q1
define addNumbers(a: INTEGER, b: INTEGER): INTEGER → A function header with two integer parameters and an integer return type
Q2
: BOOLEAN → Indicates the function returns a TRUE or FALSE value
Q3
The data type describing a parameter or return value in a function header → INTEGER
Q4
A colon used just before the return type in a function header → define greet(name: STRING): STRING
Q5
define greet(name: STRING) STRING return "Hello " + name end function → The header is missing the colon before the return type
Q6
define square(num): REAL return num * num end function → The parameter num is missing its data type
Section C: Definitions
Q1
addNumbers(a: INTEGER, b: INTEGER): INTEGER — A function header specifying the function's name, its typed parameters, and the data type of its return value
Section D: Fill in the Blanks
Q1
define addNumbers(a: INTEGER, b: INTEGER): INTEGER
Q2
define addNumbers(a: INTEGER, b: INTEGER): INTEGER
Q3
define greet(name: STRING): STRING
Q4
define isEven(num: INTEGER): BOOLEAN
Q5
define square(num: REAL): REAL
Section E: Spot the Error
Q1
A — The header is missing the colon before the return type — it should read (name: STRING): STRING.
Q2
B — Assignment in pseudocode uses ←, not <-.
Q3
C — A function definition must close with end function, not end func.
Q4
D — The parameter num is missing its data type — it should read (num: REAL).
Q5
A — Data types should be written in uppercase, such as INTEGER, not lowercase integer.