← All workbooksPrint double-sided, A4, black and white
GRADE 10 · TERM 2

Decisions, Text & Networks

A pencil-and-paper workbook: think it through first, learn the Delphi, then prove you can do it.

Name:
Class: Date:

How to use this workbook

  1. Work with a pencil. Mistakes are how we learn: rub out and try again.
  2. Start each unit with Think First. Try it on your own before you read the explanation.
  3. Read Learn It, then do the activities. Trace tables and code are written by hand.
  4. At the end of each unit, tick the “I can” boxes you are sure of. Write down anything you still want to ask.
  5. The checkpoint test is done under test conditions, with no notes.

In this workbook

  1. Everyday decisions
  2. IF…THEN…ELSE and nested IF
  3. AND, OR, NOT and IN
  4. CASE and MessageDlg
  5. Strings and validation
  6. Devices, ports and networks
  7. Term checkpoint test
Matches the Annual Teaching Plan: Term 2 — full IF…THEN…ELSE and nested IF; AND, OR, NOT and IN; CASE and MessageDlg; Length, UpperCase, UpCase and Trim; input validation; FormCreate and Activate; input, output and storage devices; the system unit; ports; PAN, HAN, LAN and WAN; client-server and peer-to-peer networks.

UNIT 1Everyday decisions

You make decisions all day: Is it raining? Do I have money for a pie? A program does the same, but it can only ask questions with a YES or NO answer. In this unit you will practise decisions on paper before you meet them in Delphi.

By the end of this unit I can: (tick each box when you are sure)
One thing I want to ask my teacher:
THINK FIRST · no computer needed

1.1Who gets the free sweet? [4]

Mama Thandi runs a spaza shop. She has two different offers and she wants to know who qualifies for a free sweet.
Offer A: you must buy bread AND milk.   Offer B: you must buy bread OR milk (or both). Write Yes or No in each box.
The customer buys…Offer A (AND)Offer B (OR)
Bread and milk
Bread only
Milk only
Nothing
In your own words: when is AND stricter than OR?
LEARN IT

Conditions and flowcharts

A condition is a question that can only be answered True or False (Yes or No): “Is the mark 50 or more?” is a condition; “What is the mark?” is not. A flowchart draws the steps of an algorithm with arrows:A decision placed inside the Yes or No path of another decision is nested. Nesting lets you ask a second question only when the first answer needs it.

1.2Follow the flowchart [4]

Lerato decides how to get to school using this flowchart. Follow the arrows and write what she does in each situation.STARTSchool day?YesRaining?YesLift available?NoSleep inNoWalk to schoolYesGet a liftNoTake a taxi

SituationWhat does Lerato do?
Saturday, raining
Monday, sunny
Tuesday, raining, nobody can give her a lift
Wednesday, raining, her aunt can give her a lift
Why does Lerato never ask “Is it raining?” on a Saturday?

1.3Draw a flowchart [6]

Draw a flowchart on the grid for this algorithm. Use the correct shapes and label every arrow that leaves a diamond.
Input a mark (iMark). If the mark is 50 or more, then check again: if it is 80 or more display ‘Distinction’, otherwise display ‘Pass’. If the mark is below 50 display ‘Not yet’. Then stop.

LEARN IT

AND, OR and NOT

Programmers join conditions with three words:A truth table lists every possible combination of True and False and shows the result. With two conditions there are 2 × 2 = 4 rows.

1.4Truth table: AND, OR and NOT [8]

Complete the table (T = True, F = False). Work out NOT A first; then use it for the last column.

ABA AND BA OR BNOT A(NOT A) AND B
TT
TF
FT
FF

1.5True or False? [6]

Thabo is 16 years old (iAge = 16), has R18 (rMoney = 18) and it is break (bBreak = True). Circle True or False for each condition.

1(iAge >= 14) AND (rMoney >= 20)True  False
2(iAge >= 14) OR (rMoney >= 20)True  False
3NOT bBreakTrue  False
4(rMoney > 10) AND (NOT bBreak)True  False
5(iAge = 15) OR bBreakTrue  False
6NOT ((iAge < 18) AND (rMoney > 100))True  False

UNIT 2IF…THEN…ELSE and nested IF

