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

Term 2 review

Week 21 · Review: Term 2 · 3 lessons
2

Review: sub-routines and tables

Computing 6: Units 5–8, pp. 68–123
GoalRecall how sub-routines shorten an algorithm and how a table of records is built, searched and judged.
New words
sub-routine · a named set of steps that does one job and can be called many timesrecord · one row of a table, holding everything about one thingfield · one column of a table, holding one kind of datakeyword · a word or part of a word that we search for
Explanation

A sub-routine is a named set of steps that does one job. We write it once and call it wherever the job is needed. The main algorithm becomes shorter, and a mistake is fixed in only one place. We can judge a program with criteria, such as function and ease of use, cost, training and support, and technical requirements. A database table stores data in records and fields. Each field has a data type, which is text, number or date. A code field makes every record different. A keyword search finds the cells that contain the keyword anywhere inside them. A phrase narrows the search, and we always read the matches to check them.

ABCD
1CodeNameAgeJoined
2B-01Aziza113 Sep
3B-02Timur1214 Sep
4B-03Dilya102 Oct
5B-04Sanjar129 Oct
6B-05Madina1130 Oct
Worked examples
Main algorithmSub-routine: lay one place
Repeat 4 times: lay one place, move to the next seat1 Put down a plate
Lay one place2 Put down a fork
Stop3 Put down a cup
Setting five places at a table is the same job five times. The sub-routine is written once. Done in full, the job takes 5 × 3 = 15 laying steps and 4 moves. With the sub-routine, the three laying steps appear only once.
SearchCells foundWhy
SepD2, D3two members joined in September
12C3, C5two members are 12 years old
OctD4, D5, D6three members joined in October
9 OctD5the phrase finds only one date
adB6only Madina has the letters ad
Here are five searches on the club table in the first picture. Ages are in column C and dates are in column D. Each search looks at every cell. The phrase 9 Oct is narrower than the keyword Oct.
QuestionProgram XProgram Y
Does it do the whole job?yesyes
Is it free?yesno
Is help available?nono
Does it run on our laptop?yesyes
The club must choose one of two programs for its table. Count the yes answers. Both programs do the whole job and run on the club’s laptop. Program X is free but has no help, and program Y costs money and has no help either. X has 3 yes answers and Y has 2, so X is the better choice.
Class activity

Paper database (no computer): choose a topic, such as a class reading club. Draw a table with a code field and three more fields. Write the data type of each field. Fill in five records. Swap tables with a partner. The partner searches for a keyword and then a phrase, and writes the cells that match, in the style A3 or C5. Then the partner adds a new record, changes one value and deletes one record. Last, write the steps for ‘add a new record’ as a sub-routine, and say where the main algorithm would call it.

Practice
1
How many fields and how many records does the table have? Give the best data type for each field.
ABCD
1CodeFruitPriceStock
2F-1Apple640
3F-2Pear825
4F-3Grapes1418
5F-4Pomegranate1230
6F-5Apricot1022
2
Using the table in question 1, which cells match the keyword ap?
3
A main algorithm calls ‘wrap one gift’ six times. The sub-routine has 4 steps. How many steps are carried out altogether, and how many lines of the sub-routine are written?
4
Which program should be chosen, and why?
QuestionProgram PProgram Q
Does it do the whole job?yesno
Is it free?noyes
Is help available?yesyes
Does it run on our laptops?yesyes