CS U211 - Lab 4


Part I: HW Submission System

This part should be done with your HW partner. If you don't have one that's fine... if (s)he is not here, contact your local Csu211 representitive.

Navigate to this page and follow allong with the TA as we all learn how to submit our electronic assignments. Note You'll have to repeat this for your personal computer.


Switch Partners

The rest of lab assignment is to be completed in pairs. Please stand up, and find a new partner... not for good, just for the rest of this Lab.

Remember, each pair works on one computer. Change roles after each exercise! DON'T FORGET to apply the design recipe!


Part II: Structures Again

Exercise 1:

I'm writing a grading program to calculate grades at the end of the semester. You guys can help by giving a data definition. I want each assignment grade to contain the student's name, the assignment number, and their score on the assignment.

Give a data definition for a grade as a structure. Give three examples of grades.

Develop a function grade->string that consumes a grade structure and a number representing the maximum possible score on the assignment, and produces a descriptive string similar to:

"Bryan Chadwick, Assignment 5 -  14/28 : 50%"

Exercise 2:

Develop a function that computes the result of the formula (a+b)2/(a-b)2. Give an example of using the function. Then write down the evaluation steps in the Definitions window. Afterwards, use the stepper to compare the way you and DrScheme evaluated the formula. Unless you have made a mistake, both ways of calculating the result of the formula should give the same vaule.

See the Assignment #4 page for an example of this.

Part III: Structures and Unions

Hint: in the following exercises give names to your examples so you can use them again later.

Exercise 3:

Now that we have a simple grade structure, we want to expand it to include HW pairs. A pair-grade includes the each of the fields of the original grade but includes two names.

Write the structure definition for pair-grade and the data definition for the union, hw-grade.

Give three examples of pair-grades. Write a template, func-hw-grade, for functions that work with hw-grades.

Exercise 4:

Write pair-grade->string that takes a pair-grade and produces a string like before, but that includes both names:
"Bryan Chadwick and Matt Horan, Assignment 5 -  14/28 : 50%"

These two functions are good, but they both repeat code. Abstract them into a single function with the following contract:
;; magic-grade->string: String Number Number Number -> String
and combine your earlier definitions (grade->string and pair-grade->string) into a single definition of hw-grade->string which takes a hw-grade and computes the expected string for each case using your new (magic!) function. (Remember to use your template!)

Exercise 5:

Using your hw-grade defintions (and template), design the function passing? that takes a hw-grade and returns whether or not the person or pair recieved a passing grade on the assignment (greater than 65%).

Exercise 6:

Now design the function grade-curve that takes a hw-grade and the maximum grade, and calculates a new grade based on the following formula:
Use your template, and be sure to return a valid hw-grade.


Part IV: Extras - The World

In the following exercises, we will try to develop a simple game. Imagine we're on an Australian safari, and the bad-guys have just released some killer kangaroos!! (yup, that's a gun on it's back!) The government has asked us to shoot them down before they can do any harm (or build a simulation to train the Military).

Exercise 7:

Using the images below, design the function which-image that takes a number (between 0 and 3), and produces the corresponding image (left to right).
0 = 1 = 2 = 3 =

Exercise 9:

Our world will be two numbers: the first is the picture number and the second is the current x coordinate of the Kangaroo.

Design a structure to hold these values, and write the function world->scene that draws the correct image (from the number in the wolrd) at the Kangaroo's current coordinates (use 150 for the y) in a 400 x 300 empty scene.

Exercise 10:

Write the function update-world that moves the Kangaroo to the left 20 pixels (subtract from the x) and updates the current image number using the remainer function:
(remainder (+ (world-imgnum w) 1) 4)
What does this expression do? Ask your Instructor/TA/Tutor if it's not clear.

Exercise 11:

Design the function wrap-roo that takes the world and resets the x coordinate of the kangaroo to 400 if it is less than 0.

Don't forget to test everything individually!

Once you've tested things, change update-world to include a call to wrap-roo and add these lines to make your kangaroo come alive!

    (big-bang 400 300 .1 (make-world 0 400))
    (on-redraw world->scene)
    (on-tick-event update-world)

Exercise 12 (Extra Challenge):

I'm not sure how long this will take, but the Australian public is depending on you.

If you have time, add a target posn to the world representation, and draw a cross-hair at that point. Add a mouse function that sets the new target coordinates on a non-button-down mouse event.

If you're really motivated, add a score to the world and design a text placement in the scene to display it (within world->scene). If the mouse is pressed and the coordinates are close enough to the kangaroo then up the score.

What magic functions do you need to implement this and any other functionality you want to add?

Ask the Helpers for help if you have questions. Here's an idea of what I had in mind

That's It

If you had trouble finishing any of the exercises in the lab, homework, or just feel like you're struggling with any of the material, please feel free to come to office hours and talk to a TA or tutor for additional assistance.