Background:
RLE compression relies on the fact that in many files there are many repeated characters (example: AAAAAA). The algorithm replaces this with a character+count resulting in a much smaller size.
For example, a string in a file contains: "AAAAADDDDDDDDEEEQQQQQQQQQQAAEE" is replaced with: "A5D8E3Q10A2E2".
There are two operations:
A) COMPRESS: read and compress the file into a 2nd file
B) DECOMPRESS: read a compressed file and reconstruct the original file.
Part 1: Compression
Write a Compress function that receives a string as a parameter and returns a compressed string. The function will:
a. Read the 1st character from the string parameter
b. Count how many times it is repeated
c. Add this info to a new string
d. Read the next character from the source string
e. Repeat from step b above, till the end of the string
f. When done, the function will return the new string
Test your function using the sample string above.
Part 2: File Processing
Ask the user for the input file name and open it (this is the text file containing data/art to be compressed)
Open an output file to be the compressed file (add extension .comp to the name)
Read a line from the input file (getline into a string)
Send the string to the compress function. When the compress function returns the compressed string, write it to the output file
Read the next line from the input file, go to #4
Repeat until the end of the file
Part 2: Decompress
Write a function decompress that takes a string and returns a string
Stringstream 1 char and 1 number
Create a string that is filled with x-number of this char
Add this string to the decompressed string
Repeat until the end of the source string
Return the decompressed string
Use the above function and open the .comp file, read line by line from it, decompress each line, and write it to a .decomp file
RESULT:
You will have a new .comp file that is a compressed version of the original file AND a .decomp file that is the decompression of the decomp file.
Your .decomp file should be the same as the original file.