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:
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 .
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 .
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 your work in the usual way, using the submit command. For example, to submit the file foo.c, do:
submit cs202_01 hw7 foo.c
submit cs202_02 hw7 foo.c
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.
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.
#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.
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.cwhen 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.
Here is a sample of the output generated by the hw7 program.
Note that lines of the form
>>>>> Web search for http://lycos.comare 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