Question
I need only one C++ function . It's C++ don't write any other language. Hello I need unzip function here is my zip function below.
I need only one C++ function . It's C++ don't write any other language.
Hello I need unzip function here is my zip function below. So I need the opposite function unzip.
Instructions:
The next tools you will build come in a pair, because one (zip) is a file compression tool, and
the other (unzip) is a file decompression tool.
The type of compression used here is a simple form of compression called run-length encoding (RLE). RLE is quite simple: when you encounter n characters of the same type in a row, the compression tool (zip) will turn that into the number n and a single instance of the character.
Thus, if we had a file with the following contents: aaaaaaaaaabbbb the tool or Zip function would turn it (logically) into: 10a4b
So write the C++ unzip function that will turn 10a4b into aaaaaaaaaabbbb opposite of zip function. I'll make a txt file example like file.txt that will have 10a4b text once I will run your unzip function it will turn into aaaaaaaaaabbbb. I tested my zip function on terminal and it's working perfectly.
here is my zip function:
Full program with zip funcion with output
#include
using namespace std; string zip(const string & str) { int i = str.size(); string enc;
for (int j = 0; j < i; ++j) { int count = 1; while (str[j] == str[j + 1]) { count++; j++; } enc += std::to_string(count); enc.push_back(str[j]); } return enc; } int main(int argc, char *argv[]) { ifstream in; // one argument if (argc<2) { cout << "Please enter command"; return(-1); } // two arguments if (argc<3) { cout << "Please enter file name"; return(-1); } in.open(argv[2]); if (in.bad()) { cout << "File not found"; return(-1); } string line; // read each line while (getline(in, line)) { // decode line string encode = zip(line); // print line cout << encode << endl; } return(0); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started