Writing a main program that calls one procedure per sub-problem

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

Writing a main program that calls one procedure per sub-problem

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A structure diagram has three sub-problems: GetInputs, Calculate and ShowResults. Which main program matches it?
A CALL GetInputs CALL ShowResults CALL Calculate
B CALL GetInputs CALL Calculate CALL ShowResults
2. Which line correctly runs a procedure called Calculate from the main program?
A Calculate CALL
B CALL Calculate
3. What should a main program in a decomposed solution contain?
A A short list of CALL statements, one for each sub-problem
B All the INPUT, calculation and OUTPUT code written out in full
4. Why must CALL GetInputs come before CALL Calculate?
A Calculate needs the input values, so they must be collected first
B Pseudocode always runs procedures in alphabetical order
5. A structure diagram has four sub-problems under the top-level box. How many CALL lines should the main program have?
A Four, one for each sub-problem
B One, because there is only one main program

Match the Pairs

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

Left columnRight column
1CALL GetInputs ARuns the procedure that handles the input sub-problem, so the main program holds no input detail
2CALL ShowResults BThe calls are in the wrong order. The results are shown before they are calculated and before the inputs are entered.
3A main program is a short list of CALL statements, one per sub-problem, with no detail inside it CRuns the output sub-problem as the last step of the main program, after the calculation is done
4The order of the calls matters: inputs must be collected before they are used in a calculation DThe main program contains detail (INPUT Length) instead of only CALL statements. The detail belongs inside the GetInputs procedure.
5CALL ShowResults CALL Calculate CALL GetInputs ECALL GetInputs CALL Calculate
6CALL GetInputs INPUT Length CALL Calculate CALL ShowResults FCALL GetInputs CALL Calculate CALL ShowResults

Definitions

CALL

Fill in the Blanks

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

1.
____ GetInputs CALL Calculate CALL ShowResults
2.
CALL GetInputs CALL _________ CALL ShowResults
3.
CALL GetInputs CALL Calculate CALL ___________
4.
CALL _________ CALL Calculate CALL ShowResults
5.
CALL GetInputs CALL Calculate ____ ShowResults

Spot the Error

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

Question 1
A GetInputs
B CALL Calculate
C CALL ShowResults
Question 2
A CALL GetInputs
B CALL Calculate
C CALL CheckResult
D call ShowResults
Question 3
A CALL GetInputs
B CALL Calculate
C CALL ShowResults
D Total ← Score1 + Score2
Question 4
A CALL ShowResults
B CALL Calculate
C CALL ShowResults
Question 5
A CALL GetInputs
B RUN Calculate
C CALL ShowResults

Answer Key

Writing a main program that calls one procedure per sub-problem
Section A: Quick Questions
Q1
B — CALL GetInputs CALL Calculate CALL ShowResults
Q2
B — CALL Calculate
Q3
A — A short list of CALL statements, one for each sub-problem
Q4
A — Calculate needs the input values, so they must be collected first
Q5
A — Four, one for each sub-problem
Section B: Match the Pairs
Q1
CALL GetInputs → Runs the procedure that handles the input sub-problem, so the main program holds no input detail
Q2
CALL ShowResults → Runs the output sub-problem as the last step of the main program, after the calculation is done
Q3
A main program is a short list of CALL statements, one per sub-problem, with no detail inside it → CALL GetInputs CALL Calculate CALL ShowResults
Q4
The order of the calls matters: inputs must be collected before they are used in a calculation → CALL GetInputs CALL Calculate
Q5
CALL ShowResults CALL Calculate CALL GetInputs → The calls are in the wrong order. The results are shown before they are calculated and before the inputs are entered.
Q6
CALL GetInputs INPUT Length CALL Calculate CALL ShowResults → The main program contains detail (INPUT Length) instead of only CALL statements. The detail belongs inside the GetInputs procedure.
Section C: Definitions
Q1
CALL — Runs a procedure. A main program is a short list of CALL lines, one per sub-problem from the structure diagram, in the right order, with no detail inside it.
Section D: Fill in the Blanks
Q1
CALL GetInputs CALL Calculate CALL ShowResults
Q2
CALL GetInputs CALL Calculate CALL ShowResults
Q3
CALL GetInputs CALL Calculate CALL ShowResults
Q4
CALL GetInputs CALL Calculate CALL ShowResults
Q5
CALL GetInputs CALL Calculate CALL ShowResults
Section E: Spot the Error
Q1
A — Each sub-problem in the main program needs the keyword CALL. It should be CALL GetInputs, otherwise the procedure is not run.
Q2
D — Pseudocode keywords must be written in capitals. The line should be CALL ShowResults.
Q3
D — The main program must contain no detail. The calculation belongs inside the Calculate procedure, so this line should be CALL SaveScores, which runs the last sub-problem.
Q4
A — The order of the calls matters. Results cannot be shown before the data is input and processed. Line 1 should be CALL GetInputs.
Q5
B — Pseudocode uses CALL to run a procedure, not RUN. The line should be CALL Calculate.