CSC 160 Spring 2014 - Homework 12 (100 points)
Assigned May 5, Due MONDAY May 12

1) This assignment will NOT be accepted late for any reason, since solutions will be posted to Moodle Tuesday morning (5/13).
2) Assignments with time stamps during class time (Mon or Wed 4:15-5:30pm) will be given a grade of ZERO.
3) In the spirit of the pair programming article that you read and summarized in HW5, this week's homework assignment may be done in pairs. If you choose to work in pairs, you must find time outside of class to work together in person at one computer. As per the syllabus, you cannot "pair-off" with the same person more than once during the semester. If you choose to do the assignment in pairs, please submit one copy through Moodle where both last names are used in each file name and both names appear as a comment at the top of each pane (Definitions and Interactions).
4) Start this homework as soon as possible so that you have time to get any help you may need from the instructor or course tutor prior to when the assignment is due.
5) Do not start the exercises until to have fully read and fully understood the corresponding textbook sections. If there is something you do not fully understand, you must contact the instructor or course tutor prior to starting the assigned exercises.


[75 (+25) pts.] Chapter 20A
Read Sections 20.1-20.4 of the textbook.

Do the following exercises in DrRacket (show all Design Recipe v2 steps whenever you Design a Function):
  • Design the function: on-top?. It takes a point and returns true if it is in the uppermost 50 pixels of the window.
  • Exercise 20.4.2: Design the function: above-diagonal?. It takes in a posn and returns true if the point is above the diagonal. [Hint: In Racket, the diagonal goes from the top left corner (also known as the origin) to the bottom right corner.]
    BEFORE CONTINUING, TYPE THE DEFINITION OF THE DISTANCE FUNCTION FROM THE CHAPTER 20 LECTURE SLIDES INTO THE DEFINITIONS PANE.
  • Design the function: within-distance?. It takes in two posns and a number, and tells whether the posns are within that distance of one another. (Hint: You will need to call the distance function written in class!)
  • Extra credit: Design the function: find-area. It consumes two Posn structures -- one representing the center of a circle and the other representing a point on its circumference -- and produces the area of the circle. (Hints: You will need to call the distance function written in class. You may also want to call the area-of-circle function from CW4.)


    [25 (+25) pts.] Chapter 20B
    Read Section 20.5 of the textbook.

    Do the following exercises in DrRacket (show all Design Recipe v2 steps whenever you Design a Function):
  • Exercise 20.5.3: Design a function named scale-posn which takes in a number and a posn, and returns a posn formed by multiplying the number by each of the coordinates of the input posn. For example, (scale-posn 3 (make-posn 2 5)) "should be" (make-posn 6 15).
  • Extra credit: Exercise 20.5.2: Design a function named swap-x-y that takes in a posn and returns a new posn with the coordinates swapped: the x-coordinate of the output should be the y-coordinate of the input, and vice versa.


    Grading Contract Purpose Data Analysis Examples Skeleton
    w/Inventory
    Add details
    to skeleton
    Definition
    25 points: on-top? /2 /1 /3 /3 /2 /2 /12
    25 points: Exercise 20.4.2 /2 /1 /3 /3 /2 /2 /12
    25 points: within-distance? /2 /1 /3 /3 /2 /2 /12
    Extra Credit: find-area /3 /1 n/a /3 /2 /2 /14
    25 points: 20.5.3 /3 /1 n/a /3 /2 /2 /14
    Extra Credit: 20.5.2 /3 /1 n/a /3 /2 /2 /14



    Last Modified: 5/11/14