CompSci 108
Fall 2006
Software Design and Implementation

Anagrams

Two words are anagrams if they are composed of the same letters. For example, "bagel" and "gable" are anagrams as are "drainage" and "gardenia". In this example, the program reads a dictionary (a list of words) and finds all the words within the list that are anagrams of each other.

Example Solutions

In C++:

In Java:

Questions

To help you answer these questions, you may want to check your course readings, the C++ and Java tutorials available from the course resource page.

  1. Input/Output
    1. In C++, what are the differences between cout and cerr?
    2. In Java, what is the equivalent of C++'s cout and cerr?
    3. In general, what does try and catch mean in Java (and in C++ actually)?

  2. Collections
    1. In Java, what is the equivalent class to the C++ set?
    2. In C++ and Java respectively, what member function adds an element to a set?
    3. In C++, collection classes like Set and Map are templated. How do collection classes in Java achieve similar genericity? What impact does that have on the programmer?
    4. How does operator overloading help simplify the C++ code (if at all)?

  3. Pointers
    1. In Java, every object must be created using new; how does this differ from C++?
    2. Using pointers in C++, how do you access the object to which the pointer points? Can you do the same thing in Java?
    3. Is there any similar kind of variable in C++ to Java's standard "pointer" variables?
    4. How does that difference affect how parameters are passed in each language?
    5. How does that affect how objects encapsulate their private data?

  4. Including code declarations
    1. In C++, what are the differences between using angle brackets < > and using quotes "" when including header files.
    2. In C++, what are the differences between including a header file and simply declaring a class exists?
    3. In Java there are no header files, how do you include code from other classes?
    4. Why do think Java does not have header files?
    5. In C++ and Java respectively, how do you find the source code for things you have included in your program?
    6. In C++, what does using namespace std mean?
    7. Does Java have an equivalent mechanism? If so, what is it?

  5. Running Programs
    1. How do you run a Java program?
    2. What is the main difference between running programs in C++ and Java and what impact does that have on the user?
    3. What are the phases of compilation for C++? for Java?
    4. What impact does this have on compile-time versus run-time errors?
  6. Command-line Arguments
    1. In C++, the check for a command line argument uses "if (argc > 1)". Why? What is the first argument to the program?
    2. Why is there no equivalent first argument in Java?
    3. What do the parameters to main mean in general and how do you supply them?