In Term 1 you used a simple IF. Now you will give the program two paths (IF…ELSE), put decisions inside decisions, and learn why the order of your tests matters.

By the end of this unit I can: (tick each box when you are sure)
One thing I want to ask my teacher:
THINK FIRST · no computer needed

2.1Mr Khumalo's sweets

Mr Khumalo hands out sweets for marks. His rules are on the board, in this order: (1) 30 or more: 1 sweet. (2) 50 or more: 2 sweets. (3) 80 or more: 3 sweets. He reads them from the top and stops at the first rule that is true. Thandi scored 85. How many sweets does she get? Is that fair? Rewrite the three rules in an order that works for every learner.
LEARN IT

IF…THEN…ELSE

An IF statement chooses between two paths. If the condition is True the statement after then runs; if it is False the statement after else runs. Never both. Two traps: (1) There is no semicolon before else: a semicolon ends the whole IF, so the else has nothing to belong to and Delphi reports an error. (2) A branch with more than one statement must be wrapped in begin … end; otherwise only the first statement belongs to the IF.
Delphi
if iMark >= 50 then
begin                               // two statements: begin ... end
  lblResult.Caption := 'Pass';
  btnCertificate.Enabled := True;
end                                 // NO semicolon before else
else
  lblResult.Caption := 'Not yet';   // one statement: no begin needed
LEARN IT

Nested IF and the ELSE IF chain

Put an IF inside the else (or the then) of another IF to ask a second question. Delphi tests from the top and takes the first True; after that it skips the rest. So the order matters: test the most demanding condition first.
Delphi
// a chain: the order of the tests matters
if iMark >= 80 then
  sResult := 'Distinction'
else
  if iMark >= 50 then
    sResult := 'Pass'
  else
    sResult := 'Not yet';

// a second question is only asked when the first is True
if bRegistered then
begin
  if rFine = 0 then
    sMsg := 'You may borrow'
  else
    sMsg := 'Pay your fine first';
end
else
  sMsg := 'Please register';

2.2Be the computer: pie prices [8]

A pie costs less when you buy more. Complete the table for each value of iPies. Write Yes or No for each test, or a dash (-) if the test is never reached.

Delphi
if iPies >= 10 then
  rPrice := 11
else
  if iPies >= 5 then
    rPrice := 12
  else
    rPrice := 14;
rTotal := iPies * rPrice;
iPiesiPies >= 10 ?iPies >= 5 ?rPricerTotal
3
5
10
12

2.3Debug: two broken IFs [8]

A does not compile: find two errors. B compiles, but a learner who scores 50 should pass and only a passing learner may see the certificate button: find two errors. Write the corrected code.

Delphi
// A
if iAge >= 18
  lblStatus.Caption := 'Adult';
else
  lblStatus.Caption := 'Learner';

// B
if rMark > 50 then
  lblResult.Caption := 'Pass'
else
  lblResult.Caption := 'Not yet';
btnCertificate.Visible := True;

2.4Write it: taxi fare [6]

A taxi charges R10 for a child under 12, R12 for a pensioner (60 or older) and R20 for everyone else. The age is in the spin edit sedAge. Write the code to work out iFare and show it in lblFare as, for example, R20.

2.5Debug: wrong order [4]

The symbol should be A for 70 or more, B for 50 to 69, C for 30 to 49 and D below 30. The code is meant to do that. What symbol does it give for marks of 75, 55 and 20? Then rewrite the tests so that it works.

Delphi
if iMark >= 30 then
  sSymbol := 'C'
else
  if iMark >= 50 then
    sSymbol := 'B'
  else
    if iMark >= 70 then
      sSymbol := 'A'
    else
      sSymbol := 'D';

2.6Write it: library books [6]

A learner may borrow a book only if registered (checkbox chkRegistered). If registered, check the fine typed in edtFine (a real number): a fine of 0 shows You may borrow a book in lblMsg, otherwise Please pay your fine first. A learner who is not registered sees Please register first. Use a nested IF.

UNIT 3AND, OR, NOT and IN

Real rules usually have more than one part: “older than 14 and has permission”. In this unit you will combine conditions in Delphi, use brackets so they mean what you intend, and meet the IN operator.

