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

PLEASE HELP ME TO SOLVE THIS TWO PROBLEMS!!! PART1 //***************************

ID: 3695874 • Letter: P

Question

PLEASE HELP ME TO SOLVE THIS TWO PROBLEMS!!!

PART1

//**************************************************************************************************************
// FILE: Decryptor.cpp
//
// DESCRIPTION: Implementation of the Decryptor class.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++, Spring 2016
//
// LAB INFO: Lab 11 Date/Time: your-lab-date-and-time TA: your-lab-ta
//**************************************************************************************************************
#include <fstream> // For ifstream and ofstream class declarations
#include "Decryptor.hpp" // For Decryptor class declaration

using namespace std;

//----- Decryptor() --------------------------------------------------------------------------------------------
// Default constructor. Every class must have at least one constructor even if there are no data members to
// initialize. This particular constructor does nothing so just write a pair of empty braces with no statements
// inside them. See Encryptor::Encryptor() for an example.
//--------------------------------------------------------------------------------------------------------------
???

//----- decryptFile() ------------------------------------------------------------------------------------------
// Reads and decrypts the contents of pCipherFile and outputs the decrypted text to pPlainFile. pCipherFile
// ends with "#####" which acts as a sentinel, so when reading pCipherFile we use a sentinel loop.
//--------------------------------------------------------------------------------------------------------------
// Write the function header and left brace
???
// Define an ifstream object named 'fin' and open 'pCipherFile' for reading. Note: pCipherFile is a string
// object. The ifstream constructor expects the input parameter to be a C-string. Given a C++ string object,
// we can get the C string stored within it by calling the string::c_str() function, e.g.,
//
// string pCipherFile = "cipher.txt"; // pCipherFile is a C++ string
// ifstream fin(pCipherFile.c_str()); // Get the C-string contained w/in pCipherFile and pass it as the arg
???

// Define an ofstream object named 'fout' and open 'pPlainFile' for writing. Note that pPlainFile is a C++
// string object, so call c_str() on it which will get the C-string contained within pPlainFile and pass it
// to the ofstream constructor as the arg.
???

// Write a sentinel loop which reads 5-character ciphertext strings from the ciphertext file. Each time
// through the loop we decrypt the ciphertext string and send the output to the plain text file. We read 5-
// character ciphertext strings by calling readCipherString() and passing 'fin' as the input parameter.
// The format of a sentinel loop is:
//
// Read a value
// While the value that was read is not the sentinel Do
// Process the value
// Read a value
// End While

// Define string object named 'cipherstring' and initialize it to the string returned by calling the
// readCipherString(fin) function. Note that 'fin' is passed by-reference. ifstream and ofstream objects
// must always be passed by-reference.
string cipherstring = readCipherString(fin);

// While cipherstring is not equal to the sentinel string "#####' Do...
while(??? != ???) {

// Call decryptCipherString() passing 'cipherstring' as the argument. Send the character returned from
// decryptCipherString() to 'fout'.
???

// Call readCipherString() passing 'fin' as the argument and assign the string returned readCipher
// String() to 'cipherString'.
???

// End the sentinel loop.
???

// Close fin and fout.
???
???

// End the function
???


//----- DecryptCipherString() ----------------------------------------------------------------------------------
// Decrypts a ciphertext string and returns the decrypted plaintext character. This function is basically a big
// if-elseif-elseif-... statement. See Encryptor::encryptPlainChar(). What you are doing here is very similar.
//--------------------------------------------------------------------------------------------------------------
// Write the function header and the left brace
???
// Define a char variable named 'plainchar' and initialize it to the space character ' '.
???

// If pCipherString is equal to the string " ** *" Then
// plainchar <- 'A'
if (pCipherString == " ** *") {
plainchar = 'A';

// Else if pCipherString is equal to the string " * *" Then
// plainchar <- 'B'
} else if (pCipherString == " * *") {
plainchar = 'B';

// Else if pCipherString is equal to the string " ***" Then
// plainchar <- 'C'
???

// ... and so on for each of the remaining characters.
???

// Return plainchar
???

// End the function
???

//----- readCipherString () ------------------------------------------------------------------------------------
// When this function is called, the input stream pointer 'pFin' is pointing at the beginning of a ciphertext
// string which consists of five star and space characters, e.g.,
//
// + -- These are characters in the file which have already been read and processed.
// |
// | +---+--- A ciphertext "character" is actually a 5-char string containing '*' and ' ' chars. This one
// | | | consists of three stars separated by two spaces.
// V V V
// .....* * *.....
// ^ ^
// | |
// | +-- These are characters in the file which we have not read yet
// |
// +-- This is the position of the input stream pointer pFin
//
// What we need to do is read the five characters starting at the position of the input stream pointer and turn
// these five characters into a string object which we will return. This can be accomplished by writing a count-
// ing loop which executes five times. Each time through the loop we read a single character using the input
// stream get() function -- we use get() because it reads and returns spaces. For each character that we read,
// we stick it onto the end of a string object using the string concatenation operator. After doing this five
// times, we have a five character string containing the stars and spaces.
//--------------------------------------------------------------------------------------------------------------
//???
string Decryptor::readCipherString(ifstream& pFin) // Note: ifstream objects must be passed by-reference
{
// Define and instantiate a string object named 'cipherstring' and initialize this string object to the
// empty string with the assignment operator.
???

// Write the first line of a counting loop (using a for loop) which executes five times, i.e., initialize an
// int variable named 'cntr' to 1, and each time through the loop, increment cntr. Keep looping as long as
// cntr is less than or equal to 5.
???

// Call pFin.get() to read a single character. get() returns a char which we assign to a char variable
// named ch. Note that ch must be defined as a char.
???

// Concatenate ch onto the end of cipherstring using the string concatenation operator +.
cipherstring += ch;

// End the for loop.
???

// Return cipherstring.
???

// End the function
???

PART 2

//**************************************************************************************************************
// FILE: Test.cpp
//
// DESCRIPTION: Implementation of the Test class.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++, Spring 2016
//
// LAB INFO: Lab 11 Date/Time: your-lab-date-and-time TA: your-lab-ta
//**************************************************************************************************************
#include "Decryptor.hpp" // For Decryptor class declaration
#include "Encryptor.hpp" // For Encryptor class declaration
#include "Test.hpp" // For Test class declaration

using namespace std;

//----- Test() -------------------------------------------------------------------------------------------------
// Default constructor. Every class must have at least one constructor even if there are no data members to
// initialize. This particular constructor does nothing so just write a pair of empty braces with no statements
// inside them.
//--------------------------------------------------------------------------------------------------------------
???

//----- run() --------------------------------------------------------------------------------------------------
// Performs the testing of the Encryptor and Decryptor classes. We instantiate an Encryptor object and use it to
// encrypt the secret message stored in the file "plain.txt", writing the encrypted message to a file named
// "cipher.txt". Then we instantiate a Decryptor object and use it to decrypt the encrypted message stored in
// "cipher.txt", writing the output to a file named "plain-new.txt". To verify the program works correctly, load
// both "plain.txt" and "plain-new.txt" into the editor pane, and verify the two files are identical (except
// that "plain-new.txt" will not contain the whitespace characters that are in "plain.txt").
//--------------------------------------------------------------------------------------------------------------
// Write the function header and the left brace
???
// Define and instantiate an Encryptor object named 'encryptor' calling the default constructor to
// initialize the object.
???

// Call the encryptFile() function on 'encryptor' and pass "plain.txt" as the plaintext file name and
// "cipher.txt" as the ciphertext file name.
???

// Define and instantiate a Decryptor object named 'decryptor' calling the default constructor to
// initialize the object.
???

// Call the decryptFile() function on 'decryptor' and pass "cipher.txt" as the ciphertext file name and
// "plain-new.txt" as the new plaintext file name.
???

// End the function
???

Explanation / Answer

Try the below code, i think it may help you to an extent....

//PART1

//**************************************************************************************************************
// FILE: Decryptor.cpp

#include <fstream>           // For ifstream and ofstream class declaration
#include <string>           // For strings
#include "Decryptor.hpp"   // For Decryptor class declaration
using namespace std;

class Decryptor
{
   Decryptor() {}
  
   // Member function declarations
   string DecryptCipherString(string pCipherString);
   string readCipherString(ifstream& pFin);

   void decryptFile(string pCipherFile,string pPlainFile)  
   {

       // string pCipherFile = "cipher.txt";
       ifstream fin(pCipherFile.c_str());
        fin.open(pCipherFile,"r");
      
       // string pPlainFile = "plain-new.txt";
       ofstream fout;
       ofstream fout(pPlainFile.c_str());
       fout.open(pPlainFile,"w");

// sentinel loop which reads 5-character ciphertext strings
       char ciper_ch;
       string cipherstring = readCipherString(fin);
       while(cipherstring != "#####") {
           cipher_ch = decryptCipherString(cipherstring);
           fout.write(cipher_ch);
           cipherString = readCipherString(fin);
       }

   // Close fin and fout.
fin.close();
   fout.close();
  
   } // decryptFile() ends....


}; // Decryptor class ends...

string Decryptor::DecryptCipherString(string pCipherString)
{
char plainchar= ' ';

   if (pCipherString == " ** *") {
plainchar = 'A';
} else if (pCipherString == " * *") {
plainchar = 'B';
   } else if (pCipherString == " ***") {
plainchar = 'C';
   }
   else{
// ... and so on for each of the remaining characters.
//// DID NOT SPECIFIED THE REMAINING CHARACTERS COMPARISION CHARACTERS HENCE LEFT BLANK IN ELSE LOOP....
   }
  
   // Return plainchar
return plainchar;
}


string Decryptor::readCipherString(ifstream& pFin)
{

   string cipherstring = '';

for(int cntr=1; cntr <= 5; cntr++)
   {
       char ch;
       ch = pFin.get();

       cipherstring += ch;
   }
// Return cipherstring.
   return cipherstring;
  
}


//PART2

//**************************************************************************************************************
// FILE: Test.cpp


#include "Decryptor.hpp" // For Decryptor class declaration
#include "Encryptor.hpp" // For Encryptor class declaration
#include "Test.hpp" // For Test class declaration
using namespace std;

class Test
{
       Test() {}
      
       void run()
   {
           Encryptor encryptr = new Encryptor();

           // Call the encryptFile() function on 'encryptor' and pass "plain.txt" as the plaintext file name and
           // "cipher.txt" as the ciphertext file name.          
           // HERE THE encryptFile() DEFINITION IS NOT GIVEN SO THOUGHT THAT PLAINTEXT FILE NAME AS ARGUMENT 1
           // AND CIPHERTEXT FILE NAME AS ARGUMENT 2 AND PASSED TO encryptFile() FUNCTION....
           encryptr.encryptFile("plain.txt","cipher.txt");

           Decryptor decryptr = new Decryptor();
           // Call the decryptFile() function on 'decryptor' and pass "cipher.txt" as the ciphertext file name and
           // "plain-new.txt" as the new plaintext file name.
           // HERE THE decryptFile() DEFINITION IS NOT GIVEN SO THOUGHT THAT CIPHERTEXT FILE NAME AS ARGUMENT 1
           // AND NEW PLAINTEXT FILE NAME AS ARGUMENT 2 AND PASSED TO decryptFile() FUNCTION....
           decryptr.decryptFile("cipher.txt","plain-new.txt");
          
       }

}; // Test class ends...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote