Please work on C++ You can ONLY use given #include code you are working on #incl
ID: 3889631 • Letter: P
Question
Please work on C++
You can ONLY use given #include
code you are working on
#include <fstream>
#include <string>
#include <algorithm>
void unzip_file(const std::string& filename) {
//TODO
}
Test code(cannot change):
#include <iostream>
int main() {
std::string testFilename;
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
void unzip_file(const std::string& filename){
streampos size;
char * memblock;
string in;
string out;
in = filename;
out = filename + "-unzipped";
ifstream file (in.c_str(), ios::in|ios::binary);
ofstream ofile (out.c_str(), ios::out|ios::binary);
if (file)
{
file.seekg (0, ios::end);
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
for (int i = 4; i<size; i = i+8){
for (int j = 0; j<4; j++){
if ((i+j) < size){
ofile.write(&memblock[i+j],1);
}
}
}
for (int i = 0; i<size; i = i+8){
for (int j = 0; j<4; j++){
if ((i+j) < size)
ofile.write(&memblock[i+j],1);
}
}
ofile.close();
delete[] memblock;
}
}
int main () {
string filename;
cout << "Enter file name :" << endl;
cin >> filename;
unzip_file(filename);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.