By the end of this unit I can: (tick each box when you are sure)
One thing I want to ask my teacher:
THINK FIRST · no computer needed

3.1The tuck shop sign

A hand-written sign at the tuck shop reads: “Pie AND chips OR cooldrink: R20.”
Nomsa has only a cooldrink. Zinzi has a pie and chips. Hendrik has a pie and a cooldrink. Who might the shopkeeper let through, and why do Nomsa and Hendrik argue? Show, with brackets, the two different meanings of the sign.
LEARN IT

Brackets, and the order of AND, OR and NOT

Delphi applies NOT first, then AND, and OR last. It does this even if you wrote the OR first, just like multiplication happens before addition in maths. Comparisons such as iAge >= 14 are applied after AND/OR, so every comparison needs its own brackets; otherwise Delphi tries to AND the numbers together and gives an error. Always use brackets: they make the meaning clear to you and to the computer.
Delphi
// WRONG, does not compile:  if iAge >= 14 and iAge <= 19 then
if (iAge >= 14) and (iAge <= 19) then
  ShowMessage('Teenager');

if (bPaid) or (bSRC) then
  ShowMessage('Entry allowed');

if not (iMark >= 50) then      // same as iMark < 50
  ShowMessage('Not yet');

bResult := bA or bB and bC;    // means bA or (bB and bC)
bResult := (bA or bB) and bC;  // a different question!
LEARN IT

The IN operator

IN checks whether a value is in a set, written in square brackets. It replaces long chains of OR. A set can list values, give a range with .., or mix both. It works with whole numbers and characters (not with real numbers or strings).
Delphi
if cLetter in ['A', 'E', 'I', 'O', 'U'] then
  ShowMessage('Vowel');

if iMonth in [6..8] then          // June to August
  ShowMessage('Winter');

if not (iSeat in [1..15, 40..55]) then
  ShowMessage('Seat must be 1-15 or 40-55');

3.2Truth table: school trip [8]

A learner may go on the trip if they have paid and have a permission slip and are not on detention: (bPaid AND bPermission) AND (NOT bDetention). Complete the table (T = True, F = False).

bPaidbPermissionbDetentionNOT bDetentionMay go?
TTT
TTF
TFT
TFF
FTT
FTF
FFT
FFF

3.3Predict: the precedence trap [3]

Work out the value of each Boolean. Then say in one sentence why they are different.

Delphi
bA := True;
bB := False;
bC := False;
bResult1 := bA or bB and bC;
bResult2 := (bA or bB) and bC;

3.4Evaluate with these values [6]

Use iMark = 62, cGrade = 'C', bPaid = True and iDay = 6. Circle True or False for each condition.

1(iMark >= 50) AND bPaidTrue  False
2(iMark IN [40..59]) OR (cGrade = 'B')True  False
3cGrade IN ['A'..'C']True  False
4NOT bPaidTrue  False
5NOT (iDay IN [1..5])True  False
6(iMark < 50) OR NOT bPaidTrue  False

3.5Debug: three broken conditions [6]

Each condition has a mistake. Say what is wrong and write it correctly.

Delphi
1.  if iAge >= 14 and iAge <= 19 then
2.  if cLetter = 'A' or 'E' or 'I' then
3.  if not iMark >= 50 then

3.6Write the conditions [8]

Write a Delphi condition (the part between if and then) for each sentence.
(a) The age iAge is from 14 to 16, including both.
(b) Entry is free if iAge is under 6 or 60 and over.
(c) The grade iGrade is not 8, 9 or 10.
(d) The character cKey is a digit from 0 to 9.

3.7Write it: matric dance ticket [7]

A ticket costs R150. Only Grade 11 and 12 learners may buy one (the grade is in the spin edit sedGrade). A learner gets R30 off if they paid early (chkEarly is checked) or are on the SRC (chkSRC is checked). Show the price in lblPrice as R120. A learner in any other grade sees Not eligible in the label. Use an integer variable iPrice.

UNIT 4CASE and MessageDlg

When one value can lead to many different outcomes, a long IF chain gets untidy. CASE is the neat alternative. You will also learn to ask the user a Yes/No question with MessageDlg.

