Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

File Filter A file filter reads an input file, transforms it in some way, and wr

ID: 3740423 • 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

FileFilter:

FilterFile.h:

#ifndef FILEFILTER_H
#define FILEFILTER_H
#include
#include
#include
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);
}
};

Has a uninterminated #indef

in does not name a type

unexpected unequalified id before while

Encryption.h:

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)
{
}
};

main. cpp:

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;
}

Explanation / Answer

#include "stdafx.h"
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
class FileFilter
{
private: int key;
public:
FileFilter()
{
}
FileFilter(int key)
{
this->key=key;
}
char transform(char ch)const
{
if(ch>='a' && ch<='z')
return ((ch-'a')+key)%26+'a';

else if(ch>='A' && ch<='Z')
return ((ch-'A')+key)%26+'A';
}
virtual void doFilter(ifstream &in, ofstream &out)const=0;
};

class Encryption : public FileFilter
{

public:
Encryption()
{
}
Encryption(int key):FileFilter(key)
{
  
}
void doFilter(ifstream &in,ofstream &out)const
{
char ch;
while(!in.eof())
{
in>>ch;
if(isalpha(ch))
out<<transform(ch);
else
out<<ch;
}

}
};

class UpperCase :public FileFilter
{
public:
void doFilter(ifstream &in,ofstream &out)const
{
char ch;
while(!in.eof())
{
in>>ch;
if(isalpha(ch))
out<<(char)toupper(ch);
else
out<<(char)ch;
}
}
};
class Copy :public FileFilter
{
public:
void doFilter(ifstream &in,ofstream &out)const
{
char ch;
while(!in.eof())
{
in>>ch;
out<<ch;
}
}
};
int main()
{
string filename,outfile;
cout<<"Enter File Name: ";
cin>>filename;

ofstream outFile;
ifstream inFile;
inFile.open(filename);

if(inFile==NULL)
{
cout<<"Cannot open the file "<<filename;
exit(0);
}

Encryption e;
UpperCase c;
Copy c2;

do{
cout<<"1.Encryption"<<endl;
cout<<"2.To transform uppercase"<<endl;
cout<<"3.Copy to another file"<<endl;
cout<<"4.exit"<<endl;
cout<<"Enter your choice: ";
int choice;
cin>>choice;
int key;
switch(choice)
{
case 1:
cout<<"Enter Encryption Key(2-25): ";
cin>>key;
cout<<"Enter output file name: ";
cin>>outfile;
outFile.open(outfile);
  
if(outFile==NULL)
{
cout<<"Cannot create the file "<<filename;
exit(0);
}

e=Encryption(key);
e.doFilter(inFile,outFile);
cout<<"File Encrypted Successfully"<<endl;
break;
case 2:
cout<<"Enter output file name: ";
cin>>outfile;
outFile.open(outfile);
  
if(outFile==NULL)
{
cout<<"Cannot create the file "<<filename;
exit(0);
}

  
c.doFilter(inFile,outFile);
cout<<"File Transformed Successfully"<<endl;
break;

case 3:
cout<<"Enter output file name: ";
cin>>outfile;
outFile.open(outfile);
  
if(outFile==NULL)
{
cout<<"Cannot create the file "<<filename;
exit(0);
}

  
c2.doFilter(inFile,outFile);
cout<<"File Copied Successfully"<<endl;
break;
case 4:
exit(0);
default:
cout<<"Invalid choice"<<endl;
}
}while(1);
system("pause");
return 0;
}

Use Visual C++ 2010 to run this program.
Thank you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote