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 & pencil game. 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 one player on, by guessing 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.

### Arrays

You will have **four arrays**. Three of the arrays will be C-Strings:

1. **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).
   ```cpp
   char word[21];
   ```
   - *Comments:* From word bank

2. **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.
   ```cpp
   char underScores[21];
   ```
   - *Comments:* # of underscore for the word

3. **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.
   ```cpp
   char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   ```

4. **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, then this array at element I will have the value of true. This array will also need to be initialized to all false before the user makes any guesses.
   ```cpp
   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()

-
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 & pencil game. 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 one player on, by guessing 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. ### Arrays You will have **four arrays**. Three of the arrays will be C-Strings: 1. **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). ```cpp char word[21]; ``` - *Comments:* From word bank 2. **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. ```cpp char underScores[21]; ``` - *Comments:* # of underscore for the word 3. **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. ```cpp char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ``` 4. **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, then this array at element I will have the value of true. This array will also need to be initialized to all false before the user makes any guesses. ```cpp 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() -
### Game Logic and Functions for Hangman

#### Loop Condition

While the game has not ended (the user is not at stage 6 and they have not guessed the word), do the following:

1. **Display Word:**
   - Call the `printWord` function to show the current state of the word and the `underScores` array.

2. **Set Stage:**
   - Use `printStage` to set the current stage as a variable.

3. **Guess Handling:**
   - Call `printLettersGuessed` to show the `userGuesses` array and the alphabet.
   - Ask the user for their guess:
     ```cpp
     cout << "WHAT LETTER DO YOU GUESS? ";
     cin >> letter;
     letter = toupper(letter); // Converts the letter to uppercase
     ```
   - Ensure the letter hasn't been guessed before. If it has, prompt for a different one.

4. **Update Guesses:**
   - Mark the guessed letter as true in the `userGuesses` array.

5. **Check Correctness:**
   - If the letter is in the word array, print "CORRECT" and update the `underScores` array accordingly.
   - If not, print "WRONG", increment the stage number, and call `printStage`.
   - Prompt the user to continue.

6. **Win Condition:**
   - If the word is completely guessed, print a success message.

#### Function: VOID PRINTSTAGE(INT)

This function accepts the current stage and prints the corresponding diagram. It visualizes the user's progress towards being "hanged."

- **Stage 0 Diagram**:
  - A basic diagram with minimal elements.
  ```
  ________
  |      
  |
  ```

- **Stage 1 Diagram**:
  - Slightly more detailed to indicate progression.
  ```
  ________
  |      |
  |      
  ```

Players remain at stage 0 until an incorrect guess advances them to stage 1.

This guide assists in understanding the hangman game mechanics and tracking the user's progress visually through diagrams representing different stages.
Transcribed Image Text:### Game Logic and Functions for Hangman #### Loop Condition While the game has not ended (the user is not at stage 6 and they have not guessed the word), do the following: 1. **Display Word:** - Call the `printWord` function to show the current state of the word and the `underScores` array. 2. **Set Stage:** - Use `printStage` to set the current stage as a variable. 3. **Guess Handling:** - Call `printLettersGuessed` to show the `userGuesses` array and the alphabet. - Ask the user for their guess: ```cpp cout << "WHAT LETTER DO YOU GUESS? "; cin >> letter; letter = toupper(letter); // Converts the letter to uppercase ``` - Ensure the letter hasn't been guessed before. If it has, prompt for a different one. 4. **Update Guesses:** - Mark the guessed letter as true in the `userGuesses` array. 5. **Check Correctness:** - If the letter is in the word array, print "CORRECT" and update the `underScores` array accordingly. - If not, print "WRONG", increment the stage number, and call `printStage`. - Prompt the user to continue. 6. **Win Condition:** - If the word is completely guessed, print a success message. #### Function: VOID PRINTSTAGE(INT) This function accepts the current stage and prints the corresponding diagram. It visualizes the user's progress towards being "hanged." - **Stage 0 Diagram**: - A basic diagram with minimal elements. ``` ________ | | ``` - **Stage 1 Diagram**: - Slightly more detailed to indicate progression. ``` ________ | | | ``` Players remain at stage 0 until an incorrect guess advances them to stage 1. This guide assists in understanding the hangman game mechanics and tracking the user's progress visually through diagrams representing different stages.
Expert Solution
Step 1

C++ program is given below  trying to implement hangman figure in every wrong guess

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