Lab 1

All problems are to be done using DrRacket. You should be using typed racket, meaning that the first line of your definitions window should be #lang typed/racket. A note on style: your lines of code should not exceed 80 characters in width. See the text for numerous examples of proper indentation and code formatting. Also, note that striking the tab key will move a line of code to its canonical position.

Hw 1

The first thing you will do today is try to submit your first homework. If you haven't finished homework 1, that's okay, just commit and empty file to your repository. You can always commit as many times as you want before the deadline (6pm today)

Open a terminal and type the following commads (replacing CNETID with your CnetId):

svn co https://phoenixforge.cs.uchicago.edu/svn/CNETID-cs151-sum-17
cd CNETID-cs151-sum-17
mkdir hw1
touch hw1/hw1.rkt
svn add hw1
svn commit -m "Empty hw1 file added to repository"

The first command checks out a local copy of your repository. You should see a new folder created in your home directory. If you want to put your repository in a different location (on your desktop, for example), you can change directories (cd) before the first command. Alternately, you could move your repository (mv) after you create it.

The second command, cd CNETID-cs151-sum-17 changes your current directory, moving into the repository. The third command, mkdir hw1 creates a new directory named hw1 inside your local repository. The fourth command touch hw1/hw1.rkt creates an empty file named hw1.rkt inside the new hw1 folder you just created.

The fifth command, svn add hw1 adds the hw1 directory to the list of things on your local machine that svn will track. It also adds everything inside that folder. Finally, the sixth command, svn commit -m "Empty hw1 file added to repository" will send your changes to the server.

Now you should put your solution in the hw1.rkt file you've created. Once you save your changes, you can do the svn commit command again to send your changes to the server (but use a different commit message!).

You can check to see if you've done it correctly at this site: https://phoenixforge.cs.uchicago.edu.

Problem 1

The Chicago Transit Authority (CTA) has the following fares:

You are planning a trip, or series of trips, and have already determined how many times you will begin a trip on a train, how many times you will begin a trip on a bus, and how many times you will pay the additional transfer fare. (In particular, while there are various rules dictating when you do and don't need to pay for a transfer, assume you have already counted exactly how many times you will actually need to do this.)

You have a Ventra farecard, currently with a zero balance, and need to load adequate transit value on it for your upcoming trip(s). As an added wrinkle, however, you are loading money onto your card from the Ventra web site, rather than from a physical ticket vending machine, so you can only add value in $5 increments. This means that you may need to round up to the nearest multiple of $5, if your fares work out to be other than a multiple of $5, in order to have enough transit value for all your trips. (The website does not allow you to enter an arbitrary value, unlike the vending machines.)

Write the function add-to-ventra which, given the number of train fares, bus fares, and transfers, in that order, all Integers, returns the amount of money, an Integer and a multiple of $5, to add to your card to cover the specified trips. This function must add enough value to an empty card to cover the trips, but if rounding up to a multiple of $5 is required because the fare is not coincidentally a multiple of $5 already, must only round up to the nearest multiple, not a greater one. The function's type must be (-> Integer Integer Integer Integer).

For example, if you need 2 train fares, 1 bus fare and 3 transfers, then you would need 2 * $2.25 + 1 * $2.00 + 3 * $0.25 = $7.25 and you would have to load ten dollars onto your card. Therefore, calling (add-to-ventra 2 1 3) should give the result 10.

In your implementation, you might find the following built-in function to be helpful: exact-ceiling, which consumes a number and produces the nearest integer equal to or greater than it. Rounding up to the nearest multiple of five can be tricky: feel free to discuss with your classmates.

Problem 2

Define a function ball-at. This function will take one integer as input. It will create an image as output. That image should be a rectangle with a black outline of width 50 and height 200. There should be a solid blue ball in box with radius 10. The input is the number of pixels the ball should be from the bottom of the box. Examples:

(ball-at 0) (ball-at 50) (ball-at 180)

Before you start, spend some time thinking about which functions will be easiest to use. You can do this problem with overlay/offset, overlay/xy, overlay/align/offset, or just using overlay and some white rectangles. Spend some time reading the documentation. Ask your neighbor what method they think would be a good idea.

Submit Your Work

Submit your work by committing lab1/lab1.rkt to your CS151 subversion repository by Thursday, June 22 at 11:59 am. All your work must be contained in that one file.

You should commit your work early and often. Intermediate commits — that is, commits made along the way to the final commit — are strongly encouraged; only your last commit before the deadline will be evaluated by your graders.