This is the problem:
Write a class EncryptableString that is derived from the STL string class. The Encryptable string class adds a member function void encrypt( ) that encrypts the string contained in the object by replacing each letter with its successor in the ASCII ordering. For example, the string baa would be encrypted to cbb. Assume that all characters that are part of an EncryptableString object are letters a, .., z and A, .., Z, and that the successor of z is a and the successor of Z is A. Test your class with a program that asks the user to enter strings that are then encrypted and printed.
I wrote my code, but I can only get the output to replace the first letter with the letter A, no matter what word I input. I how would I modify the program so the first letter of the word is replaced with the seuccessive letter in the alphabet?
Here is my code so far:
#include <iostream>
#include <string>
using namespace std;
class EncryptableString: public string
{
private:
public:
EncryptableString( );
EncryptableString( string source );
void encrypt( );
string theString; //should be private, and need to include input output methods
};
EncryptableString::EncryptableString( )
{
theString = "";
}
EncryptableString::EncryptableString(string source )
{
theString = source;
}
void EncryptableString::encrypt( )
{
theString[0] = 'A';
}
int main()
{
string word;
cout << "Please enter a word: \n";
cin >> word;
EncryptableString s1;
EncryptableString s2( word );
cout << s1.theString << endl << s2.theString << endl << endl;
s2.encrypt( );
cout << s2.theString << endl;
cin.ignore();
cin.get();
return 0;
}