RU beehive logo ITEC dept promo banner
ITEC 380
2016summerIII
ibarland

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)

hw02b
defining functions
hw02b

Due: May.31 (Tue) 17:30, on D2L.
Your submitted file should be named “hw02b.rkt” as plain-text (which is what DrRacket saves as).

Standard instructions for all homeworks:

It's intended that you complete hw02 (on D2L) before working on this problem.

Follow the design recipe, steps 4,5,7,8. (You don't need to label each step; just turn in the final result.)

  1. (10pts) Recall that in May.17's lecture, we demo'd the steps of writing a simple function, pizza-area, which computed the area of a pizza given diameter. We will write a couple of similar functions.

    Of course, Pizzas have topping in the middle, and crust around the edge. (You can think of the full pizza being a disc, with a smaller pure-topping-covered disc inside of it.)

    1. Define a named-constant CRUST-WIDTH, which should be 2 inches.
    2. Some people ignore the crust of a pizza, and just want to know how much topping-covered area they'll be getting when they order a pizza. Write topping-area, which returns the amount of pizza covered in topping (in square-inches), for a given diameter (in inches).
    3. Other people love the crust, and only care about how much crust is on their pizza! Write crust-area, which returns the amount of crust (in square-inches) for a pizza of a given diameter (in inches).
  2. (10pts) Write the function has-suffix?, which takes in two strings and returns whether or not the first string ends with (the letters of) the second.

    Note that this is a computer-sciency definition of “suffix”. It has nothing to do with syllables or English. More precisely: we say that string a has b as a suffix, iff: there exists a string x such that (string=? a (string-append x b))1.

    hint:You can certainly use cond (or if) if you like, but they're not actually needed; you can instead use a min or max in a clever (but standard) way.

conditions/requirements

In addition to the general requirements above, here are some more specific to this homework:


1 We'll see later how, in a declarative language (Prolog), this definition alone constitutes runnable code.      

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)


©2015, Ian Barland, Radford University
Last modified 2016.Jun.06 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.