CMSC--202 Computer Science II for Majors
Fall 1997 18 November 1997 Homework 7

The purpose of this homework is to give you some experience working with binary trees. You will also get some more practice designing and implementing ADTs. Your ADT will hold a collection of URLs (uniform resource locators) and their titles. You are familiar with URLs from your interaction with the web. For example, http:\\ www.gl.umbc.edu is the URL for the homepage of the gl machines. The title of a URL is the title of the web page to which it refers. Your ADT might be called a ``urlCollection,'' but you are free to call it anything you wish. The following ADT operations are required:

index(url)
- this operation takes a URL and indexes it in the collection. If it's already in the collection, no action is required ( i.e. no duplicates in the collection). The index operation stores the URL and its title (if not already there). It returns the title in either case.
list
- this operation lists the URLs in the collection along with their titles. The listing is done to stdout.

Here's an important point: you must use a binary tree to store the data. The binary tree must be the one in the 202 library. You may use only the binary tree operations of the binary tree ADT, although you may write additional functions based on those operations.

The Program

Your program continually prompts the user for a command (one of `` index,'' `` list,'' or `` quit'') and reacts accordingly.

A sample run is given on page gif.

Important Note

Use the url_to_string function that is declared in url_to_string.h. The function itself is in the usual lib202.a library. The function requires that you be connected to the web and that the lynx program be available. All the UCS workstations and the gl machines meet these requirements. Your home machine may not meet the requirements. If not there is a way to test your program without it -- see page gif. In any event, the grader will test your program while connected to the web. Be aware that the url_to_string function will print a message to stdout whenever it goes out to the web.

Submit

Submit your work in the usual way, using the submit command. For example, to submit the file foo.c, do:

Submit all the files required to successfully compile your homework using your submitted makefile. The only constraints on file names are that the executable must be named hw7 and the makefile must be named Makefile or makefile. Otherwise, you may name your files as you wish.

Testing Off the Web

 

If you wish to test your program on a machine that is not connected to the web or does not have the lynx browser available, you can do the following. This is just for testing purposes. Your submitted homework must work on the gl machines while connected to the web.

  1. Place the following function in your homework code:

    #ifdef NOTONWEB
    char * url_to_string(char * u)
    {
      if (strcmp(u, "foo") == 0)
        return "foo bar <TITLE>Fake Foo URL</title> greep fern";
      else
        return "bar foo <title>Fake Other URL</TITLE> glack";
    }
    #endif
    

    this will ``override'' the definition in the lib202 library.

  2. Inform the compiler about the NOTONWEB macro by defining it on the cc line. For example, suppose you placed the url_to_string function in the file foo.c. Then your cc line would be:
    cc -DNOTONWEB -I /home/anastasi/Public/202/Includes -g -c foo.c
    
    when you are ready to test it connected to the web, recompile with the line
    cc -I /home/anastasi/Public/202/Includes -g -c foo.c
    

Your submitted makefile should not use the -DNOTONWEB macro.

Sample Run

  Here is a sample of the output generated by the hw7 program.

Note that lines of the form

>>>>> Web search for http://lycos.com
are generated by the url_to_string function when it goes out to the web. When you find a URL in the collection, you do not go out to the web, you simply return its title from the collection. Thus, not every index command has the message from url_to_string.

Script started on Wed Nov 12 13:15:48 1997
umbc8[101] hw7
Command (index <url> or list  or quit): index http://lycos.com
>>>>> Web search for http://lycos.com
Title
  Lycos: Your Personal Internet Guide
Command (index <url> or list  or quit): index http://www.gl.umbc.edu
>>>>> Web search for http://www.gl.umbc.edu
Title
  GL Computing Homepage
Command (index <url> or list  or quit): index foo
>>>>> Web search for foo
Title
  no title
Command (index <url> or list  or quit): index http://lycos.com
Title
  Lycos: Your Personal Internet Guide
Command (index <url> or list  or quit): list
URLs collected:
    1:  URL is http://lycos.com
        Title is  Lycos: Your Personal Internet Guide
    2:  URL is foo
        Title is  no title
    3:  URL is http://www.gl.umbc.edu
        Title is  GL Computing Homepage
Command (index <url> or list  or quit): quit

That's all folks
script done on Wed Nov 12 13:16:29 1997


Thomas A. Anastasio
Tue Nov 18 13:09:52 EST 1997