← Back to course
Intro to CS 9-10 / Week 06 / Mission Quest
6/6
Week 06 · Procedures and Abstraction

Mission Quest

Mission Quest: Call My Procedure
// Splitting a big problem into pieces you can reuse
⏱ about 20 min

Mission Quest: Call My Procedure

The greenhouse is quiet for the evening, and Comet is standing by the work table.

"I have written a procedure," she announces. "It is called cheer, and it has one parameter: times."

Wren laughs and calls out, "cheer(3)!"

Comet claps three times and shouts, "Go, Beacon!"

Nova hovers over the table and projects a scoreboard. "Now let's add a procedure that returns a value," she says.

"Then the caller has to catch the answer."

Wren grabs a stack of paper cards. "Everyone writes one procedure. Then we call each other."

  1. A procedure is a named group of instructions that may have parameters and return values.
  2. Parameters are input variables. Arguments are the values passed in when the procedure is called.
  3. Procedural abstraction means you use a procedure knowing what it does, not how.
  4. Splitting a program into subprograms is modularity. Complex programs are systems of modules.
  5. RANDOM(a, b) returns a whole number from a to b, each equally likely.
  6. Read a library's license before you use it, and always give credit.
◇ CALL MY PROCEDURE
You need paper cards, a pencil, and a number cube. No cube? Number six paper slips from 1 to 6 and draw one from a cup.
Each player writes one procedure card with a name, one parameter and a short body.
Example: PROCEDURE stomp(times): stomp your foot that many times, then sit down.
Example with a return value: PROCEDURE addTen(number): say the answer to number plus 10.
Take turns calling someone else's procedure with an argument, such as stomp(4) or addTen(7).
The player who is called follows the card exactly. The caller writes down any return value.
Use a number cube as RANDOM(1, 6) to choose an argument for a surprise round.
At the end, sign your name on your card as its author, and give credit when you use someone else's idea.
For a grown-up
This week your student learned procedures: named, reusable pieces of a program.
Ask: what is the difference between a parameter and an argument?
Ask: why should you read a license and give credit before using someone else's code, music or pictures?
Everything in this course is done on paper. No app, website or account is needed.
QUEST CHECK
  • Read the question.
  • Tap your answer.
In cheer(3), what is the 3?
In PROCEDURE addTen(number), what is number?
addTen(7) is called. What value comes back?
Quest reviewTrue or false?
The same procedure card can be called many times with different arguments.?
The player who is called may change the card's steps.?
Signing your card as author is a way of claiming credit for your work.?
WHY THIS EXERCISEReusing, following exactly and giving credit are the three habits of this week.
← Friday