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

Term 1 round-up

Week 11 · Review: Term 1 · 3 lessons
2

Review: choices and sub-routines

Computing 7: Units 7.1–7.2, pp. 8–81
GoalTrace flowcharts that choose and call sub-routines, pick comparison operators and test the boundary of a condition.
New words
selection · a choice in an algorithm: the answer to a yes/no question decides which steps are followedcomparison operator · a symbol such as <, <=, >, >=, == or != that compares two valuesboundary value · test data exactly on the edge of a condition, such as 30 for bill >= 30sub-routine · a named mini-program that the main program can run again and again
Explanation

A flowchart uses a diamond for selection. The condition inside the diamond is true or false, and only one branch is followed on each run. Sequence means that steps follow each other in a row. The operators < and > leave out the number itself, but <= and >= include it, so a small change of operator changes the answer at the boundary. That is why a good test plan has a test on the boundary and one on each side of it. A sub-routine is drawn in a main flowchart as a box that runs it, and the real symbol is a box with double lines at the sides. When the sub-routine has finished, the main flowchart carries on with the next step. A flowchart with sub-routines is shorter and easier to test, because each part can be checked on its own.

OperatorMeansIs the number itself included?
<less thanno
<=less than or equal toyes
>greater thanno
>=greater than or equal toyes
==equal toonly that number
!=not equal toevery number except that one
Worked examples
StartINPUT priceINPUT kgbill = price * kgbill >= 30?yesnoOUTPUT "Free delivery"OUTPUT "Delivery costs 4"End
A fruit stall gives free delivery when the bill is 30 or more. The flowchart has a sequence of three steps and then one selection. Trace price = 6 and kg = 5: the bill is 30, the condition bill >= 30 is true, so it outputs Free delivery.
TestTest dataExpected outcomeActual outcomePass/fail
1price = 4, kg = 7 (bill 28)Delivery costs 4Delivery costs 4pass
2price = 6, kg = 5 (bill 30)Free deliveryDelivery costs 4fail
3price = 9, kg = 4 (bill 36)Free deliveryFree deliverypass
4price = 3, kg = 0 (bill 0)Delivery costs 4Delivery costs 4pass
This test plan was used on a faulty copy of the stall flowchart whose diamond says bill > 30. The expected outcomes were worked out by hand from the rules of the stall. Test 2 sits on the boundary and fails, so only a boundary test finds this bug.
StartINPUT rainrain > 10?yesnorun: close_windowsrun: open_windowsEnd
A flowchart can choose which sub-routine to run. The sub-routine close_windows outputs Close the windows and Bring the washing in. The sub-routine open_windows outputs Open the windows. For rain = 12 the condition is true and two lines are shown. For rain = 10 or rain = 0 it is false and one line is shown.
Class activity

Boundary bingo (no computer): write the rule ‘a child can ride if the height is at least 110 cm’ on a card. Each player writes five heights between 100 and 120 cm on a grid. A partner reads out a height, and you say Ride or Too small before marking it. Then change the rule to ‘taller than 110 cm’. Which heights change their answer? Write down what you notice about the boundary.

Practice
1
Trace the flowchart for 5 lessons and for 6 lessons. What is output each time? What is the largest number of lessons that stays within the budget?
StartINPUT lessonscost = lessons * 7cost > 40?yesnoOUTPUT "Over budget"OUTPUT "Within budget"End
2
The rule is: children aged 5 or under get free entry. One test fails. Which test, what kind of error is it, and what must be changed in the flowchart?
TestTest dataExpected outcomeActual outcomePass/fail
1age = 3Free entryFree entrypass
2age = 5Free entryPay at the desk?
3age = 8Pay at the deskPay at the deskpass
3
Follow the flowchart for 4 guests and for 8 guests. The sub-routine set_table outputs Plates out and Cups out. Write every line that is output each time.
Startrun sub-routine: set_tableINPUT guestsguests > 6?yesnorun sub-routine: set_tableOUTPUT "Ready"End
4
Draw a flowchart on paper: the user types a height in centimetres. If it is 120 or more, it outputs You may ride; otherwise it outputs Too small. Then choose three test heights, including the boundary, and write the expected outcomes.