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<iostream>
#include<string>
#include<fstream>
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);
}
Full program with unzip funcion with output
#include<iostream>
#include<string>
#include<fstream>
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);
}
output

Note:------
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
I need only one C++ function . It's C++ don't write any other language. Hello I need...
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...
can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block { std::string word; int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) { string filename="input.txt"; //declare array of struct word_block word_block arr[SIZE]; int count = 0; if (argc < 2) { cout << "Usage: " << argv[0] << "...
***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...
C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...
I am getting a seg fault with my huffman tree. I'm not sure if it's my deconstructors but also getting some memory leaks. Can some one help me find my seg fault? It's in c++, thanks! //#ifndef HUFFMAN_HPP //#define HUFFMAN_HPP #include<queue> #include<vector> #include<algorithm> #include<iostream> #include <string> #include <iostream> using namespace std; class Node { public: // constructor with left and right NULL nodes Node(char charTemp, int c) { ch = charTemp; count = c; left...
#include #include #include #include #include #include // NOLINT (build/c++11) #include class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return type; } }; std::ostream...
#include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return...
Command line input In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like Linux and are passed in to the program from the operating system. To use command line arguments in the program, it must first understand the full declaration of the main function, which until now has accepted no arguments. In fact, main can accept two arguments: one argument is number of command line...
1. In ANSII standard C++, there is no library function to convert an integer to a string. Your program should develop such a function. In other words complete the following program using your itos function. (Use of other C functions is prohibitted) // this program will read in an integer and convert it to a string #include <iostream> #include <cstdlib> #include <string> using namespace std; string itos(int n) { } int main(int argc, char* argv[]){ int n = atoi(argv[1]); cout...
Program already solved, but I need to put function documentation headers for each and every function in your program (for the ones you write, and keep the function header I give you for the main() function). Also make sure you keep the file block header at the top of the file, and fill in the information correctly. Secondly this week you must get your indentation correct. All indentation must use 2 spaces, and you should not have embedded tabs in...