Fundamentals of Computer Science I (CSC-151.02 2000F)

HW4: CGI Scripting

Assigned: Friday, 13 October 2000
Due: Friday, 27 October 2000

Summary: In this assignment, you will continue with your explorations of CGI scripts from the CGI lab and the second CGI lab.

Group work: You should work in groups of size two to four. Turn in only one assignment for the whole group. Different groups may also discuss the assignment with each other.

The Project

It's getting close to preregistration time, so hoards of students will want help in choosing their courses. Your goal in this assignment is to build a simple course recommendation system. Starting with a database of courses (most of which you'll build), you will ask students for attributes of their desired courses and recommend courses for them. Your primary goal in this assignment is to learn how to build a significant Web-based interface.

We've decided to represent each course as follows:

( department      ; a string, such as "Math/CS"
  number          ; a string, such as "CSC151"
  title           ; a string, such as "Fundamentals of Computer Science I"
  nickname        ; a string, such as "Fun with Parentheses"
  description     ; a string, typically one paragraph long
  adjectives      ; a list of strings, such as 
                  ;    ("hard" "time-consuming" "practical")

For example, here is the full entry for a few courses:

(define courses
     "Fundamentals of Computer Science I"
     "Parenthesization for Fun and Profit"
     "An investigation into the algorithmic techniques that underlie all of computer science.  Taught in Scheme so that, following the Grinnell credo, it provides no practical benefit."
     ("hard" "time consuming" "practical" "fun"))

Your goal is to provide an HTML page and CGI script that lets someone enter an adjective and give a list of all the courses that are described by that adjective.

I would recommend that you follow these steps to reach the final state of the project. As long as you produce something that works, I don't really care how you get there.

Here's are some methods that you may find helpful.

;;; Determine if an adjective describes a course.
;;; Parameters:
;;;   An adjective (a string in all lowercase; spaces permitted)
;;;   A course
;;; Returns:
;;;   A boolean value (true or false)
;;; Pre:
;;;   The course is in the recommended form.
;;; Post:
;;;   Returns true if the adjective describes the course (according
;;;   to the list of adjectives) and false otherwise.
;;;   Does not affect the course.
(define describes?
  (lambda (adjective course)
    (let ((course-adjectives (list-ref course 5)))
      (if (member adjective course-adjectives) #t #f))))

;;; Given an adjective and a list of courses, extract the courses
;;; described by that adjective
;;; Parameters:
;;;   An adjective (a string in all lowercase; spaces permitted)
;;;   A list of courses
;;; Returns:
;;;   A list of courses.
;;; Pre:
;;;   All courses is in the list are in the recommended form.
;;; Post:
;;;   All courses in the result list are described by the adjective.
;;;   No courses not in the result list are described by the adjective.
;;;   The original list of courses is unaffected.
(define applicable-courses
  (lambda (adjective courses)
    (if (null? courses) null
        (let ((course (car courses))
              (remainder (applicable-courses adjective (cdr courses))))
          (if (describes? adjective course)
              (cons course remainder)

First, create a database of ten or so courses. This database is due on Tuesday so that I may share them with the class. This database must be in exactly the same format as given above.

Second, create a procedure, course->html that converts a course to an HTML string. Here's a let clause you might want to use

    (let ((dept (list-ref course 0))
          (num  (list-ref course 1))
          (name (list-ref course 2))
          (nick (list-ref course 3))
          (desc (list-ref course 4))
          (adjs (list-ref course 5)))

Third, create a procedure, courses->html that converts a list of courses to HTML.

Fourth, create a procedure, result-page that, given an adjective and a list of courses, creates (but does not display) a full HTML page for all courses that meet the adjective.

Fifth, write a CGI script that gives all the courses that meet a particular adjective (not a user supplied adjective, but one you've supplied). Your script should look something like

(display "Content-type: text/html")
(display (result-page "hard" courses))

Sixth, write an HTML form that lets a student enter an adjective.

Finally, write a CGI script that reads the adjective and displays the corresponding page.

Extra Credit

Particularly nice output will receive a little bit of extra credit.

Programs that accept multiple adjectives and rank results based on the number of adjectives matched will receive extra credit.

Programs that allow students to select on multiple criteria (e.g., all easy math courses) will receive some extra credit.

Other innovative takes on the assignment will also receive extra credit.

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at

Source text last modified Fri Oct 13 10:24:19 2000.

This page generated on Fri Oct 13 10:25:03 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at