Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

void Decompress(const char* _outputFile) { // TODO: // 1. Create a BitIfStream and read the frequency table BitIfstream bitIfStream(mFileName.c_str(), (char*)mFrequencyTable, 256); // 2. Create the

void Decompress(const char* _outputFile) { // TODO: // 1. Create a BitIfStream and read the frequency table BitIfstream bitIfStream(mFileName.c_str(), (char*)mFrequencyTable, 256); // 2. Create the leaf list and tree (in this order) GenerateLeafList(); GenerateTree(); // 3. Create a standard ofstream for output (binary mode) std::ofstream outputFile(_outputFile, std::ios_base::binary); // 4. Create a bool to use for traversing down the list, and a char to store the character for writing bool bitValue; char outputChar; // 5. Create a node pointer for use in traversing the list (start it at the top) HuffNode* point = mRoot; // 6. Go through the compressed file one bit at a time, traversing through the tree // When you get to a leaf node, write out the value, and go back to the root // Note: Remember, there may be trailing 0's at the end of the file, so only loop the appropriate number of times while (bitIfStream.Read(bitValue)) { if (bitValue) { point = point->right; } else { point = point->left; } if (point->IsLeaf) { outputChar = point->value; outputFile.put(outputChar); point = mRoot; } } // 7. Close the streams bitIfStream.Close(); outputFile.close(); // 8. Clean up the dynamic memory by clearing the tree ClearTree(); }

I need help with question 6 of the code as .Read and IsLeaf are giving me errors still.

class BitIfstream {

std::ifstream mStream; // The stream to use for inputting char mBuffer; // The current byte to read int mBitIndex; // The current bit in the buffer to read

public:

// Constructor // Will open the file and read the header (if there is one) // // In: _fileName The name of the file to open for input // _fileHeader Where to store the file header (OPTIONAL) // _headerSize The number of bytes in the optional header (OPTIONAL) BitIfstream(const char* _fileName, char* _fileHeader = nullptr, unsigned int _headerSize = 0);

// Destructor // Will close the file ~BitIfstream();

// Extraction operator // Sends back one bit from the buffer. Will read another char into the buffer once all // bits have been processed. // // In: _bit Where to store the bit // // Return: The invoking object // This allows extractions to be daisy-chained (standard behavior) BitIfstream& operator>>(bool& _bit);

// Check for End of File // // Return: True, if we are at the end of the file, having read every byte from the file and processed every bit bool eof();

// Close the file void Close();

this is from the header

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

Students also viewed these Databases questions