2023 Review 3

Exam from 2023, last day.

You may consult the Racket Help Desk, the book Picturing Programs, and the class web site. You may use the posn-util without comment.

No other reference materials are allowed. (No old assignments, stack overflow, ChatGPT, etc.)

  1. A playing card has an image and a value. The value is a number 1 through 13.

     (define-struct card (value image))
    

    The values 2 through 10 print normally. Other values print differently: 1=A, 11=J, 12=Q, 13=K. This corresponds to standard playing cards Ace, Jack, Queen, and King.

    Write the function render-card, which takes in a card struct and puts out a 70x100 image of the card with the value in the upper left in a 20 point black font.

    As an example

     (render-card (make-card 1 pic:hacker))
    

    produces

  2. A-sample: number(percent) (Listof Number) -> (Listof Number)

    A-sample takes in a integer percentage, and each number in the list has that percent chance of ending up in the output.

    Example: (A-sample 80 nums) produces a list where each item in nums has an 80% chance of ending up in the output.

    No check-expects necessary. Show the output of three identical runs when your code loads.

  1. semi-double: (Listof Number) (Listof Number) -> (Listof Number)

    Double all of the numbers in the first list that appear in the second list.

     (check-expect (semi-double (list 1 2 3 4 5) (list 2 5 1))
                   (list 2 4 3 4 10))
    

II. Animation (45 min)

You are going to write a “screen distance measurer”. It is going to keep track of the total distance between clicks.

  • Upper left corner shows cumulative total distance between clicks.
  • The first click places “anchor” to start measuring distance.
  • After the first click, you draw a line to where the mouse is.
  • The second click adds the distance to the total and makes the line vanish (until you click again).

Make a plan before you start coding!!

The starter code creates the background shown.

A video showing the animation in action is available on YouTube and there is a Google Drive link for CPS.

III. See Notes in Source