I need help with this assignment. I know pure basics cin, cout, type stuff. I don't know this advanced stuff.
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 encryption key.
#include <iostream>
#include <fstream>
#include <cctype>
usingnamespace std;
// This is the abstract Filter class. Concrete derived classes will override the // transform member function class Filter
{
public:
void doFilter(WHAT SHOULD YOU PUT IN HERE);
protected:
virtualchar transform(char ch) = 0;
};
// Filter::doFilter Performs actual filtering.
void Filter::doFilter(WHAT SHOULD YOU PUT IN HERE)
// Uppercase subclass filter class
int main( )
// Explain the program
// Echo the input file
// Get name of output file
// Open the output file
// Process
// Close output file and reopen for reading so we can print
// Close all files
// Print file
// Print the file contents
// Go back to beginning of file for further processing
can you make a simple class yet?
can you read a file yet?
you have to start with the small pieces and build up...
an easy encryption algorithm:
srand(number_password);
for(all the bytes)
byte ^= rand();
decryption is the exact same algorithm. If you bungle the password, you get junk out, if you get it right, it decrypts to the original. the output will be binary, not text, so watch that.
upper case of a file can be done by loading the entire file into one giant string and doing a std::transform of toupper on it.
so those 2 tasks can be done with minimal code (about 5 lines each give or take), you just need to wrap the class/virutal concepts around them. I would first code these 3 things (read a file and write it back out doing nothing), then uppercase, and finally encryption (be sure to test decrypting it back to the original). Once you have these stub pieces working, then wrap the class stuff around those ideas.
No, I don't know how to do classes and read a file yet. Ive been trying to read and learn on tutorial sites but still dont understand and my homework assignment is due relatively soon.
a class is a user defined variable type.
you can't just say x = 3 without making x have a type, and same for your own types, so you have to name it. the above names it by saying class filter; yours left the name and class description off so it would not compile there.
then you can use it:
filter x; //filter type created and exists, ok, can make variable of that type now.