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

C++ programming I can\'t seem to figure out whats wrong with my program, any hel

ID: 3593138 • Letter: C

Question

C++ programming

I can't seem to figure out whats wrong with my program, any help would be great.



here is the program I am working on

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 derived class 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 the following member function:
void doFilter(ifstream &in, ofstream &out)

This function should be 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 encryption key.

* The encryption can be a simple adding one to each character if you wish. Or write a more complicated one if you can get it to work.

Include a FileFilter.h, EncryptionFilter.h, EncryptionFilter.cpp, UppercaseFilter.h, UppercaseFilter.cpp, UnchangedFilter.h, UnchangedFilter.cpp.

// my program

// main.cpp

#include<fstream>
#include "UnchangedFilter.h"
#include "UppercaseFilter.h"

using namespace std;
int main(){
    ifstream fs;
    fs.open("cquote.txt");

    ofstream fout;
    fout.open("cquoteOUT.txt");

    UppercaseFilter uppercaseFilter;
    uppercaseFilter.doFilter(fs , fout);
    return 0;
}


_________________________________

// FileFilter.h

#ifndef TRANSFORM_FILEFILTER_H
#define TRANSFORM_FILEFILTER_H


#include <fcntl.h>
class FileFilter {
public:
    virtual char transform(char ch) = 0;
};

#endif

____________________________________

//EncyrptionFilter.cpp

#include "EncryptionFilter.h"

void EncryptionFilter::doFilter(ifstream &in, ofstream &out) {

    char ch;
    while(in.get(ch)){
        out.put(transform(ch));
    }

}

______________________________

//EncryptionFilter.H

#ifndef TRANSFORM_ENCRYPTIONFILTER_H
#define TRANSFORM_ENCRYPTIONFILTER_H


#include<fstream>
#include<iostream>
#include "FileFilter.h"

using namespace std;
class EncryptionFilter : public FileFilter {
public:
    static int encryptionKey;
    void doFilter(ifstream &in, ofstream &out);

    explicit EncryptionFilter(int key) {
        EncryptionFilter::encryptionKey = key;
    }

    char transform(char ch) {
        return (char)(ch + encryptionKey);
    }

};


#endif


____________________________________

// UppercaseFilter.cpp

#include "UppercaseFilter.h"

void UppercaseFilter::doFilter(ifstream &in, ofstream &out) {

    char ch;
    while(in.get(ch)){
        out.put(transform(ch));
    }

}

char UppercaseFilter::transform(char ch) {
    return (char)toupper(ch);
}

__________________________________________

//UppercaseFilter.h

#ifndef TRANSFORM_UPPERCASEFILTER_H
#define TRANSFORM_UPPERCASEFILTER_H


#include <fstream>
#include <iostream>
#include "FileFilter.h"

using namespace std;
class UppercaseFilter : public FileFilter{
public:
    void doFilter(ifstream &in, ofstream &out);
    char transform(char ch) override;
};


#endif

_____________________________________

UnchangedFilter.cpp

#include "UnchangedFilter.h"

void UnchangedFilter::doFilter(ifstream &in, ofstream &out) {

    char ch;
    while(in.get(ch)){
        out.put(transform(ch));
    }

}

char UnchangedFilter::transform(char ch) {
    return ch;
}

_____________________________________________

//UnchangedFilter.h

#ifndef TRANSFORM_UNCHANGEDFILTER_H
#define TRANSFORM_UNCHANGEDFILTER_H

#include<fstream>
#include<iostream>
#include "FileFilter.h"

using namespace std;
class UnchangedFilter : public FileFilter {
public:
    void doFilter(ifstream &in, ofstream &out);
    char transform(char ch) override;
};

________________________________

txt file

//Cquote.txt

"C is quirky, flawed, and
an enormous success."
- Dennis M. Ritchie

The best thing about a boolean is even if you are wrong,
you are only off by a bit.
- Anonymous

There are only two kinds of programming languages:
those people always (complain) about and those nobody uses.
- Bjarne Strous


#endif


______________________________________

Explanation / Answer

#include<fstream>
#include "UnchangedFilter.h"
#include "UppercaseFilter.h"

using namespace std;
int main(){
    ifstream fs;
    fs.open("cquote.txt");

    ofstream fout;
    fout.open("cquoteOUT.txt");

    UppercaseFilter uppercaseFilter;
    uppercaseFilter.doFilter(fs , fout);
    return 0;
}


_________________________________

// FileFilter.h

#ifndef TRANSFORM_FILEFILTER_H
#define TRANSFORM_FILEFILTER_H


#include <fcntl.h>
class FileFilter {
public:
    virtual char transform(char ch) = 0;
};

#endif

____________________________________

//EncyrptionFilter.cpp

#include "EncryptionFilter.h"

void EncryptionFilter::doFilter(ifstream &in, ofstream &out) {

    char ch;
    while(in.get(ch)){
        out.put(transform(ch));
    }

}

______________________________

//EncryptionFilter.H

#ifndef TRANSFORM_ENCRYPTIONFILTER_H
#define TRANSFORM_ENCRYPTIONFILTER_H


#include<fstream>
#include<iostream>
#include "FileFilter.h"

using namespace std;
class EncryptionFilter : public FileFilter {
public:
    static int encryptionKey;
    void doFilter(ifstream &in, ofstream &out);

    explicit EncryptionFilter(int key) {
        EncryptionFilter::encryptionKey = key;
    }

    char transform(char ch) {
        return (char)(ch + encryptionKey);
    }

};


#endif


____________________________________

// UppercaseFilter.cpp

#include "UppercaseFilter.h"

void UppercaseFilter::doFilter(ifstream &in, ofstream &out) {

    char ch;
    while(in.get(ch)){
        out.put(transform(ch));
    }

}

char UppercaseFilter::transform(char ch) {
    return (char)toupper(ch);
}

__________________________________________

//UppercaseFilter.h

#ifndef TRANSFORM_UPPERCASEFILTER_H
#define TRANSFORM_UPPERCASEFILTER_H


#include <fstream>
#include <iostream>
#include "FileFilter.h"

using namespace std;
class UppercaseFilter : public FileFilter{
public:
    void doFilter(ifstream &in, ofstream &out);
    char transform(char ch) override;
};


#endif

_____________________________________

UnchangedFilter.cpp

#include "UnchangedFilter.h"

void UnchangedFilter::doFilter(ifstream &in, ofstream &out) {

    char ch;
    while(in.get(ch)){
        out.put(transform(ch));
    }

}

char UnchangedFilter::transform(char ch) {
    return ch;
}

_____________________________________________

//UnchangedFilter.h

#ifndef TRANSFORM_UNCHANGEDFILTER_H
#define TRANSFORM_UNCHANGEDFILTER_H

#include<fstream>
#include<iostream>
#include "FileFilter.h"

using namespace std;
class UnchangedFilter : public FileFilter {
public:
    void doFilter(ifstream &in, ofstream &out);
    char transform(char ch) override;
};


#endif

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