Please, just post the code inside code blocks, as in
// This is C++ code
Asking us to download data and then analyze it is inconvenient at best, and a vector for malware at worst. :-(
rubberman
Posting Virtuoso
1,564 posts since Mar 2010
Reputation Points: 277
Solved Threads: 179
You posted Code that makes no sense at all.
1) Output a message
2) define a string variable
3) Sort nothing since all you did was declare a variable
4) declare a prototype for a non-existant function
5) start a loop the
a) inputs a string
b) outputs the string
You need to think through what you want to do and put the steps in their proper order.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
some hints/psuedocode
1) create a std::stack of strings
2) Either read words one by one, ending with a sentential value or read the whole sentence
3) If reading words one by one, just add it to the stack else if reading the whole sentence you will have to do some parsing, google "C++ split" or something similar, most likely you will use stringstream and the add that to the stack.
4) Now just pop the stack and output the value popped
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
A stack is a virtual container that behaves something like an array but has restricted, instead of random access, to whats inside.
The first thing you need to be able to do is be able to identify separate words (also known as tokens or substrings or whatever). Using the enter key and accepting input with the >> operator is one way to get single words, though input isn't necessarily restricted to one word at a time. For example, you can also read in an entire line consisting of multiple words separated by a space (using getline())and then find the spaces to separate the individual words. Finding the spaces can be done several diffent ways, depending on what you know how to do.
1) You could evaluate each char in the input line one at a time. If it isn't a space you add it to a new char array (word)and when you find a space you add a null terminating char to the end of the new char array and then go on to a new char array (word).
2) You could use one of the find() method of the STL string class if you know about STL strings.
3) You could use strtok().
4) You could use a stringstream.
And there may well be other ways to find individual words in a line of input, too.
The point is we don't know what tools you have available. Use what your education has provided you so far. If you are supposed to strike out on your own and find what you can find to do the trick, then pick and choose from one of the above and look them up in your favorite reference material, posting specific questions about a specific process if you have to.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396