The Anagram Project


Lab 8 Assignments

Students in the Monday lab were to write a function definition for either the cleanup functionor the contains function.
Students in the Wednesday lab were to write a function definition for either the contains function or the leftover function.

You were assigned pairs to work in.  Please work in these pairs, and
use the rules given for pair programming:

  1. Both of you work at a single terminal
  2. One person uses the keyboard and mouse while the other person "navigates"
  3. Switch roles every 20 minutes
Make sure that your program contains a working function, and a main() which tests that function for various user input.  That way, when I test your program, I can input anything I want and watch the function perform as it should.

Also make sure that you document your function very well, with a standard sort of header that describes every parameter of the function, as well as what the return value indicates or contains. 

A sample of such a header is shown to the right.  Notice that the header begins with the characters "/*", and ends with the characters "*/".  These are the delimiters used in C++ for building comments, and everything between them is ignored by the compiler. 

The example shown to the right is for our FindAnagram function, as described in class on Friday, 11/9.  You will be seeing this function again in Lab 9, hint hint.

Functions

string cleanup(string phrase);
This function takes a string parameter which may contain spaces, punctuation and letters, and returns a string which contains just the letters of that word, all made lowercase, in alphabetical order.  For example, cleanup("Hey!  Mr. Jones!") returns "eehjmnorsy"

bool contains(string phrase, string word);
This function takes two string arguments, both assumed to be in alphabetical order, and returns "true" if the phrase contains all the letters of the word, and returns "false" otherwise.  For example, contains("abcdefg","abc") returns "true," but contains("abcde","def") returns "false."

string leftover(string phrase, string word);
This function takes two string arguments, both assumed to be in alphabetical order, and with "word" assumed to be contained in "phrase."  It returns the difference between them; that is, it returns all the letters of "phrase" after the letters of "word" have been removed.  For example, leftover("abcdefghij","afgj") returns "bcdehi"

Sample Header

/*************************************
 *The FindAnagram function           *
 *by Rob Hochberg.                   *
 *Last modified 11/9/01              *
 *Parameters:                        *
 *  phrase - the phrase we are trying*
 *           to anagram              *
 *  wp     - pointer to the wordpair *
 *           where we start looking  *
 *  anagramsofar - string containing *
 *           the words found up to   *
 *           this function call      *
 *  depth  - the number of words in  *
 *           the anagramsofar        *
 *The function has no return value   *
 ************************************/
void FindAnagram(string phrase, wordpair *wp,
            string anagramsofar, int depth){
   ...
}

Lab 9 Assignments

Students in either lab have a choice of any of the following options:

  1. Write both the FindAnagram() function and the RemoveHtml() function
  2. Write the main() function, the UserInterface() function and the RemoveHtml() function
  3. Write the MakeAlphalist() function, using binary search, and the DeleteLists() function
Recall that this will count for the rest of your lab work, and that the due date has been extended to the week after Thanksgiving.

You may pair-program for this assignment, following the rules described for Lab 8 above. 

You must comment your programs as described above; make sure that you have your name(s) included in the header comments for each function that you write.  This is very important, since I will be cutting and pasting these to build our final product.

Please think of any enhancements that you would like to add to our project.  I will be glad to consider them for a final project for you, which may either add extra credit to your grade or replace the final altogether.

Note:  I have done almost all of my programming this semester through the secure shell client provided on the course homepage.  It is almost as easy as being in the lab!  If you are having any difficulty, please see me so that I can show you some nifty emacs tricks.

 

Function Descriptions

main();
This function should instantiate a new Book object, and a string for the user's phrase, and then call UserInterface() and FindAnagram(), inside of a loop.  The loop exits when UserInterface() returns "xxxdone" as the phrase.

void UserInterface(Book *book, string &phrase);
This function allows the user to set the book from which the wordlists will be created, and the phrase that the user wishes to anagram.  If the phrase that is passed is the empty string, then the function automatically asks the user to enter the name of a book, which the user does by indicating the name of the file containing that book.  The program then calls the set() function on the passed Book object.  When the user is asked to enter a phrase, if "b" is entered, then the user is prompted to enter another book name.  If "q" is entered, then the phrase is set to the special codeword "xxxdone", which signals main() that the program should end.

void FindAnagram(string phrase, wordpair *wp,
            string anagramsofar, int depth);
This function is called recursively.  Starting with the alphaword pointed to by wp, and moving through the linked list of alphawords, it tries to find a word contained in the phrase.  When it finds one, it subtracts it from the phrase, adds the (realword) word to the "anagramsofar," and calls FindAnagram on the resulting phrase.  The depth parameter is equal to the number of words in the anagramsofar parameter.

void RemoveHtml(string filename);
This function takes the file indicated by the filename and creates from it a new file called "filename_no-html" (where filename is the original filename) by removing all text between and including pairs of angle brackets < >.

void DeleteLists(singleword *sw, wordpair *wp);
This function deletes all the singlewords and wordpairs generated from the current book, so that the memory will be available when we load in our next book.

Lab10

Please note:  Many of the files listed below have changed (to make them all compatible) so if you have previously copied any of them from my public directory, you may wish to get the new versions. 

Also note that now you have to add 2 functions to Book.c, not 1.  Check out the header file Book.h to see which ones.

This lab was handed out in class and in lab, and is described completely on that page.  The only change is that I have written the new version of "alphabetize()" in the Book class only, so that you will have no new code to write for this Lab assignment, as promised. 

I have placed the following files in my public directory:

  • Book.c
  • Book.h
  • anagram.c
  • MakeAlphalist
  • contains
  • leftover
  • FindAnagram
  • main
  • UserInterface
  • DeleteLists
These are all the files you need to put together the working versions of Book.c and anagram.c.  You can also copy the files listed below, if you wish, to help with compiling and testing this project.
  • Makefile
  • matthew.txt
  • mark.txt
  • luke.txt
  • john.txt
  • gospels.txt  (All four of them together)
  • Hamlet.html
  • grail.txt  (Monty Python and the Holy Grail)
  • starwars.txt
The Makefile you can use, as per the lab handout, to do your compiling for you, every time you make a change to one or more of the files.
The Final

Tuesday Office Hours:
8-10:30am
1-5pm

The final is an open-book exam, meaning that you are free to use your textbook during the exam.  You cannot use other notes or papers, just your book, and anything you choose to write in your book.

Review Guide for Exam 1
(updated with a new reading guide!)

Review Guide for Exam 2

Material since Exam 2
Section 12.1
Section 7.4

Acrobat file
containing 
Exams 1 and 2
Solutions to those exams
All labs (except 8 and 9)
Labs 8 and 9 are above, on this page







 

Robert Hochberg
2001