CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: C++ Strings

  1. #1
    Join Date
    Oct 2010
    Posts
    3

    C++ Strings

    Hi!
    I'm having problems doing a C++ homework :S
    Here's the exercice:
    " Make a program that ask the user for a text line (25 characters maximum)
    and make them appear in the reverse order, two by two. If the characters number is odd, the last character should still appear on the screen.
    The text line should neither be modified, neither copied into an auxiliary variable.

    (a) Make an implementation using C++ strings, using a "while" cicle to show the letters in the reverse order, two by two.

    (b) Make an implementation using C strings using the "for" cicle to show the letters in the reverse order, two by two

    Example:
    (Odd) Joy day. shows up as oJ yad.y
    (Even) Joy day!?shows up as oJ yad!y?

    Note: Make sure that no text lines with more than 25 characters are accepted."


    Can somebody help me? Please :/
    Thank you

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: C++ Strings

    What have you done so far?

    Viggy

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: C++ Strings

    What part of your homework have you already done?
    What problems do you have with the rest?
    Victor Nijegorodov

  4. #4
    Join Date
    Oct 2010
    Posts
    3

    Re: C++ Strings

    Honestly, I'm having trouble with the entire exercice. I cannot understand which variables should I use because it says that I have to use a string.
    I also dont know the way I could make the while cicle to read the "cin" in the inverse order, two by two.
    I dont know if im making myself understandable :/

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: C++ Strings

    Then sorry!
    You must learn the basics of C/C++ from the very begin!
    Victor Nijegorodov

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: C++ Strings

    Quote Originally Posted by ammf View Post
    " Make a program that ask the user for a text line (25 characters maximum)
    First, write a program to prompt the user for input, but limit that input to 25 characters. This should be trivial using cin.getline.

    and make them appear in the reverse order, two by two. If the characters number is odd, the last character should still appear on the screen.
    You are required to swap the order of each pair of characters. So if the original input is 01234, then you would output 10324, or if its 012345, you would output 103254.

    The text line should neither be modified, neither copied into an auxiliary variable.
    That's fine, for this particular task the ability to move things around wouldn't help much anyway.

    (a) Make an implementation using C++ strings, using a "while" cicle to show the letters in the reverse order, two by two.

    (b) Make an implementation using C strings using the "for" cicle to show the letters in the reverse order, two by two
    Are you familiar with the difference between C++ std::strings and C-style strings? C-style strings are just char arrays. In general, C++ strings are both much easier and much safer to work with; but in this particular case, since you're limited to 25 characters of input anyway, most of the advantages of std::strings become irrelevant. The difference between the two implementations will be minimal, mostly limited to how the string is declared and the different type of loop. (I'm not sure what a "cicle" is.)

  7. #7
    Join Date
    Oct 2005
    Location
    England
    Posts
    803

    Re: C++ Strings

    Quote Originally Posted by Lindley View Post
    (I'm not sure what a "cicle" is.)
    I'm going to guess "cycle".
    Rich

    Visual Studio 2010 Professional | Windows 7 (x64)
    Ubuntu

  8. #8
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: C++ Strings

    Quote Originally Posted by ammf View Post
    "while" cicle ... "for" cicle
    I'm guessing 'cicle' = 'loop'
    My hobby projects:
    www.rclsoftware.org.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured