Assignment 2 - Spring 2019

Assigned: Wed, Feb 20
Due: Mon, March 4

Assignment Setup

  1. Use your CS account to login to one of the Linux workstations in the classroom or Asprey Lab.

  2. Open a browser and copy/paste this URL:

  3. Login to Github and you will be prompted to accept this assignment
    1. Note: this will create your own copy of Assignment 2 for you to work on, but it's not on your Linux account yet

  4. Open a terminal window.

  5. Create a new directory for this assignment in your cs101 directory by entering the following at the Linux prompt:

    cd cs101
    mkdir assign2
    cd assign2

  6. Type the following commands to pull down a copy of this lab from GitHub:
    $ git init
    $ git remote add origin
    $ git pull origin master


This assignment begins where assignment 1 left off. As I demonstrated in class, for assignment 2 you will combine your two separate big-bang programs for the cat and the happiness gauge into one big-bang program. This new program will display the cat moving across the screen, and below the cat, the happiness gauge will be decreasing with each tick of the clock, unless the user presses the up/down arrow keys to feed/pet the cat.

Program 3: happy-cat.rkt

Now you will combine the first two big-bang programs you wrote for assignment 1 into a single big-bang program.

The first program you wrote had a cat move from left to right across the empty scene, wrapping around when it reached the right edge, continuing forever. The state of this world was a number, representing the cat's x-coordinate in the empty scene.

The second program you wrote created a happiness gauge that diminished with each tick of the clock—unless you made the cat happier by petting it or feeding it (with the “down” or “up” arrows on the keyboard). The state of this world was also a number, but this time it represented the value of the happiness gauge, which ranged in value from 0 to 100.

Now you get to put these two programs together into a single program, but to do so, you will need a structure to represent the state of the world, because you have two values you need to keep track of simultaneously: the cat's x-coordinate, and the value of the happiness gauge (both are numbers).

Here's the link to the exercises in the text: Section 5.11 More Virtual Pets

You will complete Exercises 88–91.


  • One function, one purpose (or, don't try to do too much in a single function)
  • Do the exercises in order, following the Design Recipe as you go (i.e., Hand-in artifacts)
  • Do not begin Exercise 89 before you have completed Exercise 88, etc.
  • Exercise 91 is more work, and requires more thinking, than 88–90.
  • Save a backup copy of your happy-cat.rkt, and call it happy-cat-90.rkt. This accomplishes two things:
    • You have a working copy of the program through Exercise 90 (you don't want to lose your hard work), and
    • If you make changes and completely break the program beyond salvation while working on Exercise 91, you can always reference/grab a fresh copy of happy-cat-90.rkt and start again.

In case you're curious, I had over 25 tests in my solution. You should have at least that many in your solution.

From a terminal window, type the following commands at the Linux prompt:

$ git commit -m "finished happy-cat.rkt" happy-cat.rkt
$ git push -u origin master