FOUNDATION · WEEK 03

Tables, two passes and reusable procedures

Use familiar score cards, word cards and shopping bills to understand tables, grade bands, hypotheses, parameters, prizes and side effects. Build on the card-processing patterns from Weeks 1 and 2.

15 study sections20 illustrations2 resources
Start Week 3 →

Study sections

Follow the order or choose a section
01

From cards to tables: rows, columns and IDs

A table stores the same information as the cards in a more regular shape. One ordinary card becomes one row. Each field becomes a colum…

1 illustrations
02

One bill, many items: link two tables

Shopping bills have a different shape. A bill has one shop, customer and total, but it can contain any number of items. Srivatsan’s fir…

1 illustrations
03

Below average: finish one pass before filtering

We want the students whose Mathematics mark is below the average of the whole class. A running average changes whenever another card is…

1 illustrations
04

Find the range, then assign grade bands

Instead of dividing the class into above and below average, we can create four grade bands. First discover the lowest and highest actua…

1 illustrations
05

Test an idea: are frequent words short?

A hypothesis is an idea we can test with data. Looking at a few familiar words suggests that frequent words may be short. We need clear…

1 illustrations
06

The three-prizes problem: decide the rules first

The prize example asks for three high-scoring students, with two extra rules: each should be a subject topper in at least one subject,…

1 illustrations
07

Keep the top three: shift safely and handle ties

Keeping one maximum needs one remembered value. Keeping three needs three ordered places: First ≥ Second ≥ Third. When a new maximum ar…

2 illustrations
08

Procedures, parameters and return values

A procedure is a named set of steps we can reuse. Think of asking a helper to do one well-defined job. Parameters tell the helper which…

1 illustrations
09

Call one maximum procedure four times

We want to know whether some student achieves the maximum in every subject. Finding the maximum four times is the same task with a diff…

1 illustrations
10

Build the prize algorithm from smaller procedures

Now connect the pieces. First compute the third distinct mark level in every subject once. Then call a Boolean procedure on each studen…

1 illustrations
11

Ties and impossible criteria: finish the specification

A calculation can be mechanically correct while the problem rules remain incomplete. Three physical prize slots cannot always fit every…

1 illustrations
12

Side effects: returning a number can change a deck

A procedure may return the right sum and still change the data arrangement. That extra change is called a side effect. To use the proce…

1 illustrations
13

Write a contract: inputs, result and allowed changes

A procedure’s interface is the boundary between caller and helper. Its contract states what the caller supplies, what the helper return…

2 illustrations
14

Tutorial lab: nouns, bill averages and expenditure bands

Practise the same ideas with the original word cards and shopping bills. These are new questions on familiar data, so you can focus on…

3 illustrations
15

Call procedures correctly: name, count and order

A procedure call must match its definition. Tutorial 3.3 builds an average for Big Bazaar bills by returning two updated values after e…

2 illustrations