Homework 3
Please read chapter 5: Adding Structure, in the textbook. Also read section 1, 2, 3, and 4 ("Getting Started", "Functions and definitions", "More Typed Racket features" and "Defining more types") in the Typed Racket Notes.
Be sure to include type, purpose, definition and tests for all functions.
Include the following at the top of your homework:
#lang typed/racket (require typed/2htdp/image) (require typed/test-engine/racket-tests)And include (test) at the bottom of your homework.
Problem 1
These are the flags of Greece and Turkey.
Write two functions with the following type declarations:
(: flag-Greece (Nonnegative-Integer -> Image))
(: flag-Turkey (Nonnegative-Integer -> Image))
In each case the numerical argument is the desired width of the image. In other words, a call to (flag-Greece 88) should produce an image of the Greek flag that is 88 pixels wide and correspondingly tall.
Note: with functions that produce images, check-expect tests are not appropriate. Instead, use a well-chosed selection of "eyeball tests" such that you can see directly whether your functions are working or not.
The proportions of the flags drawn by your functions need not be exact, but you should fiddle with them until they are convincing, given the reference images here.
Problem 2
Write a function (: divisible-by-three? (Integer -> Boolean)) to return true if the input is divisible by three and false otherwise. The built in function remainder may be useful.
Problem 3
Write a function (: leap? (Integer -> Boolean)) to compute whether or not a year is a leap year. Leap years are not simply every fourth year. A year is a leap year if it is divisible by 4 and not divisible by 100, or if it is divisible by 400.
Problem 4
Write a function (: larger (Image Image -> Image)) that takes two images and returns the one that has the larger area. Use the image-width and image-height functions.Submit your work in your repository in hw3/hw3.rkt by noon Monday, June 26.