Procedure

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

Procedure

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement describes a procedure?
A A named subroutine that always returns a value to the caller
B A named subroutine that does a job and does not return a value
2. Which is the correct way to call a procedure named ShowMenu?
A total ← CALL ShowMenu()
B CALL ShowMenu()
3. Which is a good job for a procedure?
A Outputting a welcome message on the screen
B Working out the area of a rectangle and handing it back
4. True or false: a procedure must have at least one parameter.
A False - a procedure can have parameters or none
B True - a procedure always needs a parameter
5. Which header defines a procedure with one parameter?
A PROCEDURE Greet(Name : STRING)
B PROCEDURE Greet(Name : STRING) RETURNS STRING

Match the Pairs

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

Left columnRight column
1PROCEDURE ShowLine() OUTPUT "-----" ENDPROCEDURE AA procedure must not contain RETURN with a value because it does not return a value. Remove the RETURN line.
2CALL ShowLine() BENDPROCEDURE
3A procedure can have a parameter so it can do its job with a value passed in CPROCEDURE Greet(Name : STRING)
4A procedure does not return a value, so it ends with ENDPROCEDURE and has no RETURN DA procedure returns no value, so its result cannot be stored in a variable. It should be called with CALL ShowLine().
5x ← ShowLine() EA complete statement that runs the procedure ShowLine
6PROCEDURE ShowLine() OUTPUT "-----" RETURN 5 ENDPROCEDURE FA procedure with no parameters that does a job (outputs a line) and does not return a value

Definitions

PROCEDURE

Fill in the Blanks

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

1.
_________ ShowMenu() OUTPUT "Menu" ENDPROCEDURE
2.
PROCEDURE ShowMenu() OUTPUT "Menu" ____________
3.
____ ShowMenu()
4.
PROCEDURE Greet(Name : ______) OUTPUT "Hello ", Name ENDPROCEDURE
5.
PROCEDURE Greet(Name : STRING) OUTPUT "Hi ", ____ ENDPROCEDURE

Spot the Error

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

Question 1
A PROCEDURE ShowTitle()
B OUTPUT "Quiz Time"
C ENDPROCEDURE
D ShowTitle()
Question 2
A FUNCTION ShowLine()
B OUTPUT "----------"
C ENDPROCEDURE
D CALL ShowLine()
Question 3
A PROCEDURE Greet(Who : STRING)
B OUTPUT "Hello ", Who
C ENDFUNCTION
D CALL Greet("Sam")
Question 4
A PROCEDURE ShowSum(N : INTEGER)
B RETURN N + 10
C ENDPROCEDURE
D CALL ShowSum(5)
Question 5
A PROCEDURE Show(N : INTEGER)
B OUTPUT "Number"
C OUTPUT M
D ENDPROCEDURE
E CALL Show(7)

Answer Key

Procedure
Section A: Quick Questions
Q1
B — A named subroutine that does a job and does not return a value
Q2
B — CALL ShowMenu()
Q3
A — Outputting a welcome message on the screen
Q4
A — False - a procedure can have parameters or none
Q5
A — PROCEDURE Greet(Name : STRING)
Section B: Match the Pairs
Q1
PROCEDURE ShowLine() OUTPUT "-----" ENDPROCEDURE → A procedure with no parameters that does a job (outputs a line) and does not return a value
Q2
CALL ShowLine() → A complete statement that runs the procedure ShowLine
Q3
A procedure can have a parameter so it can do its job with a value passed in → PROCEDURE Greet(Name : STRING)
Q4
A procedure does not return a value, so it ends with ENDPROCEDURE and has no RETURN → ENDPROCEDURE
Q5
x ← ShowLine() → A procedure returns no value, so its result cannot be stored in a variable. It should be called with CALL ShowLine().
Q6
PROCEDURE ShowLine() OUTPUT "-----" RETURN 5 ENDPROCEDURE → A procedure must not contain RETURN with a value because it does not return a value. Remove the RETURN line.
Section C: Definitions
Q1
PROCEDURE — A named subroutine that does a job, like outputting a line, but does not return a value. It is called as a full statement and can have parameters or none.
Section D: Fill in the Blanks
Q1
PROCEDURE ShowMenu() OUTPUT "Menu" ENDPROCEDURE
Q2
PROCEDURE ShowMenu() OUTPUT "Menu" ENDPROCEDURE
Q3
CALL ShowMenu()
Q4
PROCEDURE Greet(Name : STRING) OUTPUT "Hello ", Name ENDPROCEDURE
Q5
PROCEDURE Greet(Name : STRING) OUTPUT "Hi ", Name ENDPROCEDURE
Section E: Spot the Error
Q1
D — A procedure is called as a complete statement using CALL. It should be CALL ShowTitle().
Q2
A — This subroutine only outputs a line and returns no value, so it is a procedure. It must start with PROCEDURE to match ENDPROCEDURE.
Q3
C — A procedure must be closed with ENDPROCEDURE, not ENDFUNCTION.
Q4
B — A procedure does not return a value, so it cannot use RETURN. It should do its job with OUTPUT N + 10.
Q5
C — The procedure only knows its parameter N. M has not been declared, so it should be OUTPUT N.