AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Two languages, one plan

Week 27 · Unit 7.6: Sequencing and pattern recognition · 3 lessons
3

Plan it in pieces

Computing 7: Unit 7.6, pp. 182–224
GoalUse a sub-routine in a flowchart and write a test plan before you write the program.
New words
sub-routine · a named mini-program kept apart from the main program and run by using its nameproject plan · a plan that says what a program must do, its sections, inputs and outputs, and how it will be testedtest plan · a table of tests with the test data, the expected outcome and the pass or fail result
Explanation

A sub-routine is a named mini-program that is kept apart from the main program. The main program runs it just by using its name, and then carries on. In a flowchart the real symbol is a box with double lines at the sides. In these drawings it is a box that says run sub-routine. Sub-routines make a flowchart shorter and easier to read, and each small section can be tested on its own. Before writing code, the programmer makes a project plan and asks questions. Which button is the input? What is the output? What happens when no button is pressed? Then a test plan is written, and each expected outcome is decided before the test is run. The same test plan is used again later to test the finished program.

StartIs button B pressed?yesnorun sub-routine: WelcomeDisplay a clear screenEnd
Worked examples
StartDisplay a heartwait 1 secondDisplay a clear screenEnd
This is the sub-routine called Welcome. The main flowchart runs it when B is pressed. A lamp over a shop door shows a heart for 1 second and then clears the screen.
TestWhat is testedTest dataExpected outcomePass/fail
1B starts WelcomeB presseda heart is shownpass
2Welcome endsB pressedafter 1 second the screen is clearpass
3Idle stateno button pressedthe screen is clearpass
This is the test plan for the shop-door lamp. The expected outcomes were written before testing. After testing, the results were written in the last column.
Part of the planDiego’s answer
What it must doshow a welcome light when a visitor presses the button
Sectionsthe main program and the sub-routine Welcome
Input and outputinput: button B; output: the heart on the lights
How to testthe three tests in the test plan
Use the resultsfix any failed test, then ask the shop owner what to change
The project plan breaks the job into smaller questions. Here is Diego’s plan for the lamp.
Class activity

Flowchart relay (no computer). Work in a team of three. Player 1 draws a main flowchart that runs a sub-routine when A is pressed and otherwise shows a clear screen. Player 2 draws the sub-routine: two pictures with waits. Player 3 writes a test plan with three tests, and decides the expected outcomes before anyone tests. Then Player 1 plays the button presses while Players 2 and 3 follow the flowchart and mark pass or fail.

Practice
1
Follow this flowchart. (a) Which input runs the sub-routine Sunset? (b) What happens when both buttons are pressed together? Explain. (c) What happens when no button is pressed?
StartIs button A pressed?yesnorun sub-routine: SunriseIs button B pressed?yesnorun sub-routine: SunsetDisplay a clear screenEnd
2
Sunrise shows a small diamond for 1 second, a diamond for 1 second and then clears the screen. Sunset shows a diamond for 1 second, a small diamond for 1 second and then clears the screen. Copy this test plan for the flowchart in question 1 and write the three expected outcomes by hand.
TestTest dataExpected outcomePass/fail
1A pressed?
2B pressed?
3A and B pressed together?
3
Ayla is making a night-light for her little brother. Pressing B starts a pattern. Write the first three questions for her project plan.
4
Explain two reasons why a flowchart with sub-routines is easier to understand and test.