CS212 Exams
Spring 1997 - Prelim
2

Solution to Object-oriented Programming

WARNING: You should seriously try to answer this question before looking at the solution -- it's just a good study skill. Also, some answers on this page may be more brief than you would want to put down in an actual exam. If you want any type of partial credit, you should write more than just the solution.



  1. popeye <animal> spinach <vegetable> milo <venus-flytrap>
    name: 'popeye
    hunger: -1
    size: 150
    location: 'nowhere
    nutritional-value: 0
    size: 100
    location: 'grocery-store
    favorite-meals: '(flies)
    name: 'milo
    hunger: -1
    nutritional-value: 0
    size: 100
    location: 'nowhere

     

  2. (defgeneric (edible? eater eaten))
    
    (defmethod (edible? (eater <thing>) (eaten <thing>)) #f)
    (defmethod (edible? (eater <animal>) (eaten <vegetable>)) #t)
    (defmethod (edible? (eater <venus-flytrap>) (eaten <fly>)) #t)

Question

Return to CS 212 Prelim 2 - Spring 1997