CS212 Exams
Spring 1998 - Prelim
2

Solution to OO Programming



  1. (defstruct <entry> 
       (title <string>) (authors <list>) (year <number>))
    (defstruct (<book> <entry>)
       (isbn <number>) (publisher <string>))
    (defstruct (<article> <entry>)
       (month <number>) (publication-name <string>))
    (defstruct (<magazine> <article>))
    (defstruct (<journal> <article>)
       (volume <number>))
  2. 
    (defgeneric (print-entry (entry <entry>)))
    
    (defmethod (print-entry (entry <entry>))
      (echo "Title: " (get-entry-title entry))
      (echo "Authors: " (get-entry-authors entry))
      (echo "Year: " (get-entry-year entry)))
    
    (defmethod (print-entry (book <book>))
      (call-next-method)
      (echo "ISBN: " (get-book-isbn book))
      (echo "Publisher: " (get-book-publisher book)))
    
    (defmethod (print-entry (article <article>))
      (call-next-method)
      (echo "Month: " (get-article-month article))
      (echo "Publication: " (get-article-publication-name article)))
    
    (defmethod (print-entry (journal <journal>))
      (call-next-method)
      (echo "Volume: " (get-journal-volume journal)))

Question

Return to CS 212 Prelim 2 - Spring 1998