Teaching 2500 F '12 Assignments The Hand In Set 1 Set 2 Set 3 Set 3h Set 4 Set 4h Set 5 Set 5h Set 6 Set 6h Set 7 Set 7h Set 8 Set 9 Set 8h Set 10 Set 9h Set 11 Set 12 Set 10h

### Problem Set 3h

Due date: 9/24 @ 11:59pm

Honors-section homework

The goal of this problem set is to practice designing data representations using structures and functions for processing such forms of data. Furthermore, you must follow the design recipe and the guidelines when you develop functions.

Note that you have to work on this problem set with your assigned partner. Partner assignments are posted on the blog.

# Structures

Problem A1
Consider the following structure definition:
``````
(define-struct automobile (year make model))
```
```
and evaluate the following expressions:
``````
(automobile-year (make-automobile 2010 'Porsche 'Boxster))

(automobile-make (make-automobile 2002 'Saab 'Viggen))

(automobile-model (make-automobile 2011 'Toyota 'Prius))
```
```
Now evaluate the following expressions, assuming a and b stand for arbitrary symbols:
``````
(automobile-model (make-automobile 2012 a b))

(automobile-make (make-automobile 2012 a b))
```
```

Formulate equations that state general laws concerning the relationships of `automobile-year`, `automobile-make`, and `automobile-model` with `make-automobile`.

Problem A2

Provide a structure definition and a data definition for representing points in time since the beginning of the week. A point in time consists of three numbers: days, hours, and minutes. (A week begins at 00:00 on Sunday.)

Problem A3

Develop the function `time->minutes`, which consumes a time structure (see Problem A2) and produces the number of minutes since the beginning of the week that the time structure represents.

Example:

``````
(time->minutes (make-time 2 10 19))
;; expected value:
3499
```
```

Explain the example.

# Cowabunga!

In many parts of the world, UFOs have been abducting cows. This should not surprise you, as you are a UFO pilot who has been sent on just such a mission. As you have probably been warned, however, the base of your UFO is made of a special alloy that cannot be allowed to come in contact with the ground. Your task, therefore, is to land your UFO atop a cow without crashing on Earth... which, as you may have heard, can turn you into a participant in certain "experiments".

The goal of this problem set is to practice designing data representations using structures and functions for processing such forms of data.

How the game works:

A cow is placed at an initial position on the bottom of the screen. The cow moves left at a fixed speed until hitting the left side of the screen at which point it changes direction and moves to the right until hitting the right side, and so on.

A UFO is placed at an initial position at the top of the screen. The UFO moves downward at a fixed rate. The UFO can be moved left/right by pressing the left/right arrow keys.

The game is over when the UFO hits the ground or the cow. The game should indicate in some way whether the game was won (UFO hits cow) or lost (UFO hits ground).

## Cows and UFOs

• Design a data definition for UFOs and Cows.
• A UFO has an X and a Y coordinate.
• A Cow has an X coordinate and is either going left or right.
• Define a function that moves a UFO down by some fixed amount.
• Define a function that moves a UFO either left or right by some fixed amount.
• Define a function that moves a Cow in the direction it is going by some fixed amount.
• Define a function that determines if a Cow is at the edge of the screen.
• Define a function that flips the direction of a Cow.
• Define a function that moves a Cow in the direction it is going, unless it at the edge, in which case, the Cow should flip directions, and then move.
• Define a function that determines if a UFO has captured a Cow.
• Define a function that determines if a UFO has crashed on the ground.
• Define a function that determines if the game is over.

## Animation system

• Define a data definition for Worlds. A World has a UFO and a Cow in it.
• Define a function that handles key events (maybe moving the UFO left / right).
• Define a function that renders the World as a Scene. Define a function that "ticks" the world (moves the UFO down and moves the Cow).
• Use the big-bang system to start the game.
Enjoy!

 last updated on Sun Dec 2 14:52:34 EST 2012 generated with Racket