By the end of this unit I can: (tick each box when you are sure)
One thing I want to ask my teacher:
THINK FIRST · no computer needed

4.1The taxi rank fare board [4]

The board at the taxi rank says: Zone 1: R12  |  Zones 2 and 3: R18  |  Zones 4 to 6: R25. Write the fare for each passenger.
A passenger travels to zone…Fare
2
6
7
What should the driver do about zone 7?
LEARN IT

The CASE statement

CASE looks at one value (the selector) and jumps to the line that matches. A line holds one value, several values separated by commas, or a range written with two dots. The optional else catches everything else.
Delphi
case iZone of
  1    : iFare := 12;
  2, 3 : iFare := 18;
  4..6 : iFare := 25;
else
  iFare := 40;
end;

4.2IF or CASE? [6]

Circle the better tool for each job.

1Turn a mark from 0 to 100 into a symbol from 1 to 7.IF  CASE
2Check that the learner is 14 or older and has paid.IF  CASE
3Turn the day number 1 to 7 into a day name.IF  CASE
4Decide whether a real-number price is above R100.IF  CASE
5Choose the taxi fare from the zone number.IF  CASE
6Check whether the text in edtName is the word Admin.IF  CASE

4.3Fill in the blanks [6]

The selector of a CASE must be an value such as an Integer or a Char. A range of 4 to 6 is written 46. The part that runs when nothing matches is called . A CASE statement ends with the word but it has no . A value may not appear in different lines.

4.4Be the computer: taxi zones [8]

Use the CASE statement in Learn It. For each zone, write which line matches (1, 2, 3, 4..6 or else) and the value of iFare.

Delphi
case iZone of
  1    : iFare := 12;
  2, 3 : iFare := 18;
  4..6 : iFare := 25;
else
  iFare := 40;
end;
iZoneLine that matchesiFare
1
3
4
7

4.5Predict: sorting letters [3]

What is the value of sGroup after the code runs when cLetter is 'M'? What if it is 'Z'? What if it is the lowercase 'c'? (Capital letters come before lowercase letters in the alphabet of the computer.)

Delphi
case cLetter of
  'A'..'F' : sGroup := 'Group 1';
  'G'..'L' : sGroup := 'Group 2';
  'M'..'R' : sGroup := 'Group 3';
else
  sGroup := 'Group 4';
end;

4.6Debug: the day types [4]

This code should say whether iDay (1 = Monday … 7 = Sunday) is a school day, a weekend day or invalid. It does not compile. Find two errors.

Delphi
case iDay of
  1..5 : sType := 'School day';
  5..7 : sType := 'Weekend';
else
  sType := 'Invalid day';
LEARN IT

MessageDlg: ask the user a question

ShowMessage only tells the user something. MessageDlg asks and gives you the answer. It is a function with four parts: the text, the icon (mtConfirmation, mtInformation, mtWarning, mtError), the buttons (mbYesNo, mbOKCancel, mbYesNoCancel) and a 0 for help (always 0 for now). It returns which button was clicked: mrYes, mrNo, mrOK or mrCancel. Compare the answer in an IF.
Delphi
if MessageDlg('Delete all the entries?', mtConfirmation, mbYesNo, 0) = mrYes then
  memOut.Clear
else
  ShowMessage('Nothing was deleted');

4.7Write it: mark to symbol [6]

The mark is in iMark (0 to 100). Use a CASE statement to put the symbol in sSymbol: 80–100 is 7, 70–79 is 6, 60–69 is 5, 50–59 is 4, 40–49 is 3, 30–39 is 2 and below 30 is 1.

4.8Write it: leaving the program [6]

When the user clicks btnExit, ask Do you really want to quit? with a question icon and Yes/No buttons. If the answer is Yes, close the form with Close. Otherwise show Welcome back! with ShowMessage.

UNIT 5Strings and validation

Programs must cope with users who type spaces, capitals and nonsense. Here you will measure and tidy text, check data before you use it, and decide when set-up code should run.

By the end of this unit I can: (tick each box when you are sure)
One thing I want to ask my teacher:

5.1Count, trim, capitalise [3]

