=====
CS 111 - Week 4 Lecture 2 - 2024-09-19
=====
=====
TODAY WE WILL:
=====
* announcements
* review cond
* refactoring example
* another example: dropping penguins!
* interval data, enumeration data
* example with enumeration data
* prep for next class
=====
* should be starting Homework 3;
deadline/at least first attempts due by this Friday, Sept. 20
* submit early, submit often!
=====
intervals and enumerations!
interval data and enumeration data
=====
* these both happen to be kinds of data where
branching is useful!
* from course text:
"An interval is a class of ... numbers via boundaries"
* these boundaries tend to define a finite number of categories
* but each category MIGHT contain many things!
* one approach in a function involving interval data
is to have a cond with a branch for each category
of data (for each category of numbers)
* (you might find you can refactor and use fewer
branches, or even no branches -- BUT this is a
good place to start!)
* CS 111 class style:
for interval data, you need at least one test per category
and at least one test per boundary between categories
* functions banana-report, bad-star-size?, and draw-penguin-scene
are functions involving intervals
--------
* There's also ENUMERATION data -- (text calls them enumerations)
* when your data is a value from a relatively small number
of discrete, specific values
* like the possible colors of a traffic light!
like the possible arrow keys on a game controller!
like the possible answers for a multiple-choice question!
* one approach in a function involving enumeration data
is to have a cond with a branch for each value in the
enumeration,
PLUS an else branch if the function's purpose describes
something to do in the case of some other value
* (again, you might find you can refactor and use fewer
branches, or even no branches -- BUT this is a
good place to start!)
* CS 111 class style: you do need a test for each of the
enumeration's values -- and IF your function's purpose
specifies a particular result for a value NOT in the
enumeration, you should include a test for that also
* function next-sound, in today's in-class examples,
is a function involving an enumeration