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.
Study sections
Follow the order or choose a sectionFrom 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…
02One 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…
03Below 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…
04Find 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…
05Test 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…
06The 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,…
07Keep 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…
08Procedures, 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…
09Call 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…
10Build 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…
11Ties 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…
12Side 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…
13Write 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…
14Tutorial 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…
15Call 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…