A learner typed a name with a space before and after it. The word below is stored in sName and every box is one character (the empty boxes are spaces). (a) How many characters are there in all (Length)? (b) What would Trim leave, and what is its length? (c) Write the result of UpperCase applied to the trimmed name.

1 
2A
3y
4a
5 
6D
7u
8b
9e
10 
THINK FIRST · no computer needed

5.2The form checker [3]

A school clerk receives this subject-choice form. Which of these entries should she reject, and which rule would she use for each (empty, out of range, wrong length)?
FieldWhat the learner wrote
Name(left blank)
Grade17
Cell number (10 digits)082 55
LEARN IT

Four string tools

Length(s) counts the characters (spaces included) and returns a whole number. UpperCase(s) turns a whole string into capitals. UpCase(c) does the same for one character. Trim(s) removes spaces at the start and end of a string. Each one returns a new value: the original does not change unless you store the result back in a variable. Position numbers start at 1, so s[1] is the first character.
Delphi
sName := Trim(edtName.Text);        // '  aya ' becomes 'aya'
iLen := Length(sName);              // 3
sBig := UpperCase(sName);           // 'AYA'
cFirst := UpCase(sName[1]);         // 'A'  (one Char, so UpCase)
sName := UpperCase(Trim(edtName.Text));   // functions can be nested

5.3What do the functions give? [5]

sName holds ' Zanele Mkhize ', which starts with two spaces and ends with one. Write the result of each expression. Put text answers in single quotes.

ExpressionResult
Length(sName)
Trim(sName)
Length(Trim(sName))
UpperCase(Trim(sName))
UpCase(sName[4])
LEARN IT

Validate before you process

Garbage in, garbage out. A program must check data before it uses it. Common checks: presence (text is not empty), range (a number is within limits) and length (the right number of characters). Use IF, and use Exit to leave the event handler when the data is bad so that nothing else runs. A classic: Sqrt crashes on a negative number, so test the number first.
Delphi
rNum := StrToFloat(edtNum.Text);
if rNum < 0 then
  ShowMessage('You cannot take the square root of a negative number')
else
  lblRoot.Caption := FloatToStrF(Sqrt(rNum), ffFixed, 8, 2);

if Trim(edtName.Text) = '' then
begin
  ShowMessage('Please type your name');
  Exit;                       // stop here, do nothing else
end;

5.4Be the computer: ticket validation [8]

A ticket costs R45. The rule says between 1 and 6 tickets may be ordered. Complete the table for each value typed.

Delphi
iQty := StrToInt(edtQty.Text);
if (iQty < 1) or (iQty > 6) then
  sMsg := 'Invalid'
else
  sMsg := 'Total R' + IntToStr(iQty * 45);
iQtyiQty < 1iQty > 6sMsg
0
6
7
3

5.5Debug: the greeting [6]

This code should greet the learner by name and show the first letter in capitals. Find three errors and rewrite the code correctly.

Delphi
sName := Trim(edtName.Text);
if sName = 0 then
  ShowMessage('Please type your name');
cInitial := UpperCase(sName[1]);
lblHi.Caption := 'Hello ' + sName + ', your initial is ' + cInitial;

5.6Write it: when the number is negative [5]

The learner types a number in edtNum and clicks the button to get the square root in lblRoot. Write the code so the program does not crash when the number is negative: show the message Negative numbers have no square root instead.

LEARN IT

FormCreate and Activate: when does code run?

Windows creates your form once and then you can click away and back. Two events let you run code at the right moment. FormCreate happens once, when the form is first created, before it appears: use it for set-up like Randomize, clearing labels and disabling buttons. FormActivate happens every time the form becomes the active window (for example when you return to it): use it to refresh something or to put the cursor in an edit box.
Delphi
procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;                    // once only
  lblResult.Caption := '';
  btnCalc.Enabled := False;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  edtName.SetFocus;             // every time the form is activated
end;

5.7FormCreate or FormActivate? [4]

Which event is the better place for each job?

1Call Randomize once when the program starts.FormCreate  FormActivate
2Put the cursor in edtName each time the user returns to the form.FormCreate  FormActivate
3Set lblResult to an empty string when the program opens.FormCreate  FormActivate
4Refresh the “last visited” label each time the form comes to the front.FormCreate  FormActivate

