Lab 8: Word Guess

This assignment assumes that you have read up through Chapter 8 (Strings). Please bring your book to lab, as you will need it as a reference. Each lab assignment is more work than the previous one, so get started early.

The objectives for this assignment are for you to:

  • Demonstrate an understanding of strings as a special case of arrays.
  • Learn how to use the string handling functions in the standard library.
  • Get even more practice in decomposing programs into small functions.
  • Getting Started

    As in the previous lab, start by creating a directory just for this assignment, and changing to that directory:
    mkdir cse20211/lab8
    cd cse20211/lab8
    

    Word Guess

    Write a program (guess.c) that plays a word guessing game as follows.

    At the beginning of the game, the program should select a word from a list of 10 (or more) secret words, ranging in length from 5 to 12 letters. On each turn, print out the word, but substitute an asterisk for the letters not yet guessed. The player can guess either a single letter, or guess the entire word. If a correct letter is guessed, indicate how many times it appears in the word, and update the display. If a correct word is guessed, display it, and the game is over. The player wins by either revealing all of the letters, or by guessing the whole world in 10 or fewer turns. When the game ends, ask if the player would like to play again.

    Here is an example game:

    * * * * * * * *
    Guess a letter or the word:
    b
    
    Good guess!
    There are 2 Bs in the word.
    9 guesses left.
    
    B * * * B * * *
    Guess a letter or the word:
    Q
    
    Sorry, there are no Qs in this word.
    8 guesses left.
    
    B * * * B * * *
    Guess a letter or the word:
    5
    
    5 is not a letter at all!
    7 guesses left.
    
    B * * * B * * *
    Guess a letter or the word:
    
    Sorry, the secret word is not basebomb.
    6 guesses left.
    
    B * * * B * * *
    Guess a letter or the word:
    l
    
    Good guess!  There are 2 Ls in the word.
    5 guesses left.
    
    B * * * B * L L
    Guess a letter or the word:
    BaseBall
    
    Correct: the secret word is BASEBALL!
    
    Would you like to play again? (yes/no)
    yes
    
    * * * * *
    Guess a letter or the word:
    ...
    
    Be sure that your program handles the following boundary conditions:
  • Only alphabetic guesses are allowed.
  • The user may type either a letter or a word at the prompt, and the program should determine whether it is a letter guess or a word guess.
  • Accept either upper or lower case letters for all guesses.
  • The game may end if the user guesses the word, if the user runs out of guesses, or if the user guesses all letters in the word.
  • To avoid array overruns, define a maximum word length in a global constant, and use it throughout the program.
  • Hints:
  • Review the functions in ctype.h for converting between upper and lower characters.
  • Review the functions in string.h for comparing, copying, and modifying strings.
  • Divide your program into several short functions that each do simple things.
  • Turning In

    Please review the general instructions for lab reports.

    Turn in guess.c and report.txt. Your lab report should cover the assignment, explaning how it works from the user perspective, how the program works internally, and how you verified that the output of the program is correct.

    Turning In

    This assignment is due on Monday, November 7th at noon. Late assignments are not accepted.