;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-abbr-reader.ss" "lang")((modname practice_test) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "htdp"))))) ; Q1 (1 point): What does the following statement evaluate to? (+ 3 (- 4 3)) ; Q2 (2 points): Consider the following function signature, purpose, and header: ; two-x : number -> number ; returns two times the supplied number (define (two-x x) (...)) ; Complete the design recipe by writing the function body and one test ; Q3 (2 points): Consider the following data definition: ; a cheese is a: ; - symbol name ; - number cost ; - symbol color (define-struct cheese (name cost color)) ; Write a template for this data definition ; Q4 (2 points): Consider the following template: ; (define (fun-for-food f) ; (cond [(cheese? f) (...)] ; [(bread? f) (...)] ; [(broccoli? f) (...)]) ; Write the data definition for "food" that corresponds to the template above. ; Assume data definitions and struct statements have already been supplied for ; bread and broccoli, similar to the for "cheese" above (the details of these ; definitions are unimportant for the "food" definition). (define-struct bread (name cost color)) (define-struct broccoli (name cost color)) ; Q5 (6 points): Consider the following data definition: ; a list-of-food is either: ; - empty ; - (cons food list-of-food) ; where food is defined as in your answer to Q4 above ; Use the design recipe to write a function "count-cheese," which counts ; how many foods in a list-of-food are cheeses. ; Guidelines: ; You don't need to explictly write out the template, but it may be helpful to do so ; You don't need to supply examples or tests, use the test cases given below. ;Test cases: (check-expect (count-cheese (list (make-cheese 'cheddar 12 'orange) (make-bread 'wheat 8 'brown) (make-cheese 'swiss 5 'white))) 2) (check-expect (count-cheese empty) 0) ; Q6 (2 points): Consider the following function: (define (f x) (cond [(> x 0) 7] [else (f x)])) ; a) what is the result of (f 4) ? ; b) what is the result of (f -5) ?