| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I really need help with this programming challenge that I have to do. I have no idea what to do, if someone could get me started on the right path, I would greatly appreciate it.
Here are my instructions: 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. I don't know what the STL string class is, nor do I know how to encrypt a string by modifying it via ASCII characters. |
|
#2
|
|||
|
|||
|
Re: Help with String Encryption Class
STL strings class is std::string. This looks like a class assignment so I find it hard to believe they haven't covered, at least std::string, yet would assign you a problem using it.
I'll get you started a bit with the class declaration: Code:
#include <string>
class EncryptableString : public std::string
{
void encrypt();
};
|
|
#3
|
||||
|
||||
|
Re: Help with String Encryption Class
std::string is actually a std::base_string. This container, like the other STL containers does not have a virtual destructor. As a result you cannot use it as a base class, or you risk to incorrectly destruct the objects of the derived type. I suggest you read this article: http://www.codeguru.com/Cpp/Cpp/cpp_...icle.php/c4143.
So you should use composition with std::string and other STL containers, not inheritance.
__________________
Marius BancilaHome Page | Blog My CodeGuru articles My latest articles: Visual Studio 2010 series: VC++, C++ compiler, MFC Try my VSBuildStatus add-in for Visual Studio 2005, 2008 & 2010 (v1.2.0). I do not offer technical support via PM or e-mail. Please use vbBulletin codes. Please answer my multi-core and concurrency questionnaire. |
|
#4
|
|||
|
|||
|
Re: Help with String Encryption Class
Quote:
Quote:
__________________
C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way Kindly rate my posts if you found them useful
|
|
#5
|
|||
|
|||
|
Re: Help with String Encryption Class
Just because a base class has no private destructor doesn't mean you can't derrive from it.
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|