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

CS19 Fall 2017

Assignment 4 (Cinco! Word Game)

Directory Name

19-4

executable Resulting from make (set in makefile)

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 list of about 2400 five letter words is provided1 (click this link to get the word list). (Every file will always have at least one legal secret word. The words will always be five letters, all lowercase, one per line.) 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.

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 filename is specified on the command line. The Dictionary class will store the words in a Set<string>. The function that selects a random word (to be the secret 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. Some of the starter code is required, and you may modify the remaining portion as directed.

What to turn in

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.

Suggestions

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

[steveh@pengo ~]$ ./p4 cinco-words.txt
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.
[steveh@pengo ~]$ 

Sample Run

[steveh@pengo ~]$ ./p4 cinco-words.txt
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.
[steveh@pengo ~]$ 

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