RAM DESCRIPTION: You will create a C++ program that will allow the user to play the game Hangman. Hangman is traditionally a paper & pench One player thinks of a word and the other player tries to guess it by suggesting letters that may be in the word. Your program will be player one, by pulling a word from a "word bank" and then player two is the user of your program. The game is over when one or two things happen: The user correctly completes the word. The user incorrectly guesses a letter six times. + ARRAYS oefore Majoresop torunagain. Comment You will have four arrays. Three of the arrays will be C-Strings: Character array of size 21 (20 characters plus one null-terminator) that will hold the word read in from the "word bank". You may assume that the game only plays with words, not phrases. (No spaces). char word[21]; rom word bank Character array of size 21 (20 characters plus one null-terminator) that will at first hold all underscores. Then, as the user makes correct guesses, the underscores will be replaced with the correct letters. This means you will have to initialize this array to all underscores before the user makes any guesses. char underScores[21]; Hof underscores for the word. Character array of size 27 (26 characters plus one null-terminator). Initialize this array when you define it to all the uppercase letters in the alphabet. "ABCDEFGHIJKLMNOPQRSTUVWXYZ". char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Boolean array of size 26 (26 boolean values). This array will have a true/false toggle for each letter of the alphabet. If the user has guessed the letter B, then this array at element 1 will have the value of true. This array will also need to be initialized to all false before the user makes any guesses. bool userGuesses[26]; WORD BANK You will have an input file called wordBank.txt. You need to manually type in TEN or more words to this file. Your program will not be outputting to this file. wordBank.txt will be used as an input file only. LDalu CAPS * FUNCTION: INT MAIN() Open the input file wordBank.txt. If the file can't open, print out a message that a word could not be found in the word bank. Allow the user to play this game (run the program) multiple times. -while looP SETTING UP FOR THE GAME nent Set all the elements of the userGuesses array to false Using a loop, set all elements of the underScores array to the underscore character Set the stage variable to zero (the starting stage) Read in a word from the input file (get the word)- make sure that if the user runs the program multiple times that they get a different word each time from the file. romment 2och AME PLAY onother eto play

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I am trying to write this program and I got stuck on page two. Please help me write this.

