CS 342 Lab 1-Alternate: Moving from Java to C++

Note: Only use this Alternate Lab 1 if you have not completed CS 241, or if you used C++ in your CS 241 Lab 2 and CS 241 Lab 3.

CS 342 Lab 1-Alternate: Moving from Java to C++

Lab date: 18 January through 20 January 2000
Due date: 23 January 2000 11:59 pm

Objective:

This lab shows the obvious differences between Java and C++. And, it ensures that you are comfortable using the tools for compiling C++ programs. Finally, it introduces some elementary C++ language features.

Preparation:

Obtaining the Lab distribution:

At a Unix shell prompt, type ~cs342/bin/lab1. That will copy several files to a new lab1 subdirectory. You can cd lab1 and enter make javamap.class to compile the Java test program, if you like.

NOTE: If you're a CEC Unix machine, you must pkgadd java_1.2. (Or maybe java2, but we haven't tested it yet.)

Assignment:

  1. Compile and run the Java hash map program. Our particular HashMap maps a lower case character ('a' .. 'z') to an integer. The lower case character is the key, the integer is the value. (This could be a very simple model of a student name-to-id number map.)

  2. Add some test cases to provide better coverage of the hash map functionality. Specifically, be sure to test what happens when you try to put or get an unexpected key value, such as a key that is outside the allowed range.

    This may not seem very useful at this point. But, you'll be implementing a (simple) hash map, and need to adequately test that.

  3. Replace the use of the built-in Java hash map with your own hash map. It can be simple, and need only provide put, get, and size methods. It need only map single characters to integers. It's OK, for this lab, to use an array of a hard-coded size for your hash map.

  4. Translate your Java program to C++. Be sure that all of your C++ source code is in a file named main.cc.

  5. Put your test output in these files:
    1. out.javamap for the Java HashMap implementation.

    2. out.java for your Java implementation that does not use HashMap.

    3. out.c++ for your C++ implementation.

    You can use the shell redirection operator to put output into a file, e.g.,
    java javamap > out.javamap
    

What to Submit:


CS 342 home page