1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class FileFilter
{
public:
virtual char transform(char ch) = 0;
void doFilter (ifstream &in, ofstream &out);
};
void FileFilter::doFilter(ifstream &in, ofstream &out)
{
char ch;
char transCh;
in.get(ch);
while (!in.fail())
{
transCh = transform(ch);
out.put(transCh);
in.get(ch);
}
};
class Encryption : public FileFilter
{
private:
int key;
public:
char transform(char ch)
{
return ch + key;
}
Encryption (int encKey)
{
key = encKey;
}
};
class ToUpper : public FileFilter
{
public:
char transform(char ch)
{
return toupper(ch);
}
};
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 four files to be used are called: \nin.txt\nkey.txt\nupper.txt\ncopy.txt\ndouble.txt" << endl;
cout << "\nEnter file to encrypt: ";
cin >> inFileName;
/*
cout << "Enter file to receive encrypted text: ";
cin >> outFileName;
cout << "Enter encryption key: ";
cin >> offset;
*/
inFile.open(inFileName);
/*outFile.open(outFileName);
if ((!inFile) || (!outFile))
{
cout << "File opening error, close program and try again." << endl;
system("pause");
exit(1);
}
Encryption obfuscate(offset);
obfuscate.doFilter(inFile, outFile);
outFile.close();
inFile.clear();
inFile.seekg(0L, ios::beg);
cout << "\nEnter file to receive uppercase text: ";
cin >> outFileName;
outFile.open(outFileName);
while (!outFile)
{
cout << "File opening error, please re-enter name: ";
cin >> outFileName;
}
ToUpper upper;
upper.doFilter(inFile, outFile);
outFile.close();
inFile.clear();
inFile.seekg(0L, ios::beg);
cout << "\nEnter file to receive untouched copy: ";
cin >> outFileName;
outFile.open(outFileName);
while (!outFile)
{
cout << "File opening error, please re-enter name: ";
cin >> outFileName;
}
Unchanged copy;
copy.doFilter(inFile, outFile);
outFile.close();
inFile.clear();
inFile.seekg(0L, ios::beg);
*/
cout << "\nFinally, enter file to receive double spaced copy: ";
cin >> outFileName;
outFile.open(outFileName);
while (!outFile)
{
cout << "File opening error, please re-enter name: ";
cin >> outFileName;
}
DoubleSpace doubleSpace;
doubleSpace.doFilter(inFile, outFile);
inFile.close();
outFile.close();
return 0;
}
|