Please read the remarks about programming problems for this course.
A word search puzzle consists of words hidden in a rectangular block of random characters. You will complete a C++ program to produce such a puzzle.
The word search program you are to complete consists of six C++ files, found here:
main
function and a function that
reads the list of words from a text file and inserts
them into a C++ std::vector
. The code
in this file loads the words, builds the key and puzzle,
and prints the key and puzzle.
You should not modify this file.
LetterMatrix
, which represents a
two-dimensional vector of characters.
A word search puzzle and its key will be a
LetterMatrix
.
Additionally, this file provides the declaration of
several overloaded operators that work with
LetterMatrix
objects.
This type provided as a convenience to simplify the code
you need to write.
You should not modify this file.
make_key
and make_puzzle
functions.
You are encouraged to add helper functions to assist these
two functions.
As you can see, you first create a random number generator object, specifying its range of values in the construction. Afterward when you need a pseudorandom number, you simply "call" the object like a function. Every time you "call" the object it will return the next pseudorandom integer in its sequence.
These files constitute a C++ project that will build and run. The
make_key
and make_puzzle
functions are
stubs that contain no useful code; you will replace their contents
with your code. Complete make_key
first; it fills a
puzzle with space characters (' '
) and then inserts
the words. After that, the make_puzzle
function is
easy—it simply makes a copy of the key and then replaces
all the remaining empty spaces with random characters.
You should study all the code provided, especially the code that reads data from a text file and the overloaded operator functions. You may need to write similar code yourself in the future.
The program reads the list of words from a text file named wordlist.txt. The file should contain ten words, each on its own line. No word will contain more than 15 letters.
The program places the words in a 20 x 20 block filled with random letters.
Your code should place the words randomly in different several ways:
You can simplify this process by computing a random row, column starting
location for the first letter in the word and then computing a random
row change, column change vector (the term vector is used
here
in the mathematical sense, not the C++ std::vector
data structure sense). This vector then can take care of
both the orientation and forwards/backwards direction.
Using randomness in this way means you should not determine ahead of time how many words are printed backwards or diagonally, etc. Since the placement is done entirely at random, some puzzles, although rare, may contain no diagonally-placed words, or no backwards words; however, multiple runs of your program over the same list of words must clearly demonstrate that your program satisfies all the requirements listed in this specification.
Another use of randomness is in the selection of letters to fill in around the words to hide; they too should be chosen at random and not predetermined.
Your program should be able to handle correctly words that overlap, such as:
R O S T A T I C D C E E V I C E
Notice how DEVICE and VECTOR overlap at V, and STATIC and VECTOR overlap at T. Such overlap is not common via purely random placement, so you may need to run your programs multiple times to demonstrate this capability.
The words in the file may may consist of both upper- and lowercase alphabetic letters, but the program capitalizes all the letters in a word before using them in the puzzle.
The program produces the following output, in the following order:
Here is the output of a sample run.
You have only two functions to write, but there is a lot of other code involved that you need to understand. You have one week to complete the assignment, but most students will want to set aside a few hours over several days to complete the assignment. The following represents a reasonable time schedule for this assignment:
Submit your completed wordsearch.cpp C++ source file to http://eclass.e.southern.edu. Be sure your name appears within a comment as the first line in each source file you submit.