CPS 100, Spring 2004, Anagram

Make sure to check the Anagram Forum discussion forum for news
This assignment comes in two parts. Part I is described here. Part II will be available after you've worked on part I.

Creating a Course Directory

See Assignment Zero for information on setting up a directory for your cps100 work.

Getting/Snarfing Code

Information on copying or snarfing files for the Anagram assignment is accessible.


Two words are anagrams if they contain the same letters. For example, bagel and gable are anagrams as are glare, lager, large, and regal.

Word puzzles like the Jumble shown below, and found in many newspapers are based on anagrams too. You can also play jumbles online at jumble.com.


You're given a small program simpleanagram.cpp that prompts the user for a word and then prints all the words that are anagrams of the user-entered word. As the source of anagrams, the program uses a dictionary/file specified when it's started. For Part I you must modify the program as follows.

  1. Running the program as shown below should print a list of all anagrams in the file specified by the user. The user will not be prompted for a word as in the current version.

    The program reads one file, and finds the words in that file that are anagrams of each other.

    Each sequence of anagrams is printed on one line, and every line printed should have at least two words that are anagrams. For example, the output of the program might be as follows (depending on the file read). Do not print lines with only one words, e.g., for the word "zoo" which doesn't have any anagrams.

     prompt> simpleanagram datafile
     gazer graze 
     gases sages 
     heals leash shale 
     heaps phase shape 
     hares hears share shear 
     earth hater heart 
     haste hates heats 
     haves shave 
     arise raise 
     lakes leaks 

    Be sure that every line printed consists of words that are anagrams of each other and that every line printed has at least two words on it.

  2. The simplest method for implementing this modification involves sorting the vector of Ana objects. To do this you'll need to implement an overloaded operator < similar to the operator == that's already implemented. See Tapestry for details on operator overloading.

Summary of running simpleanagram.cpp

Compile and run from the commandline as follows
  prompt> make simpleanagram
  prompt> simpleanagram datafile


  prompt> simpleanagram

(which will prompt for a file name)
Alternatively, if you're using Eclipse you'll need to add a make target of simpleanagram using the Eclipse make tutorial for help.


Part I is worth 20 points.

Criteria Points
Implemented as specified in general 8
Robust for all inputs/special cases 4
Documentation, style of code 4

In your README, which you must submit, you should include


To submit use Eclipse and the name anapartI or
 submit_cps100 anapartI Makefile *.cpp README

Jeff Forbes
Last modified: Thu Jan 24 10:28:48 EST 2002