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

PLease Help! c++ code Write an abstract file filter class (Filter.h file) that d

ID: 3917943 • Letter: P

Question

PLease Help! c++ code

Write an abstract file filter class (Filter.h file) that defines a pure virtual function for transforming a character. Pure virtual function: a virtual member function that must be overridden in a derived class that has objects. The abstract base class contains at least one pure virtual function: virtual void function_name() = 0; The = 0 indicates a pure virtual function, and there must be no function definition in the base class. Create two (2) derived classes of the file filter. One class that performs encryption as explained below, and another that transforms a file to all upper case. Prompt the user to select from these choices (1) being to upper case and (2) being to encryption. The class should have the following member function: void doFilter(ifstream& in_stream, ofstream& out_stream);// Should be called to perform the filtering The member function for transforming a single character should have the prototype: char transform(char ch); The encryption filter class “transform” function will convert the ASCII value for encryption by adding five (5) to the value and convert to the character for output (this is the encryption key). The program will prompt for the input file name from a function, echo the original file contents from a function, and then prompt for the output file name from a function. It will prompt for “1” for upper case output, or “2” for encryption output (this can be in main). The program will write to the output file and display the output to the console window. The program will have separate open_inputFile and open_outputFile functions with error checking in each, and a separate display function. All functions associated with the filter object will be in the Filter.h file.

Explanation / Answer

Please find the code below:

Filter.h

#ifndef FILTER_H_

#define FILTER_H_

#include <fstream>

#include <sstream>

using namespace std;

class Filter{

virtual void doFilter(ifstream& in_stream, ofstream& out_stream)=0;

virtual char transform(char ch) =0;

};

#endif /* FILTER_H_ */

main.cpp--

#include<iostream>

#include "Filter.h"

class Encryption : public Filter{

public:

void doFilter(ifstream& in_stream, ofstream& out_stream){

//rewind the file pointer

if (in_stream.is_open()) //if file opened

{

cout<<"Opening file for encryption...... ";

in_stream >> std::noskipws;

char data;

in_stream.clear();

in_stream.seekg(0);

string candidate,line;

while(in_stream>>data){

data = transform(data);

out_stream<<data;

}

cout<<"Encryption done...... ";

}else{

cout<<"File not found";

return;

}

}

char transform(char ch){

return ch+5;

};

};

class UpperCase : public Filter{

public:

void doFilter(ifstream& in_stream, ofstream& out_stream){

//rewind the file pointer

if (in_stream.is_open()) //if file opened

{

cout<<"Opening file for Uppercase...... ";

in_stream >> std::noskipws;

char data;

in_stream.clear();

in_stream.seekg(0);

string candidate,line;

while(in_stream>>data){

data = transform(data);

out_stream<<data;

}

cout<<"File content changed to upper case...... ";

}else{

cout<<"File not found";

return;

}

}

char transform(char ch){

if(ch>='a' && ch<='z'){

ch = ch-32;

}

return ch;

};

};

int main()

{

ifstream file("open_inputFileEncrypt.txt");

ofstream myfile ("open_outputFileEncrypt.txt"); //printing data to out file

Encryption e;

e.doFilter(file,myfile);

ifstream file2("open_inputFileUpper.txt");

ofstream myfile2("open_outputFileUpper.txt"); //printing data to out file

UpperCase u;

u.doFilter(file2,myfile2);

return 0;

}

open_inputFileEncrypt.txt----

hello how are YIOU

open_inputFileUpper.txt---

hello how are YIOU

output::::

open_outputFileEncrypt.txt--

mjqqt%mt|%fwj%^NTZ

open_outputFileUpper.txt

HELLO HOW ARE YIOU

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