At home exercise:
Working for a vet clinic, we need to model pets.
The clinic cares about the following:
type of animal, age, has-had-shots?, chases-vets?.
Follow all appropriate steps of the design recipe.
- make a structure for pets
- make some examples (perhaps giving it a name, perhaps not)
- write an expression that extracts whether the pet has had its shots?
- write a function needs-shots?,
which returns true exactly when
the pet is older than 1yr, and hasn't already had its shots.
- write a program pet-whoopie, which takes in two pets,
and returns a new pet of age 0 w/o shots;
the pet's type is the same as the first parameter's pet-type.
- write a program age-pet: it takes in a pet,
and returns a pet of the same type which is a year older.
Note: calling age-pet or pet-whoopie
does not change any existing pets,
no more than calling + changes the numbers it receives.
These functions return new pets.
Reminder of the Design Recipe:
- data analaysis (how will you represent the problem?)
- examples of data (sample inputs)
- contract, purpose, header
- develop examples of functions (use the sample inputs)
- write the body.
- test
Note that if different problems both involve
the same answer to some parts, you don't need to repeat them.
(E.g., the last two programs both have the same
data-representation of a pet, and the same
examples of the data will suffice)