PS
Just occured to me, as you're using cin for input, which breaks strings on whitespace...
If I put a space between the last word and the full stop/period then your program's happy! :-)
1 2
|
the fish rules .
That appears to be a sentence!
|
So it looks like you might need to modify your word() function if you want to allow people to follow normal punctuation conventions? (You need a basic sentence tokenizer!)
You might also think about moving the
string next = word();
calls out of the noun() and verb() functions and into sentence() so all part of speech are treated consistently? This may well make it easier to extend things in the future.
Similarly, the test for the final '.' looks like it should probably be handled by sentence() rather than main().
Andy
PS On a slightly related note, a common convention is for function names to generally be verbs, so you might want to consider altering the existing functions so their names say what they do. e.g. word() -> get_next_word() (or getNextWord(), etc) and noun() -> is_noun() (or isNoun(), etc, inspired by the C standard library's isdigit, etc.) Not everyone follows this convention, but I find this helps me understand how my programs work.