Matching argument values to parameter types and order

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

Matching argument values to parameter types and order

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. PROCEDURE Greet(Name : STRING, Age : INTEGER) Which call matches the parameters?
A CALL Greet("Sam", 15)
B CALL Greet(15, "Sam")
2. PROCEDURE Add(A : INTEGER, B : INTEGER) Which call has the right number of values?
A CALL Add(4, 5)
B CALL Add(4)
3. PROCEDURE ShowScore(Score : INTEGER) Which call is correct?
A CALL ShowScore(80, 90)
B CALL ShowScore(80)
4. PROCEDURE SetAge(Age : INTEGER) Which call passes the right data type?
A CALL SetAge(14)
B CALL SetAge("fourteen")
5. PROCEDURE SetCount(Count : INTEGER) Which call is valid?
A CALL SetCount(7.5)
B CALL SetCount(7)

Match the Pairs

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

Left columnRight column
1CALL ShowTotal("five", 3) // parameter 1 is INTEGER AError: the STRING "five" is passed to an INTEGER parameter, so the data type does not match.
2CALL Rectangle(5) // needs width, height BToo many values: three values are given for two parameters. Remove one value, for example CALL SetScore(10, 20).
3Values go to parameters in order, so the first value is given to the first parameter. For PROCEDURE Greet(Name : STRING, Age : INTEGER) this call is correct. CError: too few values, because the procedure has two parameters but the call gives only one.
4A REAL value such as 7.5 can only be passed to a parameter declared as REAL, so the parameter must be REAL, as in PROCEDURE ShowPrice(Price : REAL). DThe values are in the wrong order: 15 is passed to the STRING parameter and "Sam" to the INTEGER parameter. Swap them to CALL Greet("Sam", 15).
5CALL Greet(15, "Sam") // Greet(Name : STRING, Age : INTEGER) ECALL Greet("Sam", 15)
6CALL SetScore(10, 20, 30) // SetScore(A : INTEGER, B : INTEGER) FCALL ShowPrice(7.5)

Definitions

CALL Name(value1, value2)

Fill in the Blanks

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

1.
PROCEDURE Repeat(Times : _______) CALL Repeat(5)
2.
PROCEDURE Area(Len : INTEGER, Wide : ____) CALL Area(5, 2.5)
3.
PROCEDURE Show(Name : STRING, Age : INTEGER) ____ Show("Ann", 14)
4.
FUNCTION Cost(Qty : INTEGER, Price : ____) Total ← Cost(2, 1.5)
5.
PROCEDURE Score(Mark : INTEGER, Team : ______ ) CALL Score(80, "Red")

Spot the Error

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

Question 1
A // Show a number
B PROCEDURE Show(N: STRING)
C OUTPUT N
D ENDPROCEDURE
E CALL Show(42)
Question 2
A PROCEDURE Double(N: INTEGER)
B OUTPUT N * 2
C ENDPROCEDURE
D CALL Double("7")
Question 3
A // Show a grade, then a mark
B // Called as CALL Go('A', 7.5)
C PROCEDURE Go(N: REAL, C: CHAR)
D OUTPUT C, N
E ENDPROCEDURE
F CALL Go('A', 7.5)
Question 4
A PROCEDURE Half(N: INTEGER)
B OUTPUT N / 2
C ENDPROCEDURE
D CALL Half(7.5)
Question 5
A W ← 2.5
B H ← 4.0
C PROCEDURE Go(A: REAL)
D OUTPUT A * B
E ENDPROCEDURE
F CALL Go(W, H)

Answer Key

Matching argument values to parameter types and order
Section A: Quick Questions
Q1
A — CALL Greet("Sam", 15)
Q2
A — CALL Add(4, 5)
Q3
B — CALL ShowScore(80)
Q4
A — CALL SetAge(14)
Q5
B — CALL SetCount(7)
Section B: Match the Pairs
Q1
CALL ShowTotal("five", 3) // parameter 1 is INTEGER → Error: the STRING "five" is passed to an INTEGER parameter, so the data type does not match.
Q2
CALL Rectangle(5) // needs width, height → Error: too few values, because the procedure has two parameters but the call gives only one.
Q3
Values go to parameters in order, so the first value is given to the first parameter. For PROCEDURE Greet(Name : STRING, Age : INTEGER) this call is correct. → CALL Greet("Sam", 15)
Q4
A REAL value such as 7.5 can only be passed to a parameter declared as REAL, so the parameter must be REAL, as in PROCEDURE ShowPrice(Price : REAL). → CALL ShowPrice(7.5)
Q5
CALL Greet(15, "Sam") // Greet(Name : STRING, Age : INTEGER) → The values are in the wrong order: 15 is passed to the STRING parameter and "Sam" to the INTEGER parameter. Swap them to CALL Greet("Sam", 15).
Q6
CALL SetScore(10, 20, 30) // SetScore(A : INTEGER, B : INTEGER) → Too many values: three values are given for two parameters. Remove one value, for example CALL SetScore(10, 20).
Section C: Definitions
Q1
CALL Name(value1, value2) — Each value in a call must match its parameter in number, order and data type, so a STRING cannot go to an INTEGER parameter and values cannot be swapped or left out.
Section D: Fill in the Blanks
Q1
PROCEDURE Repeat(Times : INTEGER) CALL Repeat(5)
Q2
PROCEDURE Area(Len : INTEGER, Wide : REAL) CALL Area(5, 2.5)
Q3
PROCEDURE Show(Name : STRING, Age : INTEGER) CALL Show("Ann", 14)
Q4
FUNCTION Cost(Qty : INTEGER, Price : REAL) Total ← Cost(2, 1.5)
Q5
PROCEDURE Score(Mark : INTEGER, Team : STRING ) CALL Score(80, "Red")
Section E: Spot the Error
Q1
B — The call passes the whole number 42, so the parameter must be INTEGER. A STRING parameter does not match the INTEGER value in the call. It should be PROCEDURE Show(N: INTEGER).
Q2
D — "7" in quotes is a STRING, but the parameter N is an INTEGER. The value in the call must match the parameter's data type. It should be CALL Double(7).
Q3
C — The call passes the letter first and the number second, so the parameters must be in the same order. Here they are swapped, so 'A' would go to a REAL parameter. It should be PROCEDURE Go(C: CHAR, N: REAL).
Q4
A — The call passes 7.5, which is a REAL number with a decimal part. An INTEGER parameter cannot accept it. It should be PROCEDURE Half(N: REAL).
Q5
C — The call passes two values (W and H), so the procedure needs two parameters. With only one parameter there are too many values, and B is never defined. It should be PROCEDURE Go(A: REAL, B: REAL).