Turning a structure diagram into pseudocode

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

Turning a structure diagram into pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A structure diagram has a box called 'Get Marks'. What is the best way to turn this box into pseudocode?
A PROCEDURE GetMarks() ... ENDPROCEDURE
B PROCEDURE x() ... ENDPROCEDURE
2. A box in the structure diagram has three sub-boxes. How does its pseudocode run the sub-boxes?
A It copies all the sub-box code inside itself
B It uses three CALL statements, one per sub-box
3. Which box in a structure diagram becomes a routine that contains the real steps (INPUT, calculations, OUTPUT)?
A The top box that has sub-boxes under it
B A bottom-level box with no sub-boxes
4. The top box 'Run Quiz' has sub-boxes 'Ask Question' and 'Show Score'. Which is the correct pseudocode?
A PROCEDURE RunQuiz() CALL AskQuestion() CALL ShowScore() ENDPROCEDURE
B PROCEDURE RunQuiz() AskQuestion ShowScore ENDPROCEDURE
5. After converting a structure diagram, you find one box has no matching PROCEDURE or FUNCTION. What should you do?
A Write a subroutine for that box so every box has code
B Ignore it because the other boxes are enough

Match the Pairs

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

Left columnRight column
1PROCEDURE GetMarks() APROCEDURE Main() CALL GetMarks() CALL Calculate() CALL ShowResult() ENDPROCEDURE
2CALL GetMarks() BThe sub-box is run without the CALL keyword. A procedure must be run with CALL GetMarks().
3A box at the top of a structure diagram with three sub-boxes becomes a routine that makes three CALL statements CFUNCTION Average(Total : INTEGER) RETURNS REAL RETURN Total / 3 ENDFUNCTION
4A bottom-level box that works out and gives back a value becomes a FUNCTION that RETURNS it DA bottom-level box called Get Marks becomes a procedure with the same name
5PROCEDURE Main() CALL GetMarks() ENDPROCEDURE // the diagram also has Show Result EA parent box runs its sub-box by calling the sub-box's procedure
6PROCEDURE Main() GetMarks() ENDPROCEDURE FThe box Show Result has no CALL statement in Main, so one box has no code. Every box in the diagram must be checked and given code.

Definitions

PROCEDURE

Fill in the Blanks

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

1.
_________ ShowMenu() OUTPUT "Menu" ENDPROCEDURE
2.
PROCEDURE RunGame() ____ GetName() ENDPROCEDURE
3.
PROCEDURE _________() OUTPUT "Score: ", Score ENDPROCEDURE
4.
________ CalcTotal() RETURNS INTEGER RETURN Price * Qty ENDFUNCTION
5.
PROCEDURE SaveData() OUTPUT "Saved" ____________

Spot the Error

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

Question 1
A PROCEDURE SoundAlarm()
B OUTPUT "Alarm!"
C ENDPROCEDURE
D CALL SoundAlarms()
Question 2
A FUNCTION Main()
B CALL ReadTemp()
C CALL CheckTemp()
D ENDPROCEDURE
Question 3
A PROCEDURE RunShop()
B ScanItem()
C CALL PrintBill()
D ENDPROCEDURE
Question 4
A FUNCTION Sum() RETURNS INTEGER
B Total ← Maths + English
C OUTPUT Total
D ENDFUNCTION
Question 5
A PROCEDURE Main()
B CALL GetMarks()
C Total ← CALL Sum()
D CALL ShowTotal()
E ENDPROCEDURE

Answer Key

Turning a structure diagram into pseudocode
Section A: Quick Questions
Q1
A — PROCEDURE GetMarks() ... ENDPROCEDURE
Q2
B — It uses three CALL statements, one per sub-box
Q3
B — A bottom-level box with no sub-boxes
Q4
A — PROCEDURE RunQuiz() CALL AskQuestion() CALL ShowScore() ENDPROCEDURE
Q5
A — Write a subroutine for that box so every box has code
Section B: Match the Pairs
Q1
PROCEDURE GetMarks() → A bottom-level box called Get Marks becomes a procedure with the same name
Q2
CALL GetMarks() → A parent box runs its sub-box by calling the sub-box's procedure
Q3
A box at the top of a structure diagram with three sub-boxes becomes a routine that makes three CALL statements → PROCEDURE Main() CALL GetMarks() CALL Calculate() CALL ShowResult() ENDPROCEDURE
Q4
A bottom-level box that works out and gives back a value becomes a FUNCTION that RETURNS it → FUNCTION Average(Total : INTEGER) RETURNS REAL RETURN Total / 3 ENDFUNCTION
Q5
PROCEDURE Main() CALL GetMarks() ENDPROCEDURE // the diagram also has Show Result → The box Show Result has no CALL statement in Main, so one box has no code. Every box in the diagram must be checked and given code.
Q6
PROCEDURE Main() GetMarks() ENDPROCEDURE → The sub-box is run without the CALL keyword. A procedure must be run with CALL GetMarks().
Section C: Definitions
Q1
PROCEDURE — Each box in a structure diagram becomes a PROCEDURE or FUNCTION named after the box. A box with sub-boxes uses CALL statements to run them. Check that every box has code.
Section D: Fill in the Blanks
Q1
PROCEDURE ShowMenu() OUTPUT "Menu" ENDPROCEDURE
Q2
PROCEDURE RunGame() CALL GetName() ENDPROCEDURE
Q3
PROCEDURE ShowScore() OUTPUT "Score: ", Score ENDPROCEDURE
Q4
FUNCTION CalcTotal() RETURNS INTEGER RETURN Price * Qty ENDFUNCTION
Q5
PROCEDURE SaveData() OUTPUT "Saved" ENDPROCEDURE
Section E: Spot the Error
Q1
D — The box name becomes the subroutine name, so the CALL must match it exactly. The procedure is SoundAlarm, so the line should be CALL SoundAlarm().
Q2
A — The top box only calls its sub-boxes and returns no value, so it is a PROCEDURE, which also matches ENDPROCEDURE. The line should be PROCEDURE Main().
Q3
B — A box above other boxes runs its sub-boxes using CALL statements. The line should be CALL ScanItem().
Q4
C — A box that becomes a FUNCTION must send its answer back with RETURN. It should be RETURN Total, not OUTPUT Total.
Q5
C — CALL is only used to run a PROCEDURE. A FUNCTION is used inside an expression, so the line should be Total ← Sum().