Grading Rubric for Homework 5

Color code: red notes are instructions in my solution to the graders; the rest is what we expect to see in your homework solution.
TOTAL: 67 points:
59 points for Problem A* exercises
5 points: if the code obviously doesn't run, subtract 5 points
3 points: for news
  1. Write down point subtractions only.
  2. Write their score /67 next to the student name, circle it, and put down your email address.
  3. Write down grades and report to your head TA.

TA GRADES: 3pts

Problem 0: 3 points
[1] if it is just one paragraph (with fewer than 200 words, punish any excess words)
[1] mark typos, allow for three at most
[1] mark incomplete sentences, allow at most one



Tutor GRADES: ;; PROBLEM A0: 6 points ;; 2 points per signature


;; PROBLEM A1: 6 points ;; Part 1:
;; The Definitions: (define (fahrenheit->celsius f) (* 5/9 (- f 32))) (define (celsius->fahrenheit c) (+ (* 9/5 c) 32)) ;; The "Launch" (celsius->fahrenheit (fahrenheit->celsius 212)) ;; The Calculation: ;; [1pt] = by plug-in (celsius->fahrenheit (* 5/9 (- 212 32))) ;; [1pt] = by arithmetic (celsius->fahrenheit (* 5/9 180)) ;; [1pt] = by arithmetic (celsius->fahrenheit 100) ;; [1pt] = by plug-in (+ (* 9/5 100) 32) ;; [1pt] = by arithmetic (+ 180 32) ;; [1pt] = by arithmetic 212
;; PROBLEM A2: 26 points ;; Problem: Provide a data definition for lists of Posns. ;; Solution: [2pts, one per clause] ;; === ;; A LOP is one of: ;; -- empty ;; -- (cons Posn LOP) ;; Problem: Provide a template for processing such lists. ;; Solution: ;; [7pts: 2 for 2 cond, 2 empty?/else, 2 first/rest, 1 recursion] ;; === #; (define (temp l) (cond [(empty? l) ...] [else ... (first l) ... ;; the first Posn ... (rest l) ... ;; the rest of the list of Posns ... (temp (rest l)) ;; the rest, processed according to the purpose stmt ])) ;; Problem: Design the function lop-length, which counts how many Posns are ;; on a given list of Posns. ;; Solution: [4pts, as below] ;; === ;; [1pt] lop-length : LOP -> Number ;; [1pt] how many posns are on the given list of Posns (define (lop-length l) (cond ;; [1pt for (+ 1 ...)] [(empty? l) 0] [else (+ 1 (lop-length (rest l)))])) ;; [1pt for tests] (equal? 0 (lop-length empty)) (equal? 2 (lop-length (cons (make-posn 1 1) (cons (make-posn 1 0) empty)))) ;; Problem: Design the function lop-x, which extracts all the x coordinates ;; from a list of Posns. ;; Solution: [6pts, as below] ;; === ;; [1pt for defining LON] ;; A LON is one of: ;; -- empty ;; -- (cons Number LON) ;; [1pt] lop-x : LOP -> LON ;; [1pt] extract the x coordinates, in order, from the given list of Posns (define (lop-x l) (cond ;; [2pts: 1 for cons, 1 for posn-x/first] [(empty? l) empty] [else (cons (posn-x (first l)) (lop-x (rest l)))])) ;; [1pt for tests] (equal? empty (lop-x empty)) (equal? (cons 1 (cons 0 empty)) (lop-x (cons (make-posn 1 1) (cons (make-posn 0 1) empty)))) ;; Problem: Design the function lop-draw, which consumes a list of Posns and adds ;; them to an empty scene of 300 x 300 as red dots with a radius of 3. ;; Solution: [7pts, as below] ;; === ;; [1pt] lop-draw : LOP -> Image ;; [1pt] add the Posns on l as red dots to a blank empty scene (define (lop-draw l) (cond [(empty? l) (empty-scene 300 300)] [else (add-to-image (first l) (lop-draw (rest l)))])) ;; [MF: If add-to-image was inlined correctly, then give 2 pts.] ;; [1pt] add-to-image : Posn Image -> Image ;; [1pt] add the given Posn to the given Image as a red dot of radius 3 (define (add-to-image p i) ;; [1pt for posn-x/posn-y] (place-image (circle 3 'solid 'red) (posn-x p) (posn-y p) i)) ;; [2pts, one per function] (equal? (place-image (circle 3 'solid 'red) 100 100 (empty-scene 300 300)) (add-to-image (make-posn 100 100) (empty-scene 300 300))) (equal? (place-image (circle 3 'solid 'red) 100 100 (place-image (circle 3 'solid 'red) 30 200 (empty-scene 300 300))) (lop-draw (cons (make-posn 100 100) (cons (make-posn 30 200) empty))))
;; PROBLEM A3: 21 points ;; Problem-provided definitions: (define-struct txt (content x y)) ;; Str = (make-txt Number Number String) ;; LoStr is one of: ;; -- empty ;; -- (cons Str LoStr) (define-struct world (image hidden)) ;; World = (make-world Image LoStr) ;; intepretation: ;; the world's image represents the image that the audience can see ;; the world's list of Str represents the still hidden elements ;; Problem: Create a world with an empty blue 300 x 300 canvas to which the ;; program will add the following three phrases: "Hello World", "Nice to ;; Meet You", and "Good Bye, World" ;; Solution: [5pts: 2 for factoring out x0, 3 for the world] ;; === (define x0 20) (define world0 (make-world (place-image (nw:rectangle 300 300 'solid 'blue) 0 0 (empty-scene 300 300)) (cons (make-txt "Hello World" x0 75) (cons (make-txt "Bye World" x0 125) (cons (make-txt "Nice Knowing You World" x0 175) empty))))) ;; Problem: Design the function display, which consumes a world and returns ;; its current image. ;; Solution: [4pts, as below] ;; === ;; [1pt] World -> Image ;; [1pt] convert the world into the image that the audience should see (define (display w) ;; [1pt for world-image] (world-image w)) ;; [1pt for tests] (equal? (circle 3 'solid 'red) (display (make-world (circle 3 'solid 'red) empty))) ;; Problem: Design the function next, which consumes a world and adds the ;; next hidden Str to the currently visible slide image. ;; Solution: [12pts, as below] ;; === ;; [1pt] World -> Next ;; [1pt] add the next Str on the world's list to the image, if any (define (next w) (cond ;; [1pt for recognizing that the list can be empty] [(empty? (world-hidden w)) w] ;; [2pts: 1 for adding the text to the image, ;; 1 for placing the rest into the second slot] [else (make-world (add-text (world-image w) (first (world-hidden w))) (rest (world-hidden w)))])) ;; [if add-text is inlined correctly, give 4 points] ;; [1pt] Image Str -> Image ;; [1pt] add the text from the given str at the specified place in 22 font/red (define (add-text img str) ;; [3pts for txt-x, txt-y, txt-content] (place-image (text (txt-content str) 22 'red) (txt-x str) (txt-y str) img)) ;; [2pts for tests, 1 per function] (equal? (place-image (text "hello world" 22 'red) 100 100 (empty-scene 300 300)) (add-text (empty-scene 300 300) (make-txt "hello world" 100 100))) (equal? (make-world (place-image (text "hello world" 22 'red) 100 100 (empty-scene 300 300)) empty) (next (make-world (empty-scene 300 300) (cons (make-txt "hello world" 100 100) empty))))