Sale!

Program 2: Huffman Compression

$30.00

CSCI 2226 and 6620 Data Structures
Program 2: Huffman Compression, Phase I
1 Goals of this Assignment
In this assignment you will:
1. Write and use a C++ class.
2. Organize a modular program in the C/C++ world.
3. Use a utility module provided by the instructor.
4. Write the first of several phases of a file compression program that we will develop throughout
the term.
2 Huffman Codes

Category:

Description

5/5 - (3 votes)

CSCI 2226 and 6620 Data Structures
Program 2: Huffman Compression, Phase I
1 Goals of this Assignment
In this assignment you will:
1. Write and use a C++ class.
2. Organize a modular program in the C/C++ world.
3. Use a utility module provided by the instructor.
4. Write the first of several phases of a file compression program that we will develop throughout
the term.
2 Huffman Codes
A Huffman code can be used to compress a file. It replaces fixed-size, one-byte characters by variablelength codes (strings of bits). The codes for the most frequently used characters will be shorter than
8 bits, those for unusual characters will be longer. No codes are generated for characters that are not
used. The input file is read twice, once to generate the code, then again to encode the file. In this
assignments, you will analyze the frequencies of the characters that appear in a text file that will,
eventually, be compressed.
2.1 The Initial Tally
1. Create a simple class named Tally. Data members should include an array of 256 integer counters,
for tallying occurrences of the 256 possible ASCII characters, a counter for the number of input
characters, and an ifstream& for the input file. Define a constructor, a print function, and a
“worker” function named doTally.
2. Write a main program that calls banner() at the beginning. Open the input file and use the open
stream as a parameter to instantiate the Tally class. Call doTally(). Print the results of the tally.
Call bye() and end.