Part II: Implement text compression.
In this part, use a text file as input, read through the text file, calculate the frequencies of each character, apply your Huffman Algorithm to encode the text file into a new file.
You program should have the following functions, besides the above functions.
- Encode: takes a text file name, calls the Huffman coding algorithm, traverse the tree to get the code word, and then encode the text file into a new file.
- Decode: takes a prefix tree, and an encoded file, decode the file.
What to turn in:
- Well documented source code in C++.
- Run your algorithm for 20 files and show the compression ratio of the size of the original file and the size of the compressed file. Show the ratios in the table.
//code
// C++ program for Huffman Coding #include #include #include #include #include