Due: Oct 11th (Thurs) at the end of your lab session.

CMSC 10500, Fall 2012. Lab 2 -- Have an Okay Day!

This lab will give you practice writing functions and conditional statements.


A. Preliminaries

1. Style

Recall the use of function contracts from class. A contract takes the form
function-name : first-input-type second-input-type ... -> output-type
For example, the function to find the area of a rectangle has the contract

rectangle-area : num num -> num

since it takes two numbers (the width and height) as input, and returns a number corresponding to the area.

A quick note about coding style: Indentation and line-breaks make your code easy to read and are good programming practices, so please pay attention to them. For example, here's a definition for the area of a trapezoid:

;; trapezoid-area : num num num -> num
;; computes the area of a trapezoid using the standard formula
(define (trapezoid-area base top height) (* height (/ (+ base top) 2)))
That's a lot of code on one line! Here's an indented version:
;; trapezoid-area : num num num -> num
;; computes the area of a trapezoid using the standard formula
(define (trapezoid-area base top height)
   (* height
      (/ (+ base top)
         2)))
The convention for line-breaks is to put a break after the function header, and then a break after the first operand in each expression. We usually don't break very short expressions like (+ base top). DrRacket should indent your code automatically if you insert a line break (by pressing Enter or Return). If it does not, press Tab with your cursor anywhere at the line you're indenting.

2. Setup

Let's get started!

This should bring up a file with (require 2htdp/image) on the first line, and a few commented statements. Write your name at the place it indicates, and proceed with the assignment.

You may use any DrRacket operator for this lab except the scale function.


B. Simple Definitions

Write the following definitions right under the "Auxiliary functions" line in lab2.rkt. Don't forget to include your comments and the function contracts.


C. Generating Parts of a Face

Continue writing these definitions below the "Auxiliary functions" line.

At this point, you should save and commit your work if you have not already.


D. Generating a Face

Save and commit your work. You are now done with the mandatory part of the lab.


E. Happy and Sick Faces

Start working on this problem after you have completed everything else. Submit whatever you have at the end of this lab. You will have an opportunity to finish in the homewok for this week.

Make sure your code is commented, has contracts, and is neatly organized then save and commit it:
svn commit -m "BLAH"
where BLAH stands for a meaningful message.

Have a nice day!


Adapted by Lamont Samuels in 2012 from material designed by Sravana Reddy, Gabri Turcu and Adam Shaw.