Question: I need only one C++ function . It's C++ don't write any other language. Hello I need zip function here is my unzip function below.

I need only one C++ function . It's C++ don't write any other language.I need only one C++ function . It's C++ don't write any

Hello I need zip function here is my unzip function below. So I need the opposite function Zip.

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

My unzip function is working perfectly. So I tested a file example: ab.txt and it had 10a4b and my unzip function printed aaaaaaaaaabbbb.

I tested on unix command line. Please do the opposite of unzip read the instruction.

//FUNCTION FOR UNZIP

#include

#include

#include

#include

using namespace std;

bool isdigit(char c){

return c>='0' && c

}

// to decode string

string unzip(string str) {

string res="";

int i=0;

while (i

if(!isdigit(str[i])){

res+=str[i];

i++;

continue;

}

int j=i;

while(i

i++;

}

string num=str.substr(j,i-j);

int n=stoi(num);

for(int k=0;k

res+=str[j-1];

}

}

return res;

}

int main(int argc,char *argv[]) {

ifstream in;

// one argument

if(argc

cout

return(-1);

}

// two arguments

if(argc

cout

return(-1);

}

in.open(argv[2]);

if(in.bad()){

cout

return(-1);

}

string line;

// read each line

while(getline(in,line)){

// decode line

string decode=unzip(line);

// print line

cout

}

return(0);

}

Requirements wcat is passed in a file and will output the file on the terminal (use cat to familiarize yourself with how this should work) wgrep is passed 2 arguments, the first is the word or words that the user is looking for and the second argument is the file that should be searched (use grep to familiarize yourself with this) wzip is passed a text file and redirects it to a compressed zip file wunzip is passed a zip file and prints out the unzipped file in standard output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!