;; 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-reader.ss" "lang")((modname quiz1-practice) (read-case-sensitive #t) (teachpacks ((lib "universe.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "universe.ss" "teachpack" "2htdp"))))) ;; Helene Martin, Garfield APCS++ 2010 ;; Answers to quiz practice (define LEAVES-PER-TREE 200000) ;; hours-to-rake number -> number ;; takes in the number of trees and returns the hours to rake (define (hours-to-rake trees) (/ (* trees LEAVES-PER-TREE) 40000)) (check-expect (hours-to-rake 0) 0) (check-expect (hours-to-rake 1) 5) ;; A employee is a (make-employee string number) (define-struct employee (name salary)) (define DEREK (make-employee "Derek" 80000)) (define ADAM (make-employee "Adam" 20000)) ;; give-raises employee -> employee ;; provides a 10% raise for employees who make less than $60,000 (define (give-raises empl) (cond [(< (employee-salary empl) 60000) (make-employee (employee-name empl) (* 1.1 (employee-salary empl)))] [else empl])) (check-expect (give-raises DEREK) DEREK) (check-expect (give-raises ADAM) (make-employee "Adam" 22000)) ;; An address is (make-address string string string number) (define-struct address (street city state zip)) (define LANE-ADDRESS (make-address "444 Fnord Pl" "Seattle" "WA" 98102)) ;; A home-customer is (make-home-customer string address string number) (define-struct home-customer (name address plan card-num)) (define LANE-UNL (make-home-customer "Lane" LANE-ADDRESS "unlimited" 34454565)) (define LANE-BASIC (make-home-customer "Lane" LANE-ADDRESS "basic" 34454565)) ;; An instant-viewer is (make-instant-viewer string number) (define-struct instant-viewer (e-mail card-num)) (define QUI (make-instant-viewer "qui@qui.com" 23432432)) ;; A customer is ;; - a home-customer ;; - an instant-viewer ;; monthly-cost: customer -> number ;; consumes a video customer and produces the monthly cost for that ;; customer. The cost is $4.95 for home customers on the basic plan, ;; $16.95 for home customers on the unlimited plan, and $9.95 for ;; instant viewers. (check-expect (monthly-cost LANE-BASIC) 4.95) (check-expect (monthly-cost LANE-UNL) 16.95) (check-expect (monthly-cost QUI) 9.95) (define (monthly-cost a-cust) (cond [(home-customer? a-cust) (home-cost a-cust)] [(instant-viewer? a-cust) 9.95])) ;; home-cost home-customer -> number (define (home-cost home-cust) (cond [(string=? "basic" (home-customer-plan home-cust)) 4.95] [(string=? "unlimited" (home-customer-plan home-cust)) 16.95])) ;; is-cheap? customer -> boolean ;; checks if customer's plan costs $10 or less (define (is-cheap? customer) (<= (monthly-cost customer) 10)) (check-expect (is-cheap? QUI) true) (check-expect (is-cheap? LANE-UNL) false)