You are on page 1of 2

Assignment # 4

Programming for Engineers II


Due Date: Sunday, 7th Dec, 2014 (11:00 pm)

Marks: 20

Submission Guidelines:

It is a group assignment with groups of upto 2 members


The submission will be on the Slate. Email submissions will not be entertained.
Name/rename source and header file as Assig04-batch#-roll#-roll#.cpp, e.g., Assig04-13955-13-877.cpp. Follow the same format for the header file also.
Failing to follow the submission guidelines will result in penalty

Implementing a Dictionary Method for Text File Compression


DICTIONARY METHOD:
This is an easy method for compression but this only works on Text Files. In this
method we make a dictionary of all words in a given text file using linked lists as the
number of words are not known in a text file. We use this Dictionary for Compressing and
decompressing these files.
Compression:
At first we compress a file by using the indexes of Linked List instead of whole word.
While saving Compressed File we write index of word instead of word. But the dictionary
is stored in that file first then those indexes are stored. If word is already added then it is
not added to dictionary again and same index is used fir tis word
Decompression:
Decompression is always done on a compressed file. To decompress that file we read the
stored dictionary and start reading those indexes stored instead of words. We have a
word corresponding to every index we find in file and write those words in a new file. By
following this procedure we decompress the file.
EXAMPLE:
Original File:
Dictionary method is a great method to
compress text files. Dictionary method is a
great method to compress text
files.Dictionary method is a great method to
compress text files.

Dictionary:
Index
1
2
3
4
5
6
7
8
9

Word
Dictionary
method
is
a
great
to
compress
Text
files

Compressed File:
[intsize_of_dictionary]
[dictionary]
1 2 3 4 5 2 6 7 8 9. 1 2 3 4 5 2
6 7 8 9.
1 2 3 4 5 2 6 7 8 9.

Limitations of Dictionary Method:

It only works for text files.


It compression rate* is bad for small files.

Compression Rate:

Compressed file
100
(1 Decompressed
file )

ASSIGNMENTS GUIDELINES:

Bonus marks will be given for a very good compression rate.


You must compress and decompress file exactly.
Name of file opened for compression should be Orignal.txt
Name of compressed file should be Compressed.p2
Name of decompressed file should be Decompressed.txt
Size of Decompressed.txt file = Size of Original.txt file

You might also like