I'm working on another program for my C++ class, an extension on the word parser that I posted about here a few weeks ago. This time I'm dealing with the C++ string class rather than the older c-strings, but other than that, the base of the program is still the same. It still parses input for individual words.
Here is what I have to do: Read an input file and parse the individual words out of it (words will be returned in all lower-case and stripped of any punctuation, to make a later part of the program easier). Then I have to go through and count - up to a maximum of 100 - the # of unique words within the file, and display them in the DOS/command window at the end of the program.
The first part of the project is done; the file can be read, the words are parsed out and returned in lower-case, and all the punctuation is stripped out. What I'm having trouble with is figuring out how to implement the unique word count. What I am thinking is to put the first word read into an array. After that, compare each consequent word to each element in the array. If the word is found, do nothing; if the word is not found, add it to the array. For each element added to the array, increment a counter for the # of unique words by 1. This sounds easy, but I've been sitting here fiddling with my code all night, to no avail. I cannot get the comparison and counter to work at all. Any suggestions?
PS - sorry for so many questions, but my proffessor stinks at teaching (class oppinion, not just mine
) and the book I've got only tells me so much. I'm stumped.
Nate
Here is what I have to do: Read an input file and parse the individual words out of it (words will be returned in all lower-case and stripped of any punctuation, to make a later part of the program easier). Then I have to go through and count - up to a maximum of 100 - the # of unique words within the file, and display them in the DOS/command window at the end of the program.
The first part of the project is done; the file can be read, the words are parsed out and returned in lower-case, and all the punctuation is stripped out. What I'm having trouble with is figuring out how to implement the unique word count. What I am thinking is to put the first word read into an array. After that, compare each consequent word to each element in the array. If the word is found, do nothing; if the word is not found, add it to the array. For each element added to the array, increment a counter for the # of unique words by 1. This sounds easy, but I've been sitting here fiddling with my code all night, to no avail. I cannot get the comparison and counter to work at all. Any suggestions?
PS - sorry for so many questions, but my proffessor stinks at teaching (class oppinion, not just mine
Nate
