CSCI 261 - Programming Concepts (C++)

Spring 2018 - Assignment 4 - Hangman

Quick Links: Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This assignment is due by Thursday, March 1, 2018 11:59 PM.

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:

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: P R O _ R A M M I N _
Your guess: g
There's a G!
CONGRATS! You solved the puzzle: P R O G R A M M I N G

An example of a losing game:

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: q
Sorry, no Q's. You have 5 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!


Hints



  • You are going to need to use multiple arrays. These arrays correspond to:
    1. The secret word that is being guessed.
    2. The "current board" of letters the user has found.
    3. 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 char depending on your implementation.

  • You'll need loops in multiple places:
    1. Continue asking the user for letters until solved or out of guesses
    2. Printing the current puzzle
    3. Checking if the letter exists in the puzzle
    4. 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.


Grading Rubric


Your submission will be graded according to the following rubric.

Points Requirement Description
2 All code submitted properly
10 Labs completed
2 Autograder Tests Passed
8 Game is properly playable
8 Functional requirements met above
2 (1) Comments used (2) Coding style followed (3) Appropriate variable names, constants, and data types used (4) Instructions followed
32 Total Points


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.

From your Cloud9 workspace, right click on the Set4 folder in your workspace tree. Select "Download" from the pop-up menu. This will download a file called Set4.zip to your computer. It contains all the files of your Set4 folder (therefore L4A, L4B, L4C, L4D, L4E, A4).

Now in Canvas, go to Assignments > Set4. Upload your Set4.zip file you just downloaded. And voila! Easy peasy.

In summary, follow these specific steps:
  • right click on the Set4 folder in Cloud9.
  • select "Download" from the pop-up menu.
  • upload the Set4.zip file to Canvas Set4.
  • after you submit, download the file and double check it contains all that you think it contains!


This assignment is due by Thursday, March 1, 2018 11:59 PM.
Last Updated: 02/15/18 13:06


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0