Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions