Question: CS 0 0 2 - Assignment 6 : Hangman Collaboration Policy We encourage collaboration on various activities such as lab, codelab, and textbook exercises. However,
CS Assignment : Hangman
Collaboration Policy
We encourage collaboration on various activities such as lab, codelab, and textbook exercises. However, no collaboration between students is allowed on the programming assignments.
Assignment Specifications
The game called Hangman is a spelling game: one player sets up a word or phrase, represented by a row of dashes. If the guessing player suggests a letter which occurs in the word, the other player writes it in all its correct positions. If the suggested letter does not occur in the word, the other player draws one element of the hanged man stick figure as a tally mark. The game is over when:
The guessing player completes the word, or guesses the whole word correctly
The other player completes the diagram.
You must implement a simplified version of hangman in which the player gets incorrect guesses corresponding to drawing the hanged man
You are required to implement the specified functions and utilize any provided functions.
Headings you add to the document will
appear here.
Hangman Algorithm
Get phrase to be solved from the user using getline instead of the input operator to allow
for the presence of spaces in the phrase
Setup unsolved phrase so game has a separate string with dashes in place of characters
call setupUnsolved function
Display the unsolved phrase
Play Game until phrase is completely guessed, or all incorrect guesses are used up
Get a valid letter guess from user call getGuess function see below for meaning of "valid
guess"
After initial phrase has been set, user input should ONLY occur in the getGuess function
Update a string consisting of all characters quessed so far
Take action on the guess:
Correct: update unsolved phrase using the updateUnsolved function
Incorrect: increment the wrong guess count
Output game status:
updated unsolved phrase phrase with dashes for stillunguessed letters
list of characters guessed so far
number of wrong guesses left
Output game over message You lost! or Congratulations!!
Additional Requirements and Hints
Implement each function and get feedbackcredit for each before doing main game
All user input statements should be followed by outputting a blank line.
All user inputs and corresponding prompts after initial phrase setup occur only in body of
getGuess so there are no input or output statements in setupUnsolved or updateUnsolved
All phrases can have lowercase and uppercase alphabetic characters and valid guesses will use
only lowercase alphabetic characters ie in our testing, we will enter only lower case characters
as valid guesses; we will, of course, input nonalpha characters to test for invalid guesses
The player gets wrong guesses
You should be utilizing a single puzzle variable to hold the current state of the game, and
assigning to it the return value from setupUnsolved initially, and updateUnsolved
subsequently.
Use the string member function at: Remember, at can be used on either side of the
assignment operator to either "read" the value at a specified position of the string right
You should be utilizing a single puzzle variable to hold the current state of the game, and
assigning to it the return value from setupUnsolved initially, and updateUnsolved
subsequently.
Use the string member function at : Remember, at can be used on either side of the
assignment operator to either "read" the value at a specified position of the string right
side; or to "write" a new value into a position of the string left side
The function at "throws an exception" when you attempt to access a nonexistent location,
unlike the syntax; this can be a great help when debugging.
bool isalphachar: In order to check if a guess is valid ie if it is an alphabetic character
you can use this builtin predicate function that takes a single character as an argument.
Requires that you include the library.
char tolowerchar: In order to check if an uppercase letter matches its lowercase version,
we can pass it to this function
Note: The functions setupUnsolved and updateUnsolved are "complementary" to each other
one replaces letters with dashes, the other replaces those dashes with letters
So once you've got one working, the other should be real simple!
NOTE: There should be no global variables in your program!!!
Functions
The following functions are required, exactly as declared.
You may, if you wish, define other functions in addition to these.
You must define, implement and correctly invoke these functions exactly as declared here.
You may wish to copy & paste the following into your source code, and comment out the
function declarations you are not yet ready to implement.
@brief Puts dashes in place of alphabetic characters in the phrase.
@param phrase the phrase to be solved
@return the phrase with all alphabetic characters converted to dashes
string setupUnsolvedstring phrase;
@brief Replaces the dashes with the guessed character.
@param phrase the phrase to be solved
Example R
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
