; The Scheme code that follows was used to compute ; final grades in CS U370 (Clinger's section only). ; ; This code uses various helper functions that are ; not defined below. ; Numerical nonsense. (define (num n) (if (number? n) n 0)) (define (round1 x) (/ (round (* 10.0 x)) 10.0)) (define (curve-midterm n) (+ n)) (define (curve-final n) (+ n 10)) ; Given a list of the homework scores, and a corresponding ; list of the number of possible points for each homework, ; returns the average score as a percentage, weighting all ; homeworks equally. (define (curve-homeworks scores possible-scores) (define (curve score possible) (/ score possible)) (* 100.0 (/ (apply + (map curve scores possible-scores)) (length scores)))) ; Given a list of the homework scores, and a corresponding ; list of the number of possible points for each homework, ; returns an overall homework score obtained by disregarding ; the most detrimental homework. (define (curve-homework scores possible-scores) (do ((best 0.0 (max best (curve-homeworks (append earlier-scores (cdr later-scores)) (append earlier-possible (cdr later-possible))))) (earlier-scores '() (cons (car later-scores) earlier-scores)) (earlier-possible '() (cons (car later-possible) earlier-possible)) (later-scores scores (cdr later-scores)) (later-possible possible-scores (cdr later-possible))) ((null? later-scores) best))) (define weight:midterm .22) (define weight:final .33) (define (rawscore x) (let* ((hw (curve-homework (map (lambda (f) (num (f x))) (list hw1 hw2 hw3 hw4 hw5 hw6 hw7 hw8)) possible-hw)) (test1 (curve-midterm (num (midterm x)))) (test2 (curve-final (num (final x))))) (round1 (+ (* (- 1.0 weight:midterm weight:final) hw) (* weight:midterm test1) (* weight:final test2)))))