File Filter A file filter reads an input file, transforms it in some way, and wr
ID: 3740266 • Letter: F
Question
File Filter A file filter reads an input file, transforms it in some way, and writes the results to an output file. Write an abstract file filter class that defines a pure virtual function for transforming a character. Create one subclass of your file filter class that performs encryption, another that transforms a file to all uppercase, and another that creates an unchanged copy of the original file. The class should have a member function void doFilter(ifstream &in, ofstream &out) that is called to perform the actual filtering. The member function for transforming a single character should have the prototype char transform(char ch) The encryption class should have a constructor that takes an integer as an argument and uses it as the encrytion key. Please show me the header and .cpp files
In C++ please
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class FileFilter
{
public:
virtual char transform(char ch)= 0;
void doFilter(ifstream&in, ofstream&out)
char ch
char transCh;
in.get(ch);
while(!in.fail())
{
trans Ch = transform(ch);
out.put(trans Ch);
in.get(ch);
}
};
class Encryption : public FileFilter
{
private:
int key;
public:
char transform(char ch)
{
return ch + key;
}
Encryption (int enckey)
{
key = enckey;
}
};
class Unchanged : public FileFilter
{
public:
char transform (char ch)
{
return ch;
}
};
class DoubleSpace : public FileFilter
{
public:
char transform(char ch)
{
}
};
int main()
{
ifstream inFile;
ofstream outFile;
char inFileName[100], outFileName[100];
int offset;
cout << "the files are called: ";
cin>> inFileName;
inFile.open(inFileName);
cout << "enter a file to recieve a double spaced copy: ";
cin >> outFileName;
outFile.open(outFileName);
while (!outFile)
{
cout << "File opening error, please re-enter name: ";
cin >> outFileName;
}
DoubleSpace double Space;
doubleSpace.doFilter(inFile, outFile);
infile.close();
outfile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.