Question: In this game, a player is asked by computer to type in several animal names such as dog, cat, etc., in the beginning of the
In this game, a player is asked by computer to type in several animal names such as "dog," "cat," etc., in the beginning of the game session. There is no limit to the count of the names but these names must be space delimited. When entering a return key without typing anything (i.e., empty line), this process of input cycle ends. So, use getline()discussed in recent lecture to realize this input logic. Then you should break up the line of input being isolating "words". A word can be defined as a sequence of consecutive non-white-space characters with white space before and after.
Do not use anything from stringstream. For this assignment you should use functionality from and including getline(istream&, string&) and from rand_shuffle function.
The computer will pick up 1 to 3 names from those entered by the player. They are shuffled to produce a random word. The player will be asked to identify the names, given a hint of how many animals in that word. The player needs to type in names (or a name if asked one). Typing "?" will show the name list, and typing "quit" will end the game.
When succeeding to answer in two consecutive rounds, the computer's challenge becomes harder by striking out a character one by one. The position to strike out is chosen at random. So, succeeding 4 consecutive times, the random word has two strikes out shown by underscore "_" characters. On the other hand, failing to answer in two consecutive rounds, the computer's challenge becomes easier by reducing the count of strikes out.
Significant changes: The number of strike-outs should never exceed the length of the shuffled string. If it was to become greater, set the number of strikeouts to the length of the selected shuffled string. Nor should the number of strikeouts ever go negative.
When gathering up your collection of five or more animals(or words), your parser should be robust. It should handle multiple consecutive spaces at the beginning of a line, between animals, and even extra white space before the new-line.
The sample session follows(though animals have been replaced by letters of alphabet of varying lengths).,
Enter at least five animal names, e.g., cat, dog, etc...
> a bb
> ccc
>
> dddd eeeee
> ffffff
>
0: a
1: bb
2: ccc
3: dddd
4: eeeee
5: ffffff
What are 3 animals in "ccfefffecffeee" ? ffffff ccc eeeee
Yes!
What are 1 animal in "ccc" ? ccc
Yes!
Succeeded two consecutive times, challenge goes up!
What are 2 animals in "f_ccfffff" ? ffffff
Your number of input is incorrect. Enter again: ccc ffffff
Yes!
What are 1 animal in "cc_" ? ?
0: a
1: bb
2: ccc
3: dddd
4: eeeee
5: ffffff
Enter again: ccc
Yes!
Succeeded two consecutive times, challenge goes up!
What are 2 animals in "d_db_d" ? bb
Your number of input is incorrect. Enter again: dddd bb
Yes!
What are 2 animals in "f_bbff_f" ? ffffff bb
Yes!
Succeeded two consecutive times, challenge goes up!
What are 2 animals in "__eee_cc" ? eeeee cc
Nope!
What are 3 animals in "cc_ec_e_e" ? ccc eeeee b
Nope!
Missed two consecutive times, challenge goes down!
What are 3 animals in "f_fffbf_a" ? ffffff bb a
Yes!
What are 1 animal in "_" ? b
Nope!
What are 3 animals in "fe__feffeaff" ? quit
Bye...
This assignment will ask you to use , string::getline(), and random_shuffle() or shuffle() from to reduce the amount of coding. You can find many examples on the Web -- seehere for instance.
Also continuing with Truth in Advertising, I had one label that had a "goto" to to handle the response to '?' and when the number of words entered by the user did not equal the number of words within the shuffled string. In both cases the shuffled word stayed unchanged and the "goto" took me to the point where I had a call to "getline" to read another line of input from the user.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
