;; Answers for Exam 3 in CIS 352, Spring 2008 ;; ;; DISTRIBUTION OF SCORES ;; range: scores ;; 0- 10: ;; 11- 20: 12 ;; 21- 30: ;; 31- 40: ;; 41- 50: 47 48 48 ;; 51- 60: 58 ;; 61- 70; 62 62 66 67 ;; 71- 80: 80 ;; 81- 90: 84 88 88 88 90 ;; 91-100: 92 ;; ;; Average = 67.5 Median = 73.5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define displayln (lambda lst (let ((show (lambda (x) (display x) (display " ")))) (map show lst) (newline)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Question 2 -- Exam a ;; a.i 64 ;; a.ii 68 ;; b.i 800 ;; b.ii 4040 ;; Question 2 -- Exam b ;; a.i 70 ;; a.ii 75 ;; b.i 800 ;; b.ii 4040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Question 3 ;; write(y,z) write(b,c,d) ;; For Exam a ;; (a) 100 2 8 3 101 ;; (b) 101 3 101 3 101 ;; (c) 101 3 101 3 3 ;; (d) 101 3 101 3 1 ;; (e) 100 2 100 2 101 ;; ;; For Exam b ;; (a) 100 2 8 3 102 ;; (b) 101 3 101 3 102 ;; (c) 101 3 101 3 6 ;; (d) 101 3 101 3 2 ;; (e) 100 2 100 2 102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Question 4 -- Exam a (define fox '((a) b c) ) (define sox (cons (cdr fox) (car fox)) ) (set-cdr! (car fox) '(10) ) (define knox (cons (cdr (car sox)) (car sox))) (set-car! (cdr (car sox)) '(y z) ) (displayln "Exam 3a/Question 4/ fox = " fox) (displayln "Exam 3a/Question 4/ sox = " sox) (displayln "Exam 3a/Question 4/ knox = " knox) (displayln) ;; Question 4 -- Exam b (define fox '((x) y z)) (define sox (cons (cdr fox) (car fox))) (set-cdr! (car fox) '(10)) (define knox (cons (cdr (car sox)) (car sox))) (set-car! (cdr (car sox)) '(b c)) (displayln "Exam 3b/Question 4/ fox = " fox) (displayln "Exam 3b/Question 4/ sox = " sox) (displayln "Exam 3b/Question 4/ knox = " knox) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Question 5 --- Exam a ;; (a) 107 ;; (b) 7012 ;; (c) 1050 ;; (d) 599 ;; Question 5 --- Exam b ;; (a) 507 ;; (b) 7012 ;; (c) 1050 ;; (d) 199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Question 6 -- an answer ;; (swap-exp (id1 id2) ;; (let ((val1 (apply-env env id1)) ;; (val2 (apply-env env id2))) ;; (setref! (apply-env-ref env id1) val2) ;; (setref! (apply-env-ref env id2) val2) ;; val2)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Question 7 -- an answer ;; (while-exp (test body) ;; (eval-expression test env ;; (lambda (t) ;; (if (zero? t) ;; (cont 1) ;; (eval-expression body env ;; (lambda (val) ;; (eval-expression (while-exp test body) env cont)))))))