Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment exercises your ability to use conditionals, loops, arrays, and functions together. Instructions: Your goal for this assignment is to create a playable Hangman

This assignment exercises your ability to use conditionals, loops, arrays, and functions together.

Instructions:

Your goal for this assignment is to create a playable Hangman game. You will need to create a secret word for the user to try and guess one letter at a time.

First you need to ask the user to enter a letter. Then you'll check if that letter exists in your secret word. If it does exist, then you should tell the user and display the puzzle with the letter revealed. If the letter does not exist, then inform the user that the letter is not found. You will repeat this process until all the correct letters have been guessed or the user has entered 7 wrong letters.

Hopefully it is readily clear that you will need to use a loop to keep prompting the user to enter a letter. You will also need to use conditionals to check if the letter exists. You will need to use an array to store the secret letters (since a word is just a collection of letters). We'll also need arrays to keep track of the previously guessed letters (we don't want the player to guess wrong a second time) and the solved letters.

An example of a winning game:

image text in transcribed

Hints:

You are going to need to use multiple arrays. These arrays correspond to:

The secret word that is being guessed.

The "current board" of letters the user has found.

The list of letters the user has already guessed.

Think about what is the most appropriate type for each array. They may not all be of type chardepending on your implementation. You'll need loops in multiple places:

Continue asking the user for letters until solved or out of guesses

Printing the current puzzle

Checking if the letter exists in the puzzle

Checking if the puzzle is solved

Functional Requirements:

The user is allowed to guess using upper or lower case letters.

The user cannot guess the same letter more than once. Alert the user if they already guessed a letter.

The user is allowed 7 wrong guesses before losing the game.

Your secret word must be at least 6 letters long. This secret word must be stored in an array - not a string.

You must use arrays - not vectors.

Create a function to print the current solved puzzle

Create a function to return true or false if the letter has been already guessed

Create a function to return true or false if the letter is in the secret word

Function prototypes must be placed in a *.h file and the definitions in a corresponding *.cpp file. Your program will need to be built using the Makefile option.

Make a program in C++ that calls other functions to solve question. Please follow all directions and answer all parts of the question.

Welcome to Hangman!! Take a guess: _ Your guess: a There's a A! - - Take a guess: _- -- -A---- Your guess: c Sorry, no C's. You have 6 wrong guesses remaining Take a guess: _- -- -A---- Your guess: a You already guessed A Take a guess: PROR AMMIN Your guess: g There's a G! CONGRATS! You solved the puzzle: PROGRAMMING An example of a losing game welcome to Hangman!! Your guess: a There's a A! Take a guess: _- -- -A---- Your guess: c Sorry, no C's. You have 6 wrong guesses remaining Take a guess: _- -- -A---- Your guess: q Sorry, no Q's. You have s wrong guesses remaining Take a guess: _- -- -A---- Your guess: a You already guessed A. Pick again Take a guess: _- -- -A---- Your guess: q You already guessed Q. Pick again Take a guess: _- -- -A---- Your guess: W Sorry, no W's. You have 1 wrong guess remaining Take a guess: _- -- -A---- Your guess: x Sorry, no X's You lose. Try again

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting What the Numbers Mean

Authors: David H. Marshall, Wayne W. McManus, Daniel F. Viele

10th edition

9780077515904, 007802529X, 77515900, 978-0078025297

Students also viewed these Databases questions