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

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)

hw02
defining functions
hw02

Due: Sep.12 (Mon) 14:00, on D2L and hardcopy.
Your submitted file should be named “hw02.rkt” as plain-text (which is what DrRacket saves as).

Standard instructions for all homeworks:

  1. (10pts) Recall from 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).

    For now, your code does not need to give a correct answer for pizzas whose diameter is less than twice the CRUST-WIDTH. However, you should still have tests for that situation, which contain the true, expected answer in the check-expect.

    (So, it's fine if those tests don't pass. If you really want to get your code working for that case -- again, NOT required -- you can either read about cond, or be clever in using the functions max or min.)

  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)).

    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.
    Friday: We will mention if in class on Friday.

conditions/requirements

In addition to the standard instructions for all hws above, here are some requirements for our homeworks:


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

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)


©2016, Ian Barland, Radford University
Last modified 2016.Sep.16 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.