Using a function call in OUTPUT

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

Using a function call in OUTPUT

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line displays the value returned by the function SumSquare?
A OUTPUT SumSquare
B OUTPUT SumSquare(10, 20)
2. What happens first when this line runs? OUTPUT SumSquare(10, 20)
A The function runs and returns a value
B OUTPUT displays the words SumSquare(10, 20)
3. Which statement shows text and a function result together?
A OUTPUT "Sum of squares = ", SumSquare(10, 20)
B OUTPUT "Sum of squares = " SumSquare(10, 20)
4. Which is the correct way to put a function call inside OUTPUT?
A OUTPUT CALL SumSquare(10, 20)
B OUTPUT SumSquare(10, 20)
5. A function Double(n) RETURNs n * 2. What does OUTPUT "Result = ", Double(4) display?
A Result = 8
B Result = Double(4)

Match the Pairs

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

Left columnRight column
1OUTPUT SumSquare(10, 20) ATotal ← SumSquare(10, 20) OUTPUT Total
2OUTPUT "Sum of squares = ", SumSquare(10, 20) BThere is no comma between the text and the function call, so the two items are not separated correctly
3A function call can be placed straight into OUTPUT, so there is no need to store the result first CDisplays the text first, then the value returned by the function call, on the same line
4A function result can be stored in a variable, and then the variable is displayed with OUTPUT DThe function name is written without brackets and arguments, so the function is not called
5OUTPUT "Sum of squares = " SumSquare(10, 20) ECalls the function SumSquare with 10 and 20, then displays the value it returns
6OUTPUT "Sum of squares = ", SumSquare FOUTPUT SumSquare(a, b)

Definitions

OUTPUT SumSquare(10, 20)

Fill in the Blanks

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

1.
______ SumSquare(10, 20)
2.
OUTPUT "Sum of squares = ", _________(10, 20)
3.
Total ← SumSquare(10, 20) OUTPUT "Sum of squares = ", _____
4.
a ← 3 OUTPUT "Sum of squares = ", SumSquare(_, 4)
5.
b ← 20 OUTPUT "Sum of squares = ", SumSquare(10, _)

Spot the Error

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

Question 1
A OUTPUT "Sum = ", Add(10, 20
B OUTPUT "Next = ", Add(3, 4)
C OUTPUT "Last = ", Add(5, 6)
Question 2
A DECLARE Total : INTEGER
B Total ← CALL SumSquare(10, 20)
C OUTPUT "Sum = ", Total
Question 3
A FUNCTION Ten() RETURNS INTEGER
B RETURN 10
C ENDFUNCTION
D OUTPUT "Ten = ", Ten
Question 4
A Len ← 4
B Wid ← 6
C Size ← Area(Len, Wid)
D OUTPUT "Area = ", "Size"
Question 5
A DECLARE N : INTEGER
B N ← 7
C OUTPUT "Cube = , Cube(N)

Answer Key

Using a function call in OUTPUT
Section A: Quick Questions
Q1
B — OUTPUT SumSquare(10, 20)
Q2
A — The function runs and returns a value
Q3
A — OUTPUT "Sum of squares = ", SumSquare(10, 20)
Q4
B — OUTPUT SumSquare(10, 20)
Q5
A — Result = 8
Section B: Match the Pairs
Q1
OUTPUT SumSquare(10, 20) → Calls the function SumSquare with 10 and 20, then displays the value it returns
Q2
OUTPUT "Sum of squares = ", SumSquare(10, 20) → Displays the text first, then the value returned by the function call, on the same line
Q3
A function call can be placed straight into OUTPUT, so there is no need to store the result first → OUTPUT SumSquare(a, b)
Q4
A function result can be stored in a variable, and then the variable is displayed with OUTPUT → Total ← SumSquare(10, 20) OUTPUT Total
Q5
OUTPUT "Sum of squares = " SumSquare(10, 20) → There is no comma between the text and the function call, so the two items are not separated correctly
Q6
OUTPUT "Sum of squares = ", SumSquare → The function name is written without brackets and arguments, so the function is not called
Section C: Definitions
Q1
OUTPUT SumSquare(10, 20) — Puts a function call inside OUTPUT. The function runs first, then the value it RETURNs is displayed. Text can be added: OUTPUT "Sum = ", SumSquare(10, 20).
Section D: Fill in the Blanks
Q1
OUTPUT SumSquare(10, 20)
Q2
OUTPUT "Sum of squares = ", SumSquare(10, 20)
Q3
Total ← SumSquare(10, 20) OUTPUT "Sum of squares = ", Total
Q4
a ← 3 OUTPUT "Sum of squares = ", SumSquare(a, 4)
Q5
b ← 20 OUTPUT "Sum of squares = ", SumSquare(10, b)
Section E: Spot the Error
Q1
A — The function call is missing its closing bracket. It should be OUTPUT "Sum = ", Add(10, 20).
Q2
B — CALL is only used for procedures. A function is called by writing its name and arguments, so it should be Total ← SumSquare(10, 20).
Q3
D — A function call needs brackets, even when there are no parameters. Without them Ten is not called, so it should be Ten().
Q4
D — Quotes make Size a piece of text, so the word Size would be displayed. Without quotes, OUTPUT displays the value stored in the variable: OUTPUT "Area = ", Size.
Q5
C — The closing quote after the text is missing, so the function call becomes part of the string and is never run. It should be OUTPUT "Cube = ", Cube(N).