The goal of this lab is to implement the Huffman Tree Encoding.
You are free to create the design to solve this problem. The general steps for this program are:
You are given eight files:
test-file-0.txt
the first input filetest-file-0.table
the output to screen of the first input filetest-file-0.encoded
the output file of the first input filetest-file-1.txt
the second input filetest-file-1.table
the output to screen of the second input filetest-file-1.encoded
the output file of the second input filetest-file-2.txt
the third input filetest-file-2.table
the output to screen of the third input filetest-file-2.encoded
the output file of the third input filetest-file-3.txt
the fourth input filetest-file-3.table
the output to screen of the fourth input filetest-file-3.encoded
the output file of the fourth input fileIdeally you should write a makefile, but you can compile the following way:
g++ yoursource1.cpp yoursource2.cpp -o huffman -std=c++11 -Wall
This will result in an executable name huffman
, remember to specify the name of the exacutable in case you make your own makefile
. The program should work with command line parameters the following way:
./huffman -encode inputfile outputfile
inpufile
and create a file outputfile
with the huffman encoding of the first file./huffman -decode inputfile outputfile
inputfile
and write the decoded information into the outputfile
To encode a file named mybook.txt
and put the encoding into a file named myencodedbook.txt
:
./huffman -encode mybook.txt myencodedbook.txt
To decode a file named coded.txt
and create a decoded file named original.txt
:
./huffman -decode coded.txt original.txt
Your program should output the Coding Table in the screen using JSON-like format, as follows:
{key: , code: 11}
{key: a, code: 010}
{key: e, code: 0010}
{key: o, code: 0110}
{key: u, code: 0111}
{key: r, code: 1000}
{key: n, code: 1010}
{key: i, code: 1011}
{key: l, code: 00001}
{key: s, code: 00010}
{key: d, code: 00110}
{key: m, code: 10011}
{key: p, code: 000000}
{key: c, code: 000001}
{key: CR, code: 000110}
{key: t, code: 000111}
{key: g, code: 001111}
{key: q, code: 100100}
{key: b, code: 100101}
{key: h, code: 0011100}
{key: f, code: 00111010}
{key: z, code: 00111011}
This is the output of the program when ran using test-file-0.txt
. Things to notice:
'\n'
'\r'
The encoded file (without extra challenge) will be a single line with 0 and 1 only.
/*
Filename: huffmantree.h
Description: Declaration of the class HuffmanTree to represent the binary Huffman Tree
Author: McDonald Berger
Date: 05/29/2019
Course: Data Structures II
*/
Once you finished coding your lab you may want to test it to check it is correctly working. The steps would be:
huffman
./huffman -enconde test-file-0.txt my-0.encoded > my.table
my-0.encoded
contains the encoded file test-file-0.txt
my-0.table
contains the output to screen that shows the Huffman Code Tablediff test-file-0.encoded my-0.encoded
This will check if your encoded file is identical to the given file.diff test-file-0.table my-0.table
This will check if your encoding table is identical to the given encoding table.The comparison of the encoded files will fail, since you will have to save the Huffman Tree in the beginning of the file. So, you will need to follow this steps (Applies for Extra Challenge and for Extra - Extra Challenge).
./huffman -decode my-0.encoded my-0.decoded
diff my-0.decoded test-file-0.txt
if there is no output, it means the files are identical and your program is working as expected.NOTE: If you are using the Windows command line, you will need to use
Get Free Quote!
304 Experts Online