;; A home is either ;; - a house or ;; - an apartment (define-struct house ( address nBed nBath)) ;; A house is (make-house string num num) ;; where address is the street address ;; nBed is the number of bedrooms and ;; nBath is the number of baths ;; Examples (make-house "1600 Penn Ave." 20 10) (make-house "314 Skid Row" 1 0) (make-house "1 Suburb Way" 4 2) (define-struct apt (address aptNum nBed )) ;; An apt is (make string num num) ;; where address is the street address ;; aptNum is the apartment number ;; nBed is the number of bedrooms ;; Examples: (make-apt "123 Faceless Alley" 42 1) (make-apt "2 Swanky Drive" 1024 3) (make-apt "64 Garden Drive" 256 2) (define-struct person ( name age home)) ;; A person is (make-person symbol num home) ;; where name and age and home is a home structure. ;; Examples (make-person 'Stephen 42 (make-apt "512 Lost Trail" 1010 1)) (make-person 'Ian 39 (make-house "2048 Happy Way" 5 3)) (define sw (make-person 'Stephen 42 (make-apt "512 Lost Trail" 1010 1))) (define ib (make-person 'Ian 39 (make-house "2048 Happy Way" 5 3))) ; maxGuestsHome: aHome -> string ;; Calculates the maximum number of guests that a home can handle under the following assumptions: #| 1. Each bedroom can handle at most 2 people. 2. Any home can handle 2 people in the living room or other such non-bedroom areas if such an area exists. 3. An apartment only has 1 non-bedroom sleeping area. 4. A house has 2 non-bedroom sleeping areas. 5. The host person does not share a room with their guests. |# ;; where aHome is a home structure and the result is a number in string format. (define (maxGuestsHome aHome) (number->string (cond [(house? aHome) (+ 4 (* 2 (- (house-nBed aHome) 1)))] [(apt? aHome) (+ 2 (* 2 (- (apt-nBed aHome) 1)))]))) (string=? "42" (maxGuestsHome (make-house "1600 Penn Ave." 20 10))) (string=? "4" (maxGuestsHome (make-apt "64 Garden Drive" 256 2))) ; maxGuests: aPerson -> string ;; This function calculates the maximum number of overnight guests that a person can handle in their home. ;; aPerson is a person structure and the resultant string is of the form ;; "[person's name]'s home can handle at most X guests. (define (maxGuests aPerson) (string-append (symbol->string (person-name aPerson)) "'s home can handle at most " (maxGuestsHome(person-home aPerson)) " guests.")) ;; Test cases (string=? "Stephen's home can handle at most 2 guests." (maxGuests sw)) (string=? "Ian's home can handle at most 12 guests." (maxGuests ib))