;; Sid Stamm ;; C211 lab number 2: Lambda & If ;; 9-12-2003 ;; ACME Sports Drinks ;; GLOBAL DEFINITION OF PI (define PI 3.1415926) ;; calculates the volume of a cylinder ;; given a radius and height. ;; the variable PI must be previously defined. (define cyl-vol (lambda (rad ht) (* PI rad rad ht))) ;; determines how many cans are needed to can ;; a given volume of drink given a radius and ;; height of a can. (define vol->cans (lambda (vol can-rad can-ht) (ceiling (/ vol (cyl-vol can-rad can-ht))))) ;; Determines how many boxes are needed to pack ;; a given number of cans. (define cans->boxes (lambda (cans box-capacity) (ceiling (/ cans box-capacity)))) ;; Determines how many trucks are needed to ship ;; a given number of boxes. (define boxes->trucks (lambda (boxes truck-capacity) (ceiling (/ boxes truck-capacity)))) ;; Determines how many trucks are needed to ship ;; a volume of sports drink given conversion procedures. (define volume->trucks (lambda (volume v->c c->b b->t) (b->t (c->b (v->c volume 2 6) 24) 1000))) ;; Determines how many trucks are needed to ship ;; a volume of sports drink using previously defined ;; global procedures (define volume->trucks-noprocs (lambda (volume) (ceiling (boxes->trucks (cans->boxes (vol->cans volume 2 6) 24) 1000)))) ;; A predicate to determine if there are enough ;; drivers to ship the entire volume of sports drink. (define enough-drivers? (lambda (num-drivers vol) (>= num-drivers (volume->trucks-noprocs vol)))) ;; prints out whether or not there are ;; enough drivers ;; along with some other information. (define print-enough-drivers (lambda (num-drivers vol) (if (enough-drivers? num-drivers vol) (begin (display "Today we have enough trucks to ship ") (display vol) (display " units of Sports Drink!") (newline)) (begin (display "We need ") (display (- (volume->trucks-noprocs vol) num-drivers)) (display " more drivers to ship today's volume of Sports Drink.") (newline)))))