Pseudocode PROCEDURE ... ENDPROCEDURE and CALL

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

Pseudocode PROCEDURE ... ENDPROCEDURE and CALL

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly starts a procedure called ShowMenu that has no parameters?
A PROCEDURE ShowMenu()
B FUNCTION ShowMenu() RETURNS
2. Which keyword closes a procedure definition?
A ENDFUNCTION
B ENDPROCEDURE
3. How do you run a procedure called ShowMenu in the main program?
A CALL ShowMenu()
B RUN ShowMenu()
4. A procedure is written but the main program never contains a CALL to it. What happens?
A The procedure never runs
B The procedure runs automatically at the start
5. A structure diagram has three boxes below the top box: GetMarks, CalcAverage and ShowResult. How many procedures would you normally write?
A One, containing all the code
B Three, one per box

Match the Pairs

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

Left columnRight column
1PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE ADefines a procedure called ShowMenu with no parameters. Its block of code does not run yet.
2CALL ShowMenu() BRuns the procedure called ShowMenu from the main program.
3A procedure with no parameters is defined with empty brackets after its name and closed with ENDPROCEDURE. CPROCEDURE GetScores() INPUT Score ENDPROCEDURE
4A main program uses CALL once for each sub-problem box of the structure diagram, each box being a procedure. DCALL is missing, so this does not correctly run the procedure. It should be CALL ShowMenu().
5PROCEDURE ShowMenu() OUTPUT "1. Play" ENDFUNCTION EThe procedure is closed with ENDFUNCTION. A procedure must end with ENDPROCEDURE.
6ShowMenu() FCALL GetScores() CALL CalcAverage() CALL ShowResult()

Definitions

PROCEDURE Name() ... ENDPROCEDURE

Fill in the Blanks

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

1.
_________ ShowMenu() OUTPUT "1. Play" ENDPROCEDURE
2.
PROCEDURE ShowMenu() OUTPUT "1. Play" ____________
3.
OUTPUT "Start" ____ ShowMenu() OUTPUT "End"
4.
CALL ShowMenu() INPUT Choice CALL ________()
5.
PROCEDURE GetAge() _____ Age ENDPROCEDURE

Spot the Error

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

Question 1
A PROCEDURE ShowMenu()
B PRINT "1. Play"
C ENDPROCEDURE
D CALL ShowMenu()
Question 2
A FUNCTION Greet()
B OUTPUT "Hello"
C ENDPROCEDURE
D CALL Greet()
Question 3
A PROCEDURE ReadScore()
B INPUT Score
C ENDFUNCTION
D CALL ReadScore()
Question 4
A PROCEDURE Show Total()
B OUTPUT Total
C ENDPROCEDURE
D CALL ShowTotal()
Question 5
A PROCEDURE InputData()
B INPUT Age
C ENDPROCEDURE
D RUN InputData()

Answer Key

Pseudocode PROCEDURE ... ENDPROCEDURE and CALL
Section A: Quick Questions
Q1
A — PROCEDURE ShowMenu()
Q2
B — ENDPROCEDURE
Q3
A — CALL ShowMenu()
Q4
A — The procedure never runs
Q5
B — Three, one per box
Section B: Match the Pairs
Q1
PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE → Defines a procedure called ShowMenu with no parameters. Its block of code does not run yet.
Q2
CALL ShowMenu() → Runs the procedure called ShowMenu from the main program.
Q3
A procedure with no parameters is defined with empty brackets after its name and closed with ENDPROCEDURE. → PROCEDURE GetScores() INPUT Score ENDPROCEDURE
Q4
A main program uses CALL once for each sub-problem box of the structure diagram, each box being a procedure. → CALL GetScores() CALL CalcAverage() CALL ShowResult()
Q5
PROCEDURE ShowMenu() OUTPUT "1. Play" ENDFUNCTION → The procedure is closed with ENDFUNCTION. A procedure must end with ENDPROCEDURE.
Q6
ShowMenu() → CALL is missing, so this does not correctly run the procedure. It should be CALL ShowMenu().
Section C: Definitions
Q1
PROCEDURE Name() ... ENDPROCEDURE — Defines a named block of pseudocode for one sub-problem. It does not return a value. The block only runs when you write CALL Name() in the main program.
Section D: Fill in the Blanks
Q1
PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE
Q2
PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE
Q3
OUTPUT "Start" CALL ShowMenu() OUTPUT "End"
Q4
CALL ShowMenu() INPUT Choice CALL ShowMenu()
Q5
PROCEDURE GetAge() INPUT Age ENDPROCEDURE
Section E: Spot the Error
Q1
B — Cambridge pseudocode uses OUTPUT to display text, not PRINT. The line should be OUTPUT "1. Play".
Q2
A — The block ends with ENDPROCEDURE, so it must start with PROCEDURE, not FUNCTION. The line should be PROCEDURE Greet().
Q3
C — A PROCEDURE must be closed with ENDPROCEDURE. ENDFUNCTION is only used to close a FUNCTION.
Q4
A — A procedure name cannot contain a space. It should be one word, PROCEDURE ShowTotal(), so that CALL ShowTotal() can find it.
Q5
D — A procedure is run with the keyword CALL, not RUN. The line should be CALL InputData().