CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Building Interactive UIs with ASP.NET Ajax: Rebinding Client-Side Events After a Partial Page Postback
  • Speed Up Repetitive Insert, Update, and Delete Query Statements
  • Binding Data to Silverlight 4.0 Controls Using ASP.NET MVC Framework 2.0
  • ADO.NET Data Services in the .NET Framework

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old September 20th, 2009, 03:22 AM
    Wolf CCMLG Wolf CCMLG is offline
    Junior Member
     
    Join Date: Sep 2009
    Posts: 1
    Wolf CCMLG is an unknown quantity at this point (<10)
    Unhappy Help with String Encryption Class

    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.
    Reply With Quote
      #2    
    Old September 20th, 2009, 10:34 AM
    hoxsiew hoxsiew is offline
    Elite Member
     
    Join Date: Feb 2005
    Posts: 2,112
    hoxsiew is a glorious beacon of light (400+)hoxsiew is a glorious beacon of light (400+)hoxsiew is a glorious beacon of light (400+)hoxsiew is a glorious beacon of light (400+)hoxsiew is a glorious beacon of light (400+)hoxsiew is a glorious beacon of light (400+)
    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();
    };
    Reply With Quote
      #3    
    Old September 20th, 2009, 02:58 PM
    cilu's Avatar
    cilu cilu is offline
    Moderator/Reviewer/MS MVP
    Power Poster
     
    Join Date: Oct 2002
    Location: Timisoara, Romania
    Posts: 13,910
    cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)cilu has a reputation beyond repute (3000+)
    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 Bancila
    Home 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.
    Reply With Quote
      #4    
    Old September 20th, 2009, 03:16 PM
    laserlight laserlight is offline
    Elite Member
    Power Poster
     
    Join Date: Jan 2006
    Location: Singapore
    Posts: 4,808
    laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)
    Re: Help with String Encryption Class

    Quote:
    Originally Posted by cilu
    std::string is actually a std::base_string.
    std::basic_string<char>

    Quote:
    Originally Posted by cilu
    As a result you cannot use it as a base class, or you risk to incorrectly destruct the objects of the derived type.
    That said, you can meet the requirements of your instructions while reducing the risk of undefined behaviour by using private inheritance, even though composition is more appropriate here.
    __________________
    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
    Reply With Quote
      #5    
    Old September 20th, 2009, 04:33 PM
    OReubens OReubens is offline
    Elite Member
     
    Join Date: Apr 2000
    Location: Belgium (Europe)
    Posts: 2,461
    OReubens is a glorious beacon of light (400+)OReubens is a glorious beacon of light (400+)OReubens is a glorious beacon of light (400+)OReubens is a glorious beacon of light (400+)OReubens is a glorious beacon of light (400+)OReubens is a glorious beacon of light (400+)
    Re: Help with String Encryption Class

    Just because a base class has no private destructor doesn't mean you can't derrive from it.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:10 AM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.