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

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)

hw03b
functions for union types
and, images intro

Due:
Section 01: Sep.21 (Mon) 15:00, on D2L and hardcopy
Section 11: Sep.23 (Wed) 23:59, D2L (but start it by class on Monday).
Your submitted file should be named “hw03b.rkt” as plain-text (which is what DrRacket saves as).

Standard instructions for all homeworks:

Open DrRacket (either in labs, or you can download it to your own computer from racket-lang.org). The first time you start DrRacket, it will ask you to choose a language; select Language > Use Language... > Teaching Languages > Beginning Student, for now.

Follow the design recipe, steps 4,5,7,8.

  1. Data definition: A directory-response is one of:

    (15pts) Write a function which, given a directory-response, returns a string: either

    corresponding to the three cases in our data-definition, respectively.

    You can think of this function as being one part of a larger program which queries a campus-directory, such as radford's, and then has to use the response it gets.

    NOTE: Your function will be given directory-responses: so if you're given a string, you can deduce (from this def'n) that its length is already in [1,14). This is not something you need to check for, or handle.

    To think about: As per the design recipe since our data-definition has three different variants, you will have a cond with how many branches? (You don't need to write a template (step 3a) separately from your final code, for this homework.)


  2. Images in racket

    To experiment with functions-which-create-and-handle-images in DrRacket, include (require 2htdp/image) near the top of your file. Then you should be be able to evaluate each of the following:

    (rectangle 80 20 'solid 'blue)
    (circle 20 'solid 'red)
    (ellipse 80 20 'outline 'orange)
    
    (beside (rectangle 80 20 'outline 'blue)
            (circle 20 'solid 'red))
    (underlay (rectangle 80 20 'outline 'blue)
             (circle 20 'solid 'red))
    ; Think of 'underlay' and 'beside' as being "addition for images"
    
    ; underlay with an offset:
    (underlay/offset (rectangle 80 20 'outline 'blue)
                    0
                    10
                    (circle 20 'solid 'red))
    
    
    ; If you want to explore documentation:
    ;   In DrRacket, position the caret on a function-name
    ;   like 'underlay', and hit F1.
    

    Test cases for images

    For functions that return an image, your expected-value should either be (a) an expression involving calls to: the image primitives and/or previously-tested functions, OR (b) an image-literal (but, show the expressions you used to create that image-literal).

    For example, if the problem were to "create a function that takes in a width, and returns a solid purple rectangle with the given width and a 16:9 aspect ratio", then the "expected result" part of the test cases might involve calling the image-library's functions like rectangle:

    (check-expect (screen 32) (rectangle 32 18 'solid 'purple))
    (check-expect (screen 16) (rectangle 16 9 'solid 'purple))
    (check-expect (screen 0) (rectangle 0 0 'solid 'purple))
      ; Note: for the expected 0x0 rectangle, I could equally well write:
    (check-expect (screen 0) empty-image)
    
    Or, since DrRacket supports image literals (!), I could copy/paste images as the second argument to check-expects: a sample check-expect, with an image-literal as the expected result


    1. example results of calling donut, eyes
    2. (3pts) Write a function which takes in a size, and returns an image of a brown donut. (Mmmm, doughnut.)
    3. (3pts) Write a function eyes which takes a size and a color, and returns two colored rings side-by-side.
    4. (4pts) As needed, refactor the above functions so that there is little-to-no repeated code. (If the underlying helper function has a solid set of tests, the final function might get by with fewer tests — perhaps even just one.) You only need turn in your refactored versions.

    You only need steps 4,5,7,8 of the design recipe (once you decide what how you'll represent "size", which is a straightforward choice), and we're only using existing, simple datatypes (so no steps 1-3 or 6).

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)


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