8.10

Homework 2b

home work!

Programming Language #lang htdp/bsl

MUST BE DONE ON YOUR OWN.

Due Date Thu at 9:00pm (Week 2)

Purpose Practice with structs and conditionals

MAKE SURE YOU INCLUDE TESTS FOR ALL OF YOUR FUNCTIONS.

Submit all of the following in a single .rkt file to Gradescope You will get immediate feedback and can resubmit.

Exercises

Exercise 1 Rewrite your "dist" function from Homework 1b using the "Position" data definition.

Exercise 2 The Manhattan distance of a point to the origin considers a path that follows the rectangular grid of streets found in cities like Manhattan.

Note that there are multiple strategies: one can take a "direct" strategy, going as far left as needed, followed by as many upward steps as needed. You could also take a "random walk", going some blocks leftward, some upward, and so on until the destination—here, the origin—is reached. Stop! Does it matter which strategy you follow?

Design the function manhattan-distance, which measures the Manhattan distance of the given posn to the origin.

Exercise 3 Whenever Britons travel to Europe, they need to exchange Pounds Sterling for Euros. A currency-exchange service provides the following chart...

Notice that there is a flat fee charged for service as well as a conversion rate for each Pound -> Euro. For example, anything less than 5 Pounds gets eaten by the service fee, but 10 Pounds gets you 4 Euros.

Write a function, gbp->eur, to convert from Pounds to Euros.

Hint: it can be useful to write out a table of input/output pairs to help understand these types of mathematical relationships (and these can then provide great tests!)

Exercise 4 Write the function leap-year? which determines if a natural number represents a leap year in the Gregorian calendar.