CS21 Homework 10
Due Sunday, November 16 by 11:30pm


Introduction

For this assignment, your will write a program that plays the game of Hangman. The assignment serves two purposes. First, it is designed to give you practice with characters and strings. Second, it gives you a chance to write a program that is larger than most of the programs that you have written for previous assignments. Large programs require more up-front organization than small programs, and it is important that you begin to get experience with larger programs at this point in the course. Because of the additional organizational work and the fact that there are more details to manage, I encourage you to work in teams of two for this assignment.

We will continue working on the hangman game for our next homework. Eventually, we will add in the graphics component we completed earlier in the semester and we will enhance our program so that it selects the words for the game from an encrypted file. So for this week you should focus solely on getting the basic mechanics of the game working correctly.


Sample Runs of the Game

In the sample run below, the user was able to successfully guess the secret word. Notice that the user is not allowed to guess the same letter twice and that the input character given by the user must be alphabetic. Also notice that the letters guessed so far are displayed in alphabetic order.
Let's play hangman!  I will pick a secret word.
On each turn, you guess a letter.  If the letter is
in the secret word, I will show you where it appears.
You only get 8 incorrect guesses.  Good luck.

Secret word: - - - - - - 
You have 8 guesses left.
Letters guessed: 
Your guess: e
That guess is correct.

Secret word: - E - - - - 
You have 8 guesses left.
Letters guessed: E 
Your guess: a
There are no A's in the word.

Secret word: - E - - - - 
You have 7 guesses left.
Letters guessed: A E 
Your guess: e
You already guessed E, try again.
Your guess: .
Please enter an alphabetic character.
Your guess: l
That guess is correct.

Secret word: - E L L - - 
You have 7 guesses left.
Letters guessed: A E L 
Your guess: o
That guess is correct.

Secret word: - E L L O - 
You have 7 guesses left.
Letters guessed: A E L O 
Your guess: m
That guess is correct.

Secret word: M E L L O - 
You have 7 guesses left.
Letters guessed: A E L M O 
Your guess: w
That guess is correct.

Secret word: M E L L O W 
Congratulations! You guessed the word.
And you only had 1 wrong guesses.
In the next run of the game, the user is not able to guess the secret word.
Let's play hangman!  I will pick a secret word.
On each turn, you guess a letter.  If the letter is
in the secret word, I will show you where it appears.
You only get 8 incorrect guesses.  Good luck.

Secret word: - - - - - - 
You have 8 guesses left.
Letters guessed: 
Your guess: e
That guess is correct.

Secret word: - - - - - E 
You have 8 guesses left.
Letters guessed: E 
Your guess: a
There are no A's in the word.

Secret word: - - - - - E 
You have 7 guesses left.
Letters guessed: A E 
Your guess: u
There are no U's in the word.

Secret word: - - - - - E 
You have 6 guesses left.
Letters guessed: A E U 
Your guess: o
There are no O's in the word.

Secret word: - - - - - E 
You have 5 guesses left.
Letters guessed: A E O U 
Your guess: i
That guess is correct.

Secret word: - I - - - E 
You have 5 guesses left.
Letters guessed: A E I O U 
Your guess: t
There are no T's in the word.

Secret word: - I - - - E 
You have 4 guesses left.
Letters guessed: A E I O T U 
Your guess: r
There are no R's in the word.

Secret word: - I - - - E 
You have 3 guesses left.
Letters guessed: A E I O R T U 
Your guess: f
There are no F's in the word.

Secret word: - I - - - E 
You have 2 guesses left.
Letters guessed: A E F I O R T U 
Your guess: n
There are no N's in the word.

Secret word: - I - - - E 
You have 1 guess left.
Letters guessed: A E F I N O R T U 
Your guess: y
There are no Y's in the word.

You lose! The word was: SIMPLE

Requirements


Getting Started

Don't forget to use the top-down design strategy as you build your solution to this program. Start with a very simple main program and create stub functions for each sub-task you need to perform. Gradually fill in each stub function, compiling and testing after each addition.

In order to implement a solution to this game, you must figure out how to do the following tasks:


Handing in your solution

Use cs21handin to turn in your program.