Tree Programming Assignment: Huffman Encoding

Due Date: 9th week.

Write a class, Huffman, that has two public methods:

String Encode(String filename)
String Decode(String compressedFileContents)

The Encode method should read the contents of the file having the given pathname, and return a string, consisting of '0' and '1' characters, corresponding to the Huffman encoding of the contents of the file. The Decode method should be the inverse operation, taking, as its argument, the result of a previous call to Encode, and returning the original contents of the file as a string.

Your program should consist of a header file, "Huffman.h", and however many other files as you see fit.

Testing Your Class

I will use this driver to test your code.
I have modified Weiss's Hzip.cpp file (the definitions of the classes he defines in chapter 13 (pg 451)). You can use the resulting executable, "huffman.exe" to test your encoding. Here is a sample input file, "input.txt" to be Huffman encoded (note that there are some unprintable characters in the file, so you should download the file via the link above, rather than cut & pasting from the text immediately following):
abcdef abcdef abcdef abcde abcd abc ab a
a      a
You can run the executable on the input file like this:
huffman.exe -t input.txt

and you'll get this output:
\10 appeared 1 times and has the encoding: 111010
\13 appeared 2 times and has the encoding: 11100
' ' appeared 13 times and has the encoding: 10
'a' appeared 10 times and has the encoding: 00
'b' appeared 7 times and has the encoding: 110
'c' appeared 6 times and has the encoding: 010
'd' appeared 5 times and has the encoding: 1111
'e' appeared 4 times and has the encoding: 0111
'f' appeared 3 times and has the encoding: 0110
The encoding of the file is:
00110010111101110110100011001011110111011010001100101111011101101000110010111101
111000110010111110001100101000110100011100111010001010101010100011100
(A compression ratio of 36.5196)