void printSpaced(string s);
This function prints a string with a space inserted in between
consecutive characters. Thus, "wash" gets printed as if it were
"w a s h".
string mkShadowString(string s);
Given a string, this function returns a string of the same length, but
consisting solely of underscores (_'s). For example, "food" will
be shadowed into "____".
string uncover(string original, string covered, char c);
All occurrences of the character c within string
original will be uncovered from string covered, and
the resulting string returned. Here, original and
covered have the same length. For example, we will have
original covered c output
"housepet" "_______" 'e' "____e_e_"
"hello" "_e___" 'l' "_ell_"
It is easy to see why this function would be useful for implementing Hangman.
string crossOut(char c, string s);
This function "crosses out" the input character c from the input string s, by
replacing it with a '*', and returns the result string. For example, if you cross out character 'e' from string "get", we will have string "g*t".
Submit: ~/bin/submit -c=IC210 -p=lab07 lab07.cpp
Before you start:
On the right is an example run of what you need to create.
If the number of guesses hits zero, then instead print "You lose!!!!". It thus ends with two possible outputs:
You win!!!! The word was THEWORD You lose!!!! The word was THEWORD
Your program must first choose a random word from the file
words07.txt at the start of the program. You can hardcode this
file name into your program.
How do you pick a random number? Recall that you first need a seed value that you will get from the user, and then get a random number like so:
int seed;
cin >> seed;
srand(seed);
int n = rand() % 1466;
We will choose one of the 1466 words from words07.txt. In
other words, you must read the nth word from that file where n is your random
number! Start counting the words in the file at 0. That is, if n is 0, it means that the first word has been chosen in the
file. You'll also need to include cstdlib for these rand functions.
Other details that you must follow:
'\t') to make space between
the remaining guesses and the pad abcdedfhijklmnopqrstuvwxyz.
That is,
Wrong guesses remaining: 5\t*bcd*fghijklmn*pqr*t*vwxyz
Submit: ~/bin/submit -c=IC210 -p=lab07 lab07.cpp hangman.cpp
Make a copy of your hangman.cpp to hangman2.cpp. You will work with hangman2.cpp for this part.
The only thing we haven't done is to draw the little man. Rather than just having a countdown with the number of guesses remaining, draw the man! To get you started, here are some strings that will help you:
// use the code to draw the hanging man:
string fh = " ____ \n"
" | |\n"
" _O_ |\n"
" | |\n"
" / \\ |\n"
"______|_\n";
string ch = " ____ \n"
" | |\n"
" |\n"
" |\n"
" |\n"
"______|_\n";
cout << fh << endl;
cout << ch << endl;
Submit: ~/bin/submit -c=IC210 -p=lab07 lab07.cpp hangman.cpp
hangman2.cpp