Parameter

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

Parameter

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which describes a parameter?
A An identifier in the subroutine definition that receives a value
B The value written in brackets after the subroutine name in a CALL
2. Which line defines a procedure with a parameter?
A PROCEDURE ShowScore(Score : INTEGER)
B PROCEDURE ShowScore(Score)
3. Inside the subroutine, how is a parameter used?
A Only as a constant that can never be read
B Like a variable, for example OUTPUT Score
4. When does a parameter get its value?
A Each time the subroutine is called
B Only once, when the program starts
5. In FUNCTION Double(Num : INTEGER) RETURNS INTEGER, what is Num?
A The value returned by the function
B A parameter with the data type INTEGER

Match the Pairs

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

Left columnRight column
1PROCEDURE Greet(Name : STRING) ACALL ShowPrice(20)
2FUNCTION Area(Length : INTEGER, Width : INTEGER) RETURNS INTEGER BThe parameter has no data type. It should be written as Name : STRING.
3A parameter is used like a variable inside the subroutine body CName is a parameter: an identifier in the definition that receives a value and has the data type STRING
4At each call a value is substituted for the parameter, so Price takes the value 20 here DPROCEDURE ShowDouble(Num : INTEGER) OUTPUT Num * 2 ENDPROCEDURE
5PROCEDURE Greet(Name) EFour parameters are used, but this course allows up to three parameters.
6FUNCTION Total(A : INTEGER, B : INTEGER, C : INTEGER, D : INTEGER) RETURNS INTEGER FLength and Width are two parameters, each receiving a value when Area is called

Definitions

parameter

Fill in the Blanks

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

1.
PROCEDURE ShowDouble(___ : INTEGER) OUTPUT Num * 2 ENDPROCEDURE
2.
PROCEDURE ShowName(Name : ______) OUTPUT "Hello, " & Name ENDPROCEDURE
3.
PROCEDURE Area(Length : REAL, _____ : REAL) OUTPUT Length * Width ENDPROCEDURE
4.
FUNCTION Half(Num : INTEGER) RETURNS REAL RETURN ___ / 2 ENDFUNCTION
5.
PROCEDURE Check(Passed : _______) OUTPUT NOT Passed ENDPROCEDURE

Spot the Error

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

Question 1
A PROCEDURE Greet(Name : STRING)
B OUTPUT "Hi ", Person
C ENDPROCEDURE
D CALL Greet("Sam")
Question 2
A PROCEDURE Sq(Num)
B OUTPUT Num * Num
C ENDPROCEDURE
D CALL Sq(5)
Question 3
A PROCEDURE Show(INTEGER : N)
B OUTPUT "Value: ", N
C ENDPROCEDURE
D CALL Show(7)
Question 4
A PROCEDURE Show(Age : INTEGER)
B OUTPUT "Age: ", "Age"
C ENDPROCEDURE
D CALL Show(15)
Question 5
A PROCEDURE Greet(Name : STRING)
B OUTPUT "Hello ", Name
C ENDPROCEDURE
D CALL Greet(42)

Answer Key

Parameter
Section A: Quick Questions
Q1
A — An identifier in the subroutine definition that receives a value
Q2
A — PROCEDURE ShowScore(Score : INTEGER)
Q3
B — Like a variable, for example OUTPUT Score
Q4
A — Each time the subroutine is called
Q5
B — A parameter with the data type INTEGER
Section B: Match the Pairs
Q1
PROCEDURE Greet(Name : STRING) → Name is a parameter: an identifier in the definition that receives a value and has the data type STRING
Q2
FUNCTION Area(Length : INTEGER, Width : INTEGER) RETURNS INTEGER → Length and Width are two parameters, each receiving a value when Area is called
Q3
A parameter is used like a variable inside the subroutine body → PROCEDURE ShowDouble(Num : INTEGER) OUTPUT Num * 2 ENDPROCEDURE
Q4
At each call a value is substituted for the parameter, so Price takes the value 20 here → CALL ShowPrice(20)
Q5
PROCEDURE Greet(Name) → The parameter has no data type. It should be written as Name : STRING.
Q6
FUNCTION Total(A : INTEGER, B : INTEGER, C : INTEGER, D : INTEGER) RETURNS INTEGER → Four parameters are used, but this course allows up to three parameters.
Section C: Definitions
Q1
parameter — An identifier in a subroutine definition that receives a value when the subroutine is called. It is used like a variable inside the subroutine and has a data type.
Section D: Fill in the Blanks
Q1
PROCEDURE ShowDouble(Num : INTEGER) OUTPUT Num * 2 ENDPROCEDURE
Q2
PROCEDURE ShowName(Name : STRING) OUTPUT "Hello, " & Name ENDPROCEDURE
Q3
PROCEDURE Area(Length : REAL, Width : REAL) OUTPUT Length * Width ENDPROCEDURE
Q4
FUNCTION Half(Num : INTEGER) RETURNS REAL RETURN Num / 2 ENDFUNCTION
Q5
PROCEDURE Check(Passed : BOOLEAN) OUTPUT NOT Passed ENDPROCEDURE
Section E: Spot the Error
Q1
B — The parameter is called Name, so the body must use Name. Person was never declared, so it holds no value. It should be OUTPUT "Hi ", Name.
Q2
A — Every parameter in a subroutine definition needs a data type. It should be PROCEDURE Sq(Num : INTEGER).
Q3
A — The parameter name comes first, then a colon, then the data type. It should be PROCEDURE Show(N : INTEGER).
Q4
B — Quotes around Age make it plain text, so the word Age is printed. The parameter must be written without quotes to output the value received. It should be OUTPUT "Age: ", Age.
Q5
D — The parameter Name has data type STRING, so the value passed in must be a STRING. 42 is an INTEGER. It should be CALL Greet("Sam").