Write complex functions that consume, modify and produce structures
Deepen their understanding of structures, constructors and accessors by being introduced to a new data structure.
Students define a new data structure: a party
The Party Planner file preloaded on students’ machines
Pens/pencils for the students, fresh whiteboard markers for teachers
Class poster (List of rules, design recipe, course calendar)
Editing environment (Pyret Editor)
Seating arrangements: ideally clusters of desks/tables
- In the last lesson you learned about a new kind of data structure, called a Cake. However, a Cake isn’t the only kind of structure - we can create any kind we want! Let’s define another one. In this exercise, you’ll be a party planner. Data structures will be a useful way to represent each Party that you’re planning, keeping track of its location, theme, and number of guests.
What datatype could be used to represent the location of a Party?
What about the Party’s theme? (This could be something like "50s" or "laser tag".)
How about the number of guests?
Fill out the Party structure definition on Page 13 in your workbook.Once the Party structure is defined, you have access to new pieces of code: a function to make a Party, and three dot-accessors to get the location, theme, and number of guests out of the Party.
What is the Name of the function that creates a Party?
What is the function’s Domain? (What kinds of things are part of a Party?)
What is the Range of this function?
On Page 13, use the constructor function to define two new Parties of your own.
Right below your new Parties, list how you would access the fields of party2. How would you get the location out of party2? (Think about how you got the model or color out of a Car.)
Open the Party Planner file. Take a look at the first four lines in the definitions area. Do they match what you have written in your workbook for the data definition of Party?
Now define two new Party structures of your own. No matter what party you’re planning, make sure that your party has the right inputs in the right order.
As with the Cake structure, repetition is key: have students identify the fields of each of their parties, and ask them lots of questions: How would you get the theme out of Halloween? How would you get the number of guests out of JulyFourth?