← Back to course
Intro to CS 9-10 / Week 06 / Wednesday
3/6
Week 06 Β· Procedures and Abstraction

Wednesday

Beacon Lab: The module chart
// Splitting a big problem into pieces you can reuse
⏱ about 20 min

Wednesday: Beacon Lab: The Module Chart

Wren unrolls a long sheet of paper across the greenhouse floor. At the top he writes one word: Beacon.

"Beacon is too big to think about all at once," he says. "Let's break it into pieces."

Comet grabs a marker. "Reading the sensors is one piece. Checking the plants is another."

"And sending the report back to mission control," Wren adds.

Nova hovers above the sheet, projecting faint boxes in the air. "I found a pattern," she says.

"Each big piece has smaller pieces inside it. Keep splitting until each box is one clear job."

Comet draws the first arrow. The module chart has begun.

Your mission

You will decompose Beacon into modules: a chart of boxes, each with one job.

Complex programs are designed as systems of modules. Each module has a specific role, and they all work toward one purpose.

Dividing a program into separate subprograms like this is called modularity.

  • A large sheet of paper, or four sheets taped together
  • A pencil and two colors of marker
  • Sticky notes or small paper squares
  • A ruler for straight arrows
  1. Write Beacon in a box at the top of your sheet.
  2. Under it, write three boxes: read the sensors, check the plants, send the report.
  3. Under read the sensors, add boxes for water, light and temperature.
  4. Under check the plants, add boxes for checkPlant and average.
  5. Under send the report, add a box that builds the message and one that sends it.
  6. For each box, write its job in one short line on a sticky note.
  7. Color every box that is a procedure you already wrote this week.
ModuleIts one jobParameter (input)Return value (output)
averageFinds the mean of a lista list of numbersone number
checkPlantDecides if a plant needs waterone water levelneeds water or all good
readWaterReads the water sensors(none)a list of readings
buildReportPuts results into one messagethe averages and statusesa report string

Copy this table onto paper and add a row for each new module on your chart.

WHICH MODULE DOES THE JOB?
  • Read the question.
  • Tap your answer.
Beacon needs the mean light reading for the day.
Beacon must decide whether the basil needs water.
Beacon must turn its results into one message for mission control.
Which module can be reused for water, light and temperature?

What, not how

Procedural abstraction lets you use a procedure knowing only what it does, not how it does it.

Whoever writes buildReport can call average without reading a single line inside it.

Procedural abstraction lets the solution to a big problem be built from solutions to smaller subproblems.

Lab findingTrue or false?
Each box in a good module chart has one clear job.?
To call average, you must know every line inside it.?
Splitting a program into subprograms is called modularity.?
Modules in a system work toward one overall purpose.?
WHY THIS EXERCISEDecomposing a problem into modules is how big programs stay understandable.
Splitting a program into separate subprograms is called ____. Type one word.
WHY THIS EXERCISEModularity is the name for what you just did on your chart.
On your sheet, finish the module chart for Beacon with at least eight boxes and arrows from each box to its parts.

Great lab work, developer. Tomorrow you will meet a shared library and a random number helper.

← Tuesday