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

++ hello there, can anybody please help me? i have been trying all day to do thi

ID: 3666527 • Letter: #

Question

++ hello there, can anybody please help me? i have been trying all day to do this but i couldn't. i am taking a computer science class and i am not majoring in it. the materials we take are too hard for me to understand.

"

add a new class TransformEncryption. It will read the file characters into a 1D or 2D array. It will not change any of the input characters, but will write them to the output file in a different order than they were read. Don’t just reverse the file, but that is thinking in the right direction! You will need a key. How will you use it?

"

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

class Encryption
{
   protected:
      ifstream inFile;
      ofstream outFile;
   public:
      Encryption(char *inFileName, char *outFileName);
      ~Encryption();
      virtual char transform(char ch) const = 0;
      void encrypt();

};

Encryption::Encryption(char *inFileName, char *outFileName)
{
   inFile.open(inFileName);
   outFile.open(outFileName);
   if (!inFile)
   {
      cout << "The file " << inFileName
         << " cannot be opened.";
      exit(1);
   }
   if (!outFile)
   {
      cout << "The file " << outFileName
         << " cannot be opened.";
      exit(1);
   }
}
Encryption::~Encryption()
{
   inFile.close();
   outFile.close();
}


void Encryption::encrypt()
{
   char ch;
   char transCh;
   inFile.get(ch);
   while (!inFile.fail())
   {
      transCh = transform(ch);
      outFile.put(transCh);
      inFile.get(ch);
   }
}

class SimpleEncryption : public Encryption
{
   public:
      char transform(char ch) const
      {
         return ch+1;
      }
      SimpleEncryption(char *inFileName, char *outFileName)
         : Encryption(inFileName, outFileName)
      {
      }
};

int main()
{
   char inFileName[80], outFileName[80];
   cout << "Enter name of file to encrypt: ";
   cin >> inFileName;
   cout << "Enter name of file to receive "
      << "the encrypted text: ";
   cin >> outFileName;
   SimpleEncryption obfuscate(inFileName, outFileName);
   obfuscate.encrypt();
   return 0;
}

Explanation / Answer

#include<iostream.h>

#include<conio.h>

#include<fstream>

#include<cstdlib>

using namespace std;

class TransformEncryption{

    protected:

        ifstream inFile;

        ofstream outfile;

    public :

            TransformEncryption(char *inFileName ,char *outFileName);

            ~TransformEncryption()

            virtual char transform(char ch) const = 0

            void transform();

};

// constructor to intilaize and it is parameter constructor

TransformEncryption :: TransformEncryption(char *inFileName ,char *outFileName){

            inFile.open(inFileName)

            outFile.open(outFileName)

            if (!inFile)

            {

                cout << "The file " << inFileName<< " cannot be opened."

                exit(1)

            }

            if (!outFile)

            {

                cout << "The file " << outFileName<< " cannot be opened."

                exit(1)

            }

}

//destructor

TransformEncryption::~TransformEncryption(){

            inFile.close();

            outFile.close();

}

// file read characters

void TransformEncrytion::transform(){

            char ch;

            char transCh;

            inFile.get(ch);

            while(!inFile.fail()){

                transCh = transform(ch);

                outFile.put(transCh);

                inFile.get(ch);

            }

            //above virtual function defined here

            char transform(char ch) const{

                return ch+1;

            }}

int main()

{

            char inFileName[80], outFileName[80];

            cout << "Enter name of file to encrypt: ";

            cin >> inFileName;

            cout << "Enter name of file to receive "<< "the encrypted text: ";

            cin >> outFileName;

            TransformEncryption transEnc;

            transEnc.TransformEncryption(inFileName, outFileName);

            transEnc.transform();

            return 0;

}