UNIT 6Devices, ports and networks

No program runs alone. It runs on hardware, and today most computers are linked together. This theory unit uses diagrams and classification, with no computer needed.

By the end of this unit I can: (tick each box when you are sure)
One thing I want to ask my teacher:
THINK FIRST · no computer needed

6.1One printer, forty computers

A school has 40 computers in two labs, one good printer, and one internet line. Nothing is connected. List three problems this causes. Then list three things that become possible if all the computers are joined together.

6.2Input, output or storage? [8]

Circle the category for each device.

1ScannerInput  Output  Storage
2Data projectorInput  Output  Storage
3Solid state drive (SSD)Input  Output  Storage
4MicrophoneInput  Output  Storage
5SpeakersInput  Output  Storage
6Memory cardInput  Output  Storage
7Barcode scanner at the tillInput  Output  Storage
8PrinterInput  Output  Storage
LEARN IT

Inside the system unit

Think of the system unit as a school. The motherboard is the school building and its corridors: the main circuit board that every part plugs into. The CPU is the teacher: it carries out the instructions of every program (speed in GHz). RAM is the desks: temporary working space for the programs and files in use right now, and it is emptied when the power goes off. Storage (hard disk or SSD) is the library: the files are kept there permanently, even when the computer is off. Ports are the doors where cables and devices connect.

6.3Match the part to its job [4]

Write the name of the part: motherboard, CPU, RAM or storage.

JobWhich part? (write the name)
Carries out program instructions; the “brain”
The main circuit board that joins all the parts together
Temporary workspace that is wiped when the power is off
Keeps your files when the computer is switched off

6.4Ports [4]

Write what each port is used for.

PortUsed for
USB
HDMI
Network (NIC) port
VGA
LEARN IT

Why network, and how big is the network?

A network is two or more devices linked so that they can share. People network computers to share printers, files and one internet connection, to communicate (email, messaging) and to keep data and backups in one place. Networks are named by size: PAN (Personal Area Network): around one person, a few metres, such as Bluetooth earbuds. HAN (Home Area Network): inside one home, such as the Wi-Fi router joining phones, TV and laptop. LAN (Local Area Network): one building or campus, such as a school computer lab. WAN (Wide Area Network): towns, countries, continents, such as the Internet or a bank's network of branches and ATMs.

6.5PAN, HAN, LAN or WAN? [6]

Circle the best answer.

1A smartwatch linked to your phone by BluetoothPAN  HAN  LAN  WAN
2The Wi-Fi at your house connecting the family's phones and the smart TVPAN  HAN  LAN  WAN
3The computer lab at your schoolPAN  HAN  LAN  WAN
4A bank's ATMs and branches across South AfricaPAN  HAN  LAN  WAN
5Two buildings on the same school campus joined by a cablePAN  HAN  LAN  WAN
6The InternetPAN  HAN  LAN  WAN
LEARN IT

Client-server and peer-to-peer

In a client-server network one powerful computer, the server, controls the network: it holds the files, manages log-ins and security, runs the printer and does the backups. The other computers are clients. It is expensive and the administrator has control, but if the server fails everybody is affected. In a peer-to-peer (P2P) network every computer has equal status: any can share files or a printer, and there is no central computer. It is cheap and simple, but security and backups are handled on each computer, so it suits only a few devices.

6.6Client-server or peer-to-peer? [5]

Circle the type that fits each description.

1A school computer lab where one server controls all log-insClient-server  Peer-to-peer
2Two friends share files between their laptops at homeClient-server  Peer-to-peer
3One administrator manages every user account and the backupsClient-server  Peer-to-peer
4Every computer has equal status and there is no central computerClient-server  Peer-to-peer
5If one computer fails, everybody loses access to the shared filesClient-server  Peer-to-peer

6.7Draw a school network [8]

Draw a star network for a small computer lab on the blank page below. Show: 5 PCs (one is the teacher's), a server, a printer, a switch in the middle, and a router linking the switch to the Internet. Label every device. Under the drawing write what type of network the lab is (PAN, HAN, LAN or WAN) and whether it is client-server or peer-to-peer.

6.8Recommend a network [3]

A spaza shop owner has three computers (the till, an office laptop and a tablet) and one printer. She asks you whether she needs a server. Recommend client-server or peer-to-peer and give two reasons.

TERM CHECKPOINTDecisions, text and networks

Time: 60 minutes
Total: 55 marks
Mark: ______ / 55

No notes, no computer. Show all your working. Write Delphi code neatly and use correct indentation.

SECTION A — Trace and predict [12]

A1 [6]

A school fun run charges an entry fee. Trace the code for each runner. Write the value of iFee after the age tests, and the final iFee after the member discount.

Delphi
if iAge < 6 then
  iFee := 0
else
  if iAge <= 17 then
    iFee := 30
  else
    iFee := 60;
if bMember and (iFee > 0) then
  iFee := iFee - 10;
iAgebMemberiFee after age testsFinal iFee
4True
12False
17True

A2 [3]

What appears in lblOut?

Delphi
sTxt := '  Load shedding  ';
sTxt := Trim(sTxt);
iLen := Length(sTxt);
sTxt := UpperCase(sTxt);
lblOut.Caption := IntToStr(iLen) + ' ' + sTxt;

A3 [3]

Write the value of sSize after the code runs for iPies = 0, for iPies = 4 and for iPies = 9.

Delphi
case iPies of
  0    : sSize := 'None';
  1, 2 : sSize := 'Small';
  3..5 : sSize := 'Medium';
else
  sSize := 'Big';
end;

SECTION B — Concepts [15]

B1 [4]

Complete the truth table.

AB(NOT A) OR B
TT
TF
FT
FF

B2 [3]

Circle PAN, HAN, LAN or WAN for each.

1Wireless earphones paired with a phonePAN  HAN  LAN  WAN
2The network that links all computers in the school labPAN  HAN  LAN  WAN
3The network that links a cellphone company's towers across the countryPAN  HAN  LAN  WAN

B3 [3]

Circle Input, Output or Storage for each device.

1WebcamInput  Output  Storage
2Flash driveInput  Output  Storage
3MonitorInput  Output  Storage

B4 [3]

The is the main circuit board that joins all the parts. The carries out instructions. is the temporary workspace that is wiped when the power goes off.

B5 [2]

Circle the network type described.

1All the computers have equal status and there is no central server.Client-server  Peer-to-peer
2A central computer controls log-ins and the printer.Client-server  Peer-to-peer

SECTION C — Find the errors [8]

C1 [4]

Find two errors and write the corrected code.

Delphi
if iMark >= 0 and iMark <= 100 then
  lblOk.Caption := 'Valid';
else
  lblOk.Caption := 'Invalid';

C2 [4]

Find two errors in this CASE statement.

Delphi
case iMark of
  0..50   : sResult := 'Fail';
  50..100 : sResult := 'Pass';
else
  sResult := 'Invalid';

SECTION D — Write the code [20]

D1 [8]

A quiz mark out of 20 is in the spin edit sedScore. If the score is below 0 or above 20 show Invalid score with ShowMessage and stop. Otherwise use a CASE statement to put a medal in lblMedal: 18 to 20 Gold, 15 to 17 Silver, 10 to 14 Bronze, anything lower Keep trying.

D2 [5]

The learner types a name in edtName. Trim it. If it is empty show Please enter a name with ShowMessage. Otherwise display Hello, followed by the name in capitals in lblWelcome and the number of characters in the name in lblLen.

D3 [4]

When btnClear is clicked, ask Delete this record? with a confirmation icon and Yes/No buttons. If the user clicks Yes clear memOut and show Cleared with ShowMessage. (Write the whole event handler.)

D4 [3]

Write one IF statement (the whole statement) that shows Free entry in lblEntry when iAge is under 6 or is 60 and over, and Pay at the gate otherwise.

COMING UP NEXT TERM · warm-up

Thirty scripts to mark

In Term 3 you will make the computer do something many times without you writing it many times. Before the Delphi, think about a teacher with a pile of 30 test scripts to mark.

(a) Write, in order, the steps Mr Naidoo does for one script. (b) Which steps are done again for every script, and which are done only once (before he starts or after he finishes)? (c) What tells him when to stop? (d) What if nobody told him how many scripts there were? How would he know the pile is finished?