Procedures with two or three parameters

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

Procedures with two or three parameters

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which procedure header is written correctly for two parameters?
A PROCEDURE Show(Name : STRING Age : INTEGER)
B PROCEDURE Show(Name : STRING, Age : INTEGER)
2. Which call correctly matches PROCEDURE Show(Name : STRING, Age : INTEGER)?
A CALL Show(14, "Sam")
B CALL Show("Sam", 14)
3. How many values must a call supply for PROCEDURE Show(Name : STRING, Age : INTEGER)?
A Two: one for each parameter
B One: just the first parameter
4. Which is correct for a procedure with three parameters?
A PROCEDURE Score(Name : STRING, Maths : INTEGER, English : INTEGER)
B PROCEDURE Score(Name, Maths, English : STRING, INTEGER, INTEGER)
5. Given PROCEDURE Show(Name : STRING, Age : INTEGER), what does the call CALL Show("Sam", 14) do?
A Name is "Sam" and Age is 14 inside the procedure
B Name is 14 and Age is "Sam" inside the procedure

Match the Pairs

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

Left columnRight column
1PROCEDURE Show(Name : STRING, Age : INTEGER) APROCEDURE Report(Name : STRING, Age : INTEGER, Score : REAL)
2CALL Show("Sam", 14) BThe comma between the parameters is missing. It should be PROCEDURE Show(Name : STRING, Age : INTEGER).
3A procedure can have three parameters, each with its own data type, separated by commas CCalls the procedure with two values: "Sam" goes to Name and 14 goes to Age, matched by position
4The call must give one value for each parameter in the same order as the header, so the first value is a STRING and the second is an INTEGER DThe values are in the wrong order. 14 is passed to Name (a STRING) and "Sam" to Age (an INTEGER), so the types do not match. It should be CALL Show("Sam", 14).
5CALL Show(14, "Sam") EDefines a procedure with two parameters separated by a comma, each with its own data type
6PROCEDURE Show(Name : STRING Age : INTEGER) FCALL Show("Mia", 15)

Definitions

PROCEDURE Show(Name : STRING, Age : INTEGER)

Fill in the Blanks

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

1.
_________ Show(Name : STRING, Age : INTEGER)
2.
PROCEDURE Show(Name : STRING, Age : _______)
3.
PROCEDURE Show(Name : STRING, Age : INTEGER) ____ Show("Sam", 14)
4.
PROCEDURE Box(W : REAL, H : REAL, D : ____)
5.
PROCEDURE Show(Name : STRING, Age : INTEGER) Years ← 14 CALL Show("Sam", _____)

Spot the Error

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

Question 1
A PROCEDURE Pay(N:STRING;P:REAL)
B OUTPUT N, " owes ", P
C ENDPROCEDURE
D CALL Pay("Sam", 4.5)
Question 2
A PROCEDURE Area(L:REAL,W:REAL)
B OUTPUT L * H
C ENDPROCEDURE
D CALL Area(2.5, 4)
Question 3
A PROCEDURE Diff(A:REAL,B)
B OUTPUT A - B
C ENDPROCEDURE
D CALL Diff(9, 2.5)
Question 4
A PROCEDURE Id(I:CHAR,A:INTEGER)
B OUTPUT "Initial: ", I
C OUTPUT "Next age: ", I + 1
D ENDPROCEDURE
E CALL Id('S', 14)
Question 5
A PROCEDURE Sum(A:REAL,B:REAL)
B OUTPUT A + B
C ENDFUNCTION
D CALL Sum(1.5, 4.5)

Answer Key

Procedures with two or three parameters
Section A: Quick Questions
Q1
B — PROCEDURE Show(Name : STRING, Age : INTEGER)
Q2
B — CALL Show("Sam", 14)
Q3
A — Two: one for each parameter
Q4
A — PROCEDURE Score(Name : STRING, Maths : INTEGER, English : INTEGER)
Q5
A — Name is "Sam" and Age is 14 inside the procedure
Section B: Match the Pairs
Q1
PROCEDURE Show(Name : STRING, Age : INTEGER) → Defines a procedure with two parameters separated by a comma, each with its own data type
Q2
CALL Show("Sam", 14) → Calls the procedure with two values: "Sam" goes to Name and 14 goes to Age, matched by position
Q3
A procedure can have three parameters, each with its own data type, separated by commas → PROCEDURE Report(Name : STRING, Age : INTEGER, Score : REAL)
Q4
The call must give one value for each parameter in the same order as the header, so the first value is a STRING and the second is an INTEGER → CALL Show("Mia", 15)
Q5
CALL Show(14, "Sam") → The values are in the wrong order. 14 is passed to Name (a STRING) and "Sam" to Age (an INTEGER), so the types do not match. It should be CALL Show("Sam", 14).
Q6
PROCEDURE Show(Name : STRING Age : INTEGER) → The comma between the parameters is missing. It should be PROCEDURE Show(Name : STRING, Age : INTEGER).
Section C: Definitions
Q1
PROCEDURE Show(Name : STRING, Age : INTEGER) — Several parameters are separated by commas, each with its own data type. A call gives one value for each, in the same order, such as CALL Show("Sam", 14).
Section D: Fill in the Blanks
Q1
PROCEDURE Show(Name : STRING, Age : INTEGER)
Q2
PROCEDURE Show(Name : STRING, Age : INTEGER)
Q3
PROCEDURE Show(Name : STRING, Age : INTEGER) CALL Show("Sam", 14)
Q4
PROCEDURE Box(W : REAL, H : REAL, D : REAL)
Q5
PROCEDURE Show(Name : STRING, Age : INTEGER) Years ← 14 CALL Show("Sam", Years)
Section E: Spot the Error
Q1
A — Parameters must be separated by commas, not a semicolon. The header should be PROCEDURE Pay(N:STRING,P:REAL).
Q2
B — H is not a parameter of Area. The procedure only has L and W, so the body must use L * W.
Q3
A — Each parameter needs its own data type. B has no type, so it should be B:REAL.
Q4
C — I is a CHAR, so you cannot add 1 to it. The age is in the INTEGER parameter A, so it should be A + 1.
Q5
C — A procedure with several parameters is still a procedure. It must end with ENDPROCEDURE, not ENDFUNCTION.