Git Product home page Git Product logo

huffman's Introduction

Huffman

Design a Huffman code tree to encode and decode text files. The tree must be constructed based on a set of alphabets and their probabilities. Your objective is to assign the shortest codes to the characters with the highest probabilities. The alphabets and their probabilities will be stored in a file called "alphabet.txt". The alphabet file is organized as follows:

a 0.2

b 0.3

c 0.1

d 0.05

e 0.05

f 0.3

Lower case letters and uppercase letters are treated the same. You may convert all uppercase letters to lowercase before processing.

Write a C++ program that allows the user to encode a text file using the Huffman code tree created. Your program must be able to encode a file and decode it (restore it to its original English text). Punctuations and new lines should not be encoded or decoded and should maintain their locations inside the data files.

Your program should use command line arguments with the following options:

-e : encode convert letters to codes

-d : decode convert codes to letters

-p : print all characters with their codes and the average code length

-h : help (usage)

Report errors and exit the program if any of the following occur:

  • File does not exist
  • Wrong argument entered
  • Wrong number of arguments

Examples:

./huffman -e inputFile.txt outputFile.txt

./huffman -d inputFile.txt outputFile.txt

./huffman -h

./huffman -p

./huffman (display the usage)

huffman's People

Contributors

hc219417 avatar

Stargazers

Alejandro Rosales avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.