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

Errors, search and a coding project

Week 15 · Unit 7.3: Connections are made · 3 lessons
3

Project: the secret-note coder

Computing 7: Unit 7.3, pp. 82–111
GoalPlan, make, test and evaluate a flowchart that encrypts one letter with a shift of 3.
New words
algorithm · a precise set of steps that solves a problemtest plan · a table of tests that says what should happen, so you can compare it with what does happenboundary test · a test with data at the edge of what is allowed, where mistakes often hideevaluate · to judge how well something works and how it could be better
Explanation

A project has four stages: plan, make, test and evaluate. Our problem is that a reading club wants an algorithm that encrypts one letter with a Caesar shift of 3. Step 1 is to number the alphabet, so A is 1, B is 2 and Z is 26. Step 2 is to add 3 to the number. Step 3 is the tricky part, because X, Y and Z would go past 26, so the algorithm must wrap round by subtracting 26. A decision in the flowchart does this: if the new number is more than 26, subtract 26. Last, the algorithm outputs the letter at the new number. Then we test with letters from the middle and from the end of the alphabet, and compare the expected outcome with the actual outcome.

StartINPUT letternumber = place of letter (A = 1 … Z = 26)new = number + 3new > 26?yesnonew = new − 26OUTPUT letter at place newEnd
Worked examples
StepnumbernewOutput
after INPUT C
number = place of letter3
new = number + 336
new > 26?36no
OUTPUT36F
Trace with the letter C. C is number 3, new is 6, and 6 is not more than 26, so there is no wrap. The letter at place 6 is F.
StepnumbernewOutput
number = place of letter25
new = number + 32528
new > 26?2528yes
new = new − 26252
OUTPUT252B
Trace with the letter Y. Y is number 25, new is 28, and 28 is more than 26, so new becomes 2. The letter at place 2 is B.
TestTest dataExpected outcomeActual outcomePass/fail
1ADDpass
2MPPpass
3XAno letterfail
4ZCCpass
A test plan for a faulty copy of the flowchart whose decision says new > 27. The expected outcomes were worked out first. X is the boundary letter: new is 27, which is not more than 27, so there is no wrap and no letter at place 27. Test 3 fails and shows the bug.
Class activity

Human computer (no computer): draw the flowchart on a big sheet. Cut out cards for each box and lay them on the table in order. Write the alphabet with numbers 1 to 26 on a strip. A partner is the user and gives you a letter. You follow the boxes, moving a counter along the strip, and write the output. Test with A, M, X and Z. Then change the shift to 4 and see which letters now need the wrap-round. Write what you would do differently next time.

Practice
1
Trace the letter Z through the flowchart and complete the table.
StepnumbernewOutput
number = place of letter?
new = number + 3??
new > 26????
new = new − 26??
OUTPUT???
2
Change the algorithm to use a shift of 5. Fill in the missing numbers, then say which letters now need the wrap-round.
StartINPUT letternumber = place of letternew = number + ?new > ?yesnonew = new − ?OUTPUT letter at place newEnd
3
Write a test plan for the shift-5 algorithm using A, U, V and Z. Work out the expected outcomes first.
TestTest dataExpected outcomeActual outcomePass/fail
1A?
2U?
3V?
4Z?
4
Mia built a flowchart whose decision says new > 25. Her tests are in the table. What is wrong with her flowchart, and how should it be fixed?
TestTest dataExpected outcomeActual outcomePass/fail
1XAApass
2YBBpass
3WZno letterfail