943,907 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2020
  • C++ RSS
Sep 20th, 2009
0

String Encryption Challenge Help

Expand Post »
I am having an extremely difficult time with this programming challenge I have to do. I have no idea where to begin on this. I am a beginning programmer (obvious I know), and here are my instructions for the challenge:

"Write a class EncryptableString that is derived from the STL string class. The EncryptableString 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.


If someone can maybe lay these instructions out in a more clear and simplified form so I can possibly comprehend it better. I am quite confused on how this should be done.

This is what tiny little beginning I have, hopefully it's right. I still need a lot of help on laying out where the stuff should go, and then of course actually doing it. Any help would be greatly appreciated.

EncryptableString.h
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class EncryptableString
  6. {
  7. public:
  8. EncryptableString();
  9. void encrypt();
  10. };


EncryptableString.cpp
C++ Syntax (Toggle Plain Text)
  1. #include "EncryptableString.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. void EncryptableString::encrypt()
  8. {
  9. // Encryption Code Here
  10. }



EncryptString.cpp

C++ Syntax (Toggle Plain Text)
  1. #include "EncryptableString.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. EncryptableString.encrypt();
  9.  
  10. cin.get();
  11. return 0;
  12. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Wolf CCMLG is offline Offline
20 posts
since Sep 2009
Sep 20th, 2009
0

Re: String Encryption Challenge Help

I think those instructions are pretty clear.

Create a class, that is derived from the string class. You will have to create your own constructor(s), the encryption method, and ideally input and output methods. See below for a general framework

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class myString: public string
  7. {
  8. private:
  9.  
  10.  
  11. public:
  12. myString( );
  13. myString( string source );
  14. void modify( );
  15. string theString; //should be private, and need to include input output methods
  16. };
  17.  
  18. myString::myString( )
  19. {
  20. theString = "";
  21. }
  22.  
  23. myString::myString(string source )
  24. {
  25. theString = source;
  26. }
  27.  
  28. void myString::modify( )
  29. {
  30. theString[0] = 'A';
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36. myString s1;
  37. myString s2( "Hello, World" );
  38. cout << s1.theString << endl << s2.theString << endl << endl;
  39.  
  40. s2.modify( );
  41. cout << s2.theString << endl;
  42.  
  43. return 0;
  44. }
Reputation Points: 1268
Solved Threads: 228
Posting Virtuoso
vmanes is offline Offline
1,895 posts
since Aug 2007
Sep 20th, 2009
0

Re: String Encryption Challenge Help

You can use this to encrypt your string.
C++ Syntax (Toggle Plain Text)
  1. void EncryptableString::encrypt()
  2. {
  3. for( int i = 0; i < content.length(); i++ )
  4. {
  5. if( (content[i] >= 'a' && content[i] < 'z') || (content[i] >= 'A' && content[i] < 'Z'))
  6. {
  7. content[i] += 1;
  8. }
  9. else if( content[i] == 'z' || content[i] == 'Z' )
  10. {
  11. content[i] -= 25;
  12. }
  13. }
  14. }
I made a class that has a private variable content and has two public functions: print() and encrypt().

Based on some of your start code you showed I have a feeling you are going to run into a few problems while doing this project.
C++ Syntax (Toggle Plain Text)
  1. #include "EncryptableString.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. EncryptableString.encrypt();
  9.  
  10. cin.get();
  11. return 0;
  12. }

EncryptableString.encrypt() means nothing because it is a variable type not a variable its self.

Coming across this thread made me wonder how to output a variable within a class without having to call a function. I made a new thread for that but not knowing how to do that forced me to use a print() function, which I think is messy unless this is going to be a closed source submission.
Reputation Points: 164
Solved Threads: 98
Practically a Master Poster
sfuo is offline Offline
642 posts
since Jul 2009
Sep 20th, 2009
0

Re: String Encryption Challenge Help

I believe your homework is complete. All you have to do know is put those two in one and study it well, understanding how to program.
Reputation Points: 10
Solved Threads: 3
Junior Poster
Alex_ is offline Offline
175 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Prime numbers and the for loop
Next Thread in C++ Forum Timeline: Need help with 2 functions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC