-
October 28th, 2010, 01:54 PM
#1
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
-
October 28th, 2010, 02:06 PM
#2
Re: C++ Strings
What have you done so far?
Viggy
-
October 28th, 2010, 02:07 PM
#3
Re: C++ Strings
What part of your homework have you already done?
What problems do you have with the rest?
Victor Nijegorodov
-
October 28th, 2010, 02:16 PM
#4
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 :/
-
October 28th, 2010, 02:24 PM
#5
Re: C++ Strings
Then sorry!
You must learn the basics of C/C++ from the very begin!
Victor Nijegorodov
-
October 28th, 2010, 02:26 PM
#6
Re: C++ Strings
Originally Posted by ammf
" 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.)
-
October 31st, 2010, 06:10 AM
#7
Re: C++ Strings
Originally Posted by Lindley
(I'm not sure what a "cicle" is.)
I'm going to guess "cycle".
Rich
Visual Studio 2010 Professional | Windows 7 (x64)
Ubuntu
-
November 1st, 2010, 12:35 PM
#8
Re: C++ Strings
Originally Posted by ammf
"while" cicle ... "for" cicle
I'm guessing 'cicle' = 'loop'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|