CS 1101 - A-term 08

Homework 1 - Composing Functions

Due: September 3 at 11:59pm

Read the expectations on homework. You will be doing this homework individually.

Assignment Goals


The Assignment

In Scheme, we write larger programs and functions by combining the results of smaller ones. This set of questions helps you practice combining programs. Using a set of functions that we've provided for you, you will create images of swatches of fabric and items of clothing printed in those fabrics. The functions we've already written are in a file called a teachpack. Go to the Language menu in DrScheme and choose Clear all teachpacks. Now right-click on this link: the fabric teachpack and download it to your computer, then use the Add Teachpack option under the Language menu to load the teachpack contents into DrScheme (use "Install Teachpack..."). After you add the teachpack, hit the Run button.

The teachpack provides three images of clothing - a white tshirt, a white hat, and a pair of white gloves, and three smaller images that can be used for logos or to add prints to a fabric - a worm, a chili pepper, and a flower. It also provides a set of functions for creating fabric in different colors and prints, that are sized to fit certain items of clothing. Here is a description of the functions and images in the teachpack.

Problem 0 (you won't be turning this part in, but completing Problem 0 will make working the remaining problems much easier)

In the Interactions window:

Exercises to pass in for Homework 1

Change to the Definitions window
Write your name and login name as a comment at the top of the file.

Use comments in your file to clearly indicate the number of the problem you are solving.

  1. Write an expression to create a swatch of green fabric with pink stripes in one direction and yellow stripes in the other direction. Your fabric swatch should be sized for a hat.

  2. Write an expression to create an image of a hat printed in the fabric you created in Problem 1.

  3. Use define to create a fabric of your own design, sized for a tshirt. Name your fabric TSHIRT-FABRIC. Your fabric design should involve the use of at least two functions from the fabric teachpack.

  4. Write a function create-sized-swatch that consumes an image of a clothing item and produces an image of a swatch of fabric of your own design, that is sized correctly for the given clothing item. This is a function - don't forget to document it with a contract and purpose. Show three test cases for your function, one for each kind of clothing.

  5. Write a function cut-clothing that consumes an image for a clothing item and an image of a swatch of fabric sized to fit that clothing item, and produces an image of the clothing item in the given fabric. This is a function - don't forget to document it with a contract and purpose. Show two test cases for your function: one which creates an image of a tshirt printed in TSHIRT-FABRIC, and one which uses create-sized-swatch to create an image of gloves.

  6. Write a function add-center-logo that consumes an image for a logo and an image for a clothing item and produces an image of the clothing item with the logo centered on it. As before, start with a contract and purpose. Show two test cases for your function, at least one of which creates a clothing item in which the logo appears over a printed or striped fabric.

  7. Write a function stack-logos that consumes images of two logos and returns an image with the first logo just above the second logo. [HINT: use create-solid-fabric to create an image large enough for the two logos.] You should center the logos on the fabric. Start with a contract and purpose, and provide test cases.

    Note that Scheme has a function max that consumes two numbers and produces the larger of the numbers.

  8. Write a function side-by-side-logos that consumes images of two logos and returns an image with the first logo to the left of the second logo. [HINT: use create-solid-fabric to create an image large enough for the two logos.] You should center the logos on the fabric. Start with a contract and purpose, and provide test cases.


What to Turn In

Using web-based turnin, turn in a single file hw1.scm containing all code and documentation for this assignment. Your name must be listed in a comment at the top of the file. Files submitted after 11:59pm on Wednesday, September 3, will be considered late and will be given a grade of zero.