Defining a procedure with one parameter

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

Defining a procedure with one parameter

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which header correctly defines a procedure with one parameter called Size?
A PROCEDURE Line(Size : INTEGER)
B PROCEDURE Line(INTEGER : Size)
2. Which procedure header is written correctly?
A PROCEDURE Greet(Name : STRING)
B PROCEDURE Greet(Name STRING)
3. Where is the parameter written when you define a procedure?
A On the line after ENDPROCEDURE
B In brackets straight after the procedure name
4. Which keyword ends the definition of a procedure?
A ENDPROCEDURE
B ENDFUNCTION
5. A procedure is defined as PROCEDURE Greet(Name : STRING). Which line inside the body outputs the value that was passed in?
A OUTPUT "Hello Name"
B OUTPUT "Hello ", Name

Match the Pairs

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

Left columnRight column
1PROCEDURE Line(Size : INTEGER) AThe identifier and data type are the wrong way round. The identifier comes first, then the colon, then the type: Size : INTEGER.
2PROCEDURE ShowName(Name : STRING) BThe colon is missing between the parameter name and its data type. It should be Size : INTEGER.
3A parameter is used inside the procedure body like a variable, for example to output its value CPROCEDURE ShowPrice(Price : REAL) OUTPUT Price ENDPROCEDURE
4A procedure with a REAL parameter ends with ENDPROCEDURE after its body DOUTPUT Size
5PROCEDURE Line(Size INTEGER) EStarts a procedure called Line with one parameter, Size, which must hold a whole number
6PROCEDURE Line(INTEGER : Size) FStarts a procedure with one parameter, Name, that holds text

Definitions

PROCEDURE Line(Size : INTEGER)

Fill in the Blanks

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

1.
PROCEDURE Line(Size : _______) OUTPUT Size ENDPROCEDURE
2.
_________ Greet(Name : STRING) OUTPUT "Hello ", Name ENDPROCEDURE
3.
PROCEDURE ShowPrice(Cost : REAL) OUTPUT Cost ____________
4.
PROCEDURE Line(Size : INTEGER) OUTPUT ____ ENDPROCEDURE
5.
PROCEDURE Greet(Name _ STRING) OUTPUT Name ENDPROCEDURE

Spot the Error

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

Question 1
A PROCEDURE Line(Size : INTEGER)
B FOR Count ← 1 TO Length
C OUTPUT "*"
D NEXT Count
E ENDPROCEDURE
Question 2
A PROCEDURE Greet(Name : STRING)
B OUTPUT "Hello "
C OUTPUT Name
D ENDFUNCTION
Question 3
A PROCEDURE ShowTotal(Cost, REAL)
B OUTPUT "Total: ", Cost
C ENDPROCEDURE
Question 4
A PROCEDURE Box(Side : INTEGER)
B DECLARE Area : INTEGER
C Area ← Side * Side
D OUTPUT Size
E ENDPROCEDURE
Question 5
A PROCEDURE Stars(Num : INTEGER)
B FOR Count ← 1 TO Num
C OUTPUT "*
D NEXT Count
E ENDPROCEDURE

Answer Key

Defining a procedure with one parameter
Section A: Quick Questions
Q1
A — PROCEDURE Line(Size : INTEGER)
Q2
A — PROCEDURE Greet(Name : STRING)
Q3
B — In brackets straight after the procedure name
Q4
A — ENDPROCEDURE
Q5
B — OUTPUT "Hello ", Name
Section B: Match the Pairs
Q1
PROCEDURE Line(Size : INTEGER) → Starts a procedure called Line with one parameter, Size, which must hold a whole number
Q2
PROCEDURE ShowName(Name : STRING) → Starts a procedure with one parameter, Name, that holds text
Q3
A parameter is used inside the procedure body like a variable, for example to output its value → OUTPUT Size
Q4
A procedure with a REAL parameter ends with ENDPROCEDURE after its body → PROCEDURE ShowPrice(Price : REAL) OUTPUT Price ENDPROCEDURE
Q5
PROCEDURE Line(Size INTEGER) → The colon is missing between the parameter name and its data type. It should be Size : INTEGER.
Q6
PROCEDURE Line(INTEGER : Size) → The identifier and data type are the wrong way round. The identifier comes first, then the colon, then the type: Size : INTEGER.
Section C: Definitions
Q1
PROCEDURE Line(Size : INTEGER) — Defines a procedure with one parameter. In the brackets after the name, write the parameter identifier, a colon, then its data type. Size is used inside the body.
Section D: Fill in the Blanks
Q1
PROCEDURE Line(Size : INTEGER) OUTPUT Size ENDPROCEDURE
Q2
PROCEDURE Greet(Name : STRING) OUTPUT "Hello ", Name ENDPROCEDURE
Q3
PROCEDURE ShowPrice(Cost : REAL) OUTPUT Cost ENDPROCEDURE
Q4
PROCEDURE Line(Size : INTEGER) OUTPUT Size ENDPROCEDURE
Q5
PROCEDURE Greet(Name : STRING) OUTPUT Name ENDPROCEDURE
Section E: Spot the Error
Q1
B — The parameter is called Size, so the loop must use Size. Length is not defined anywhere. It should be FOR Count ← 1 TO Size.
Q2
D — A procedure must finish with ENDPROCEDURE. ENDFUNCTION is used to close a function.
Q3
A — A parameter is written as identifier, colon, data type. The comma should be a colon: ShowTotal(Cost : REAL).
Q4
D — The parameter is named Side, so Size does not exist in this procedure. The line should output the calculated value: OUTPUT Area.
Q5
C — The string is missing its closing quotation mark. It should be OUTPUT "*".