Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please expert I need this task in C++ language quickly please . Exercises: A file transformer reads an input file, transforms it in some way,

Please expert I need this task in C++ language quickly please .

Exercises: A file transformer reads an input file, transforms it in some way, and writes the results to an output file. Write an abstract file transformer class that defines a pure virtual function for transforming a character. Create one derived class of your file transformer 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 doTransform(ifstream &in, ofstream &out) This function should be called to perform the actual transformation. The member function for transforming a single character should have the prototype: char convert(char ch) The encryption class should have a constructor that takes an integer as an argument and uses it as the encryption key. Task 1: Implement fileTransformer & copyFile classes and try the provided main to test your code. Task 2: Implement upperFile class and try the provided main to test your code. You may use the read-made function toUpper provided in iomanip. Task 3: Implement encryptFile class and try the provided main to test your code. Bonus Task: Add a decrypt function to the class encryptFile. The function takes an input file (ifstream) to read encrypted data from, and an output file (ofstream) to write data to after decryption. The function uses the member variable key for decryption. In main, call decrypt using a[2] , giving it the file you encrypted in task 3 as input and an output file called decrypted.txt.

Base Code below may be used. CS213: Object Oriented Programming #include #include Lab 9: Virtual Functions + Abstract Classes using namespace std; class FileTransformer { public: void doTransform(ifstream &in, ofstream &out); virtual char convert(char ch)=0; }; class copyFile:public FileTransformer { public: char convert(char ch); }; class upperFile:public FileTransformer { public: char convert(char ch); }; class encryptFile:public FileTransformer { int key; public: encryptFile(int k); char convert(char ch); }; int main() { FileTransformer* a[3]; ifstream iFile("f.txt"); ofstream copied("c.txt"),encrypted("e.txt"),capitalized("cap.txt"); for(int i=0;i<3;i++) { if(i==0) { a[i] = new copyFile; a[i]-> doTransform(iFile,copied); } else if(i==1) { a[i] = new upperFile; a[i]-> doTransform(iFile,capitalized); } else if(i==2) { int key; cout<<"Enter encryption key:"; cin>>key; a[i] = new encryptFile(key); a[i]-> doTransform(iFile,encrypted); } } delete[] a; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions