Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

What is employee requisition?

Answered: 1 week ago

Question

LO4 Specify how to design a training program for adult learners.

Answered: 1 week ago