copyright Steve J. Hodges   http://steveh.net/cs19/cs19-hw04.html

CS19 Fall 2014

Assignment 4 (Cinco! Word Game)

Directory Name

19-4

Resulting Executable

p4

Program Description

In this program, you will be creating a word guessing game called Cinco. In this game, the computer will pick a (random) secret five letter word from its Dictionary. A human player guesses a word. A word is only a legal guess if it appears in the Dictionary. A word is only a legal secret word if it appears in the Dictionary and is also comprised of five different distinct letters. A word list of about 2400 five letter words is provided1 (click this link to get the word list). The file will always consist of words, one per line, in alphabetical order, all in lowercase. If the guess is correct, the computer reports how many guesses it took and the program ends. If the guess is incorrect, the computer says how many letters in the guess also exist in the secret word and how many of those letters are in the correct spot. The player then can make their next guess. If the user enters the guess of 'xxxxx' (cheat code) the program should reveal the secret word. Using the cheat code should count as a guess and should not terminate the program. (Failure to correctly implement the cheat code will result in a major point deduction!) A sample run will be provided to illustrate how your program should work.

You may either use C++ style strings or C style strings for this assignment

Any letter in your secret word should only be matched once. For example,
Secret: fable
Guess: eagle
results in 3,3 not 4,3.

This program should be constructed using two classes (plus your "main function"). One class, named Dictionary, will take care of inputting and storing the words, selecting a random word from the list, and looking up words to verify that they are in the dictionary. The words file must be named cinco-words.txt (this will allow me to easily use different files durring testing.) The function that selects a random word must not select a word with a repeated letter. (A guess may have a repeated letter.) The other class, named Cinco, will take care of the game rules, keeping track of the game state, and handling the user input and output. Some starter code is provided. Use of the provided code is optional (except for main, which is required.) You may use it as is, modify it, or discard it. If you come up with your own design, then your program architecture will be part of your overall evaluation.

Since this is a multi-file project, I will collect the directory 19-4 and all of its contents. You are required to ensure that only the necessary .h and .cpp files, a working makefile, and an optional readme.txt file are present. The binary program resulting from compiling your project should be called "p4". You will loose points if any other files are present, unless you have a 'make clean' option that removes them.

Your output must exactly match the style and formatting of the example, as the testing may be automated.

This is a program with many details. I strongly urge you to keep your program compiling and running at all stages of your project. Keep all your functions simple at first—the minimum to compile and run. Add code to one function at a time and test as you code. Have Fun!

Sample Run

CS19: Cinco! Sample Solution
by Steve J. Hodges
I'm thinking of a five letter word...
Your Guess? xyxyz
I don't know that word.
Your Guess? hello
Matching: 2
In-Place: 0
Your Guess? stove
Matching: 3
In-Place: 1
Your Guess? venom
Matching: 3
In-Place: 1
Your Guess? verse
Matching: 2
In-Place: 2
Your Guess? vague
Matching: 4
In-Place: 4
Your Guess? vogue
Correct! You got it in 6 guesses.

Sample Run

CS19 Cinco! Sample Solution
by Steve J. Hodges
I'm thinking of a five letter word...
Your Guess? draft
Matching: 2
In-Place: 1
Your Guess? xxxxx
Secret Word is: credo
Your Guess? greed
Matching: 3
In-Place: 2
Your Guess? credo
Correct! You got it in 4 guesses,
but only by cheating.

1. The file cinco-words.txt has also been copied to your home directory on Pengo.