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

this is my code #include <iostream> #include <fstream> #include <string> using n

ID: 3539389 • Letter: T

Question

this is my code

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
string source;
    string destination;
int menu;
const int sour=1,
     dest=2,
     encrypt=3,
     decrypt=4,
     exit=0;
   
do
    {
  cout<<"File Encryption and Decryption Filter"<<endl
   <<"1) Enter source filename"<<endl
   <<"2) Enter destination filename"<<endl
   <<"3) Encrypt file"<<endl
   <<"4) Decrypt file"<<endl
   <<"0) Exit"<<endl
   <<"select: ";
  cin>>menu;
  cout<<endl;

  switch(menu)
  {
   case sour:
   {
    cout<<"1: Enter source filename"<<endl;
    cin>>source;
   }
   break;

   case dest:
   {
    cout<<"2: Enter destination filename"<<endl;
    cin>>destination;
   }
   break;

   case encrypt:
      {
    if((source.empty())||(destination.empty()))
    {
     cout<<"You havenot entered source file"<<endl;
     cout<<endl;
    }
    else
    {
     fstream file1,file2;
     file1.open("source.txt", ios::in);
     file2.open("encrypted.txt", ios::out);
     char c;
     while(!file1.eof())
     {
      file1.get(c);
      file2.put(c+10);
     }

                 file1.close();
     file2.close();
    }
   }
   break;

   case decrypt:
   {
    if((destination.empty())||(source.empty()))
    {
     cout<<"You have not entered destination file"<<endl;
     cout<<endl;
    }
    else
    {
     fstream file1,file2;
     file1.open("source.txt", ios::out);
     file2.open("encrypted.txt", ios::in);
     char c;
     while(!file2.eof())
     {
      file2.get(c);
      file1.put(c-10);
     }
     file1.close();
     file2.close();
    }
   }
   break;
  }
  }while (menu != exit);
  system("pause");
  return 0;   
}

prolem is

File encryption is the science of writing the contents of a text file in a secret code. Your encryption/decryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code.

Although there are complex encryption techniques, you should come up with a simple one of your own. For example, you could read the first file one character at a time, and add 10 to the ASCII code of each character before it is written to the second file.

The program should have a menu that allows the user to perform the following tasks:


The source and destination file names should be displayed as part of the menu, if the user has specified.

For example, at the program start the menu could look like:

1: Enter source filename
2: Enter destination filename
3: Encrypt file
4: Decrypt file
0: Exit


After both file names are entered, the menu could look like:

1: Enter source filename
2: Enter destination filename
3: Encrypt file (source.txt)
4: Decrypt file (encrypted.txt)
0: Exit

and my homework error is

No (0) credit for incomplete work.

[x] -5 pt for not allowing user to enter file names.

You have hardwired the file name, the menu is not useless to specify for file name
specification.

Please rework this assignment and resubmit.

Explanation / Answer

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main()

{

string source;

string destination;

int menu;

const int sour=1,

dest=2,

encrypt=3,

decrypt=4,

exit=0;

do

{

cout<<"File Encryption and Decryption Filter"<<endl

<<"1) Enter source filename"<<endl

<<"2) Enter destination filename"<<endl

<<"3) Encrypt file "<<source<<endl

<<"4) Decrypt file "<<destination<<endl

<<"0) Exit"<<endl

<<"select: ";

cin>>menu;

cout<<endl;

switch(menu)

{

case sour:

{

cout<<"1: Enter source filename"<<endl;

cin>>source;

}

break;

case dest:

{

cout<<"2: Enter destination filename"<<endl;

cin>>destination;

}

break;

case encrypt:

{

if((source.empty())||(destination.empty()))

{

cout<<"You have not entered source file"<<endl;

cout<<endl;

}

else

{

fstream file1,file2;

file1.open(source.c_str(), ios::in);

file2.open(destination.c_str(), ios::out);

char c;

while(!file1.eof())

{

file1.get(c);

file2.put(c+10);

}

file1.close();

file2.close();

}

}

break;

case decrypt:

{

if((destination.empty())||(source.empty()))

{

cout<<"You have not entered destination file"<<endl;

cout<<endl;

}

else

{

fstream file1,file2;

file1.open(source.c_str(), ios::in);

file2.open(destination.c_str(), ios::out);

char c;

while(!file1.eof())

{

file1.get(c);

file2.put(c-10);

}

file1.close();

file2.close();

}

}

break;

}

}while (menu != exit);

// system("pause");

return 0;   

}