PROGRAM DESCRIPTION:
You will create a C++ program that will allow the user to play the game Hangman. Hangman is traditionally a paper & pench gan
One player thinks of a word and the other player tries to guess it by suggesting letters that may be in the word. Your program wih be
player one, by pulling a word from a "word bank" and then player two is the user of your program. The game is over when one of
two things happen:
The user correctly completes the word.
The user incorrectly guesses a letter six times.
comment
voefore
y ARRAYS
Majoresop
torunagain.
You will have four arrays. Three of the arrays will be C-Strings:
Character array of size 21 (20 characters plus one null-terminator) that will hold the word read in from the "word bank".
You may assume that the game only plays with words, not phrases. (No spaces).
char word[21];
from worid bank
Character array of size 21 (20 characters plus one null-terminator) that will at first hold all underscores. Then, as the user
makes correct guesses, the underscores will be replaced with the correct letters. This means you will have to initialize this
array to all underscores before the user makes any guesses.
uppercase letters in the alphabet. "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char underScores[21]; of nderscoreS for the oord.
Character array of size 27 (26 characters plus one null-terminator). Initialize this array when you define it to all the
Boolean
array of size 26 (26 boolean values). This array will have a true/false toggle for each letter of the alphabet. If the
user has guessed the letter B, then this array at element 1 will have the value of true. This array will also need to be
initialized to all false before the user makes any guesses.
bool userGuesses[26];
WORD BANK
You will have an input file called wordBank.txt. You need to manually type in TEN or more words to this file. Your program will not
be outputting to this file. wordBank.txt will be used as an input file only.
* FUNCTION: INT MAIN
Lp all CAPS
Open the input file wordBank.txt. If the file can't open, print out a message that a word could not be found in the word
bank.
Allow the user to play this game (run the program) multiple times.
SETTING UP FOR THE GAME
do-while loop
ommen
bock
Set all the elements of the userGuesses array to false
Using a loop, set all elements of the underScores array to the underscore character'.
レ
Set the stage variable to zero (the starting stage)
Read in a word from the input file (get the word)- make sure that if the user runs the program multiple times that they get
a different word each time from the file.
comma
poch
GAME PLAY
another
of gaside to Dlay
Transcribed Image Text:PROGRAM DESCRIPTION: You will create a C++ program that will allow the user to play the game Hangman. Hangman is traditionally a paper & pench gan One player thinks of a word and the other player tries to guess it by suggesting letters that may be in the word. Your program wih be player one, by pulling a word from a "word bank" and then player two is the user of your program. The game is over when one of two things happen: The user correctly completes the word. The user incorrectly guesses a letter six times. comment voefore y ARRAYS Majoresop torunagain. You will have four arrays. Three of the arrays will be C-Strings: Character array of size 21 (20 characters plus one null-terminator) that will hold the word read in from the "word bank". You may assume that the game only plays with words, not phrases. (No spaces). char word[21]; from worid bank Character array of size 21 (20 characters plus one null-terminator) that will at first hold all underscores. Then, as the user makes correct guesses, the underscores will be replaced with the correct letters. This means you will have to initialize this array to all underscores before the user makes any guesses. uppercase letters in the alphabet. "ABCDEFGHIJKLMNOPQRSTUVWXYZ". char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char underScores[21]; of nderscoreS for the oord. Character array of size 27 (26 characters plus one null-terminator). Initialize this array when you define it to all the Boolean array of size 26 (26 boolean values). This array will have a true/false toggle for each letter of the alphabet. If the user has guessed the letter B, then this array at element 1 will have the value of true. This array will also need to be initialized to all false before the user makes any guesses. bool userGuesses[26]; WORD BANK You will have an input file called wordBank.txt. You need to manually type in TEN or more words to this file. Your program will not be outputting to this file. wordBank.txt will be used as an input file only. * FUNCTION: INT MAIN Lp all CAPS Open the input file wordBank.txt. If the file can't open, print out a message that a word could not be found in the word bank. Allow the user to play this game (run the program) multiple times. SETTING UP FOR THE GAME do-while loop ommen bock Set all the elements of the userGuesses array to false Using a loop, set all elements of the underScores array to the underscore character'. レ Set the stage variable to zero (the starting stage) Read in a word from the input file (get the word)- make sure that if the user runs the program multiple times that they get a different word each time from the file. comma poch GAME PLAY another of gaside to Dlay
(loop.condition)
While the game has not ended (user is not at stage 6 yet and they have not guessed the word), then do the following:
Call the printWord function sending the word array and the underScores array as arguments.
Call the printStage function sending the stage variable as an argument.
Call the printLettersGuessed function sending the userGuesses array and alphabet array as arguments.
Ask the user for their guess. If it is a lowercase letter, then you need to make it an uppercase letter.
cout << "
WHAT LETTER DO YOU GUESS? ";
çin >> letter;
letter =
toupper (letter); //the toupper function will make letter uppercase.
Make sure the letter is not a letter already guessed. If it is a letter they have already guessed, then force the user
to enter in a different letter.
Take the usersGuesses array and make the letter they just guessed true instead of false. For example, if they
guessed the letter 'C' then you will need to make usersGuesses[2] = true;
Find out if the letter that they guessed is inside the chosen word from the word bank.
If the letter guessed is found in the-word array, then print out CORRECT! And then put the letter in the
underScores array in the same location as the wordFromFile array.
underScores[x] = word[x]; // where x is an integer incremented by the for loop.
If there were no letters found, then print out WRONG!, increment the stage number. If the stage number
is already 6, then call the printStage() function.
%3D
Tell the user to press enter to continue.
Find out if the user has guessed every letter in the word, because if they have, then the game is done and the loop
will stop.
Find out the length of the chosen word
wordLength strlen (word);
Do a special string comparison that will compare two words up to a given length. The function is
strncmp () that you will need to use. If the chosen word (word array) and the underScores array
match, then the user has guessed the word and the game is over. Print out a message that the user won
the game.
FUNCTION: VOID PRINTSTAGE(INT)
This function will accept as a parameter the current stage and print out the respective diagram to the screen. Each time the user
guesses, a diagram is printed out. The diagram represents the user being closer and closer to being "hanged"- which is why the
game is called Hangman. At the beginning of the game, the diagram starts at stage 0:
The user will stay at stage 0 (zero) until he or she guesses incorrectly, and then he/she will advance one stage to stage 1:
+-----+
Transcribed Image Text:(loop.condition) While the game has not ended (user is not at stage 6 yet and they have not guessed the word), then do the following: Call the printWord function sending the word array and the underScores array as arguments. Call the printStage function sending the stage variable as an argument. Call the printLettersGuessed function sending the userGuesses array and alphabet array as arguments. Ask the user for their guess. If it is a lowercase letter, then you need to make it an uppercase letter. cout << " WHAT LETTER DO YOU GUESS? "; çin >> letter; letter = toupper (letter); //the toupper function will make letter uppercase. Make sure the letter is not a letter already guessed. If it is a letter they have already guessed, then force the user to enter in a different letter. Take the usersGuesses array and make the letter they just guessed true instead of false. For example, if they guessed the letter 'C' then you will need to make usersGuesses[2] = true; Find out if the letter that they guessed is inside the chosen word from the word bank. If the letter guessed is found in the-word array, then print out CORRECT! And then put the letter in the underScores array in the same location as the wordFromFile array. underScores[x] = word[x]; // where x is an integer incremented by the for loop. If there were no letters found, then print out WRONG!, increment the stage number. If the stage number is already 6, then call the printStage() function. %3D Tell the user to press enter to continue. Find out if the user has guessed every letter in the word, because if they have, then the game is done and the loop will stop. Find out the length of the chosen word wordLength strlen (word); Do a special string comparison that will compare two words up to a given length. The function is strncmp () that you will need to use. If the chosen word (word array) and the underScores array match, then the user has guessed the word and the game is over. Print out a message that the user won the game. FUNCTION: VOID PRINTSTAGE(INT) This function will accept as a parameter the current stage and print out the respective diagram to the screen. Each time the user guesses, a diagram is printed out. The diagram represents the user being closer and closer to being "hanged"- which is why the game is called Hangman. At the beginning of the game, the diagram starts at stage 0: The user will stay at stage 0 (zero) until he or she guesses incorrectly, and then he/she will advance one stage to stage 1: +-----+
Expert Solution
steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY