Question: I have some problems that I can't even figure out what's exactly wrong with my code? There's someone in here already helped me, but my

I have some problems that I can't even figure out what's exactly wrong with my code? There's someone in here already helped me, but my output didn't work as the way it suppose to be yet. Please someone tell me the problem and explain it to me. I'll thank you so much for your help. Below is the information and my code.

Required Member Functions: encrypt - which will take in a single letter and return a result of type char. encryptAll - which will manipulate class variables in a loop to encrypt all of them. getMessage - which will read in a store the message string in a class variable. getCode - which will read in and store the encoding value. printOut - which will print out the current values of the class variables. To make it more readable, make sure that you skip spaces in the string (don't change them). For example, on our ASCII machines, the message:

THE REDCOATS ARE COMING!

and the integer 5 would produce: YMJ WJIHTFYX FWJ HTRNSL&

========================================================================

#include

#include

using namespace std;

class Redcoats

{

public:

void getMessage();

void getCode();

void printOut();

private:

string message;

int code;

char encrypt(char);

string encryptAll();

};// end Redcoats class

int main()

{

Redcoats redcoat;

redcoat.getMessage();

redcoat.getCode();

redcoat.printOut();

return 0;

}//end main

void Redcoats::getMessage()

{

cout << "Enter a message to encrypt: ";

getline(cin, message);

cout << "The message you entered is: " << message << endl << endl;

}// end getMessage

void Redcoats::getCode()

{

cout << "Enter the code with which to encrypt the message: ";

cin >> code;

cout << "The code entered is: " << code << endl << endl;

}// end getCode

void Redcoats::printOut()

{

cout << "The message is " << message << endl << endl;

cout << "The code is " << code << endl << endl;

cout << "The encrypted form of the message is " << encryptAll() << endl << endl;

}//end printOut

char Redcoats::encrypt (char ch)

{

if (ch == ' ')

return ch;

else

static_cast(ch + code);

return ch;

}//end encrypt

string Redcoats::encryptAll()

{

unsigned int i;

string encryptedMessage;

for(i = 0; i < message.length(); i++) {

encryptedMessage = encrypt(message[i]);

}

return message;

}

========================================================================

my output:

Enter a message to encrypt: the redcoats are coming! The message you entered is: the redcoats are coming!

Enter the code with which to encrypt the message: 5 The code entered is: 5

The message is the redcoats are coming!

The code is 5

The encrypted form of the message is the redcoats are coming!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!