Objective:

Write a program that searches for specified words hidden within a matrix of letters.

1. Ask the user for the name and location of a file to read; this file will contain the Word Search puzzle. Read the file. The may contain comments lines (they will start with a # symbol), data lines, and blank lines. The data in the file will first specify the dimensions of the matrix (e.g., 20 30). These two numbers specify the number of rows in the matrix and then the number of columns in the matrix.

2. Following these two numbers, there will be a number of rows of letters. These letters should be read into your matrix (a 2D array of chars) row by row, column by column.

3. Following the rows of letters, there will be some number of words/phrases that might or might not be hidden within the matrix. You are to search for these words/phrases and report 1) whether or not a given word/phrase is found within the matrix, and if so, 2) the starting coordinates of the word/phrase and the direction in which you found it, e.g., N, NW, SE, etc.

4. Search for each word (name, title, phrase, etc.) one at a time (i.e., read a word/phrase, search for it, report the results, and then read the next word/phrase from the file). Continue until all words/phrases have been searched for and reported.

5. You might want to start by creating your own file of data. You can start with a small matrix size (say 5x5) and your own hidden words. When you're ready, start testing one or more of the files Im going to upload to eLearning for your use. I suggest starting with the Comedy Movies puzzle called ComedyMovies-partial.txt. Once you can process this puzzle correctly, you can try other hidden- word puzzles.

6. Provide for fault-tolerance when trying to open the input file. If it doesn't exist or cant be found, tell the user. Also, tell the user the name of the file that cant be found/opened. Then give the user a chance to enter another file name and try to open that file. Continue until you either find and open the file or until the user types something like "quit" or exit. If you feel comfortable doing so, use the perror function to report the systems error message; then report your own error messages. Make sure your program can handle bad file names and/or non- existent files.

7. Don't report success or failure for each word as you go. Instead, report only words that are found, their locations, and their directions; but for words that are not found, shove them into a vector of strings and wait until youve searched for all words before reporting the words that werent found and then finally quitting. Thus, you will have all successfully found words appear first -- along with their coordinates and their direction -- and then the words that werent found will be listed at the end.

8. Report the indices where movies are found in human-speak, not C/C++ speak. (See the example output at the end of this file. Don't report coordinates using 0-based index numbers.)

9. Assume that words/phrases can appear more than once in the matrix; so you may find and report on a given word more than once.

10. Don't wrap around the edges of the matrix. Instead, if you hit an edge while searching, assume the word isnt in the matrix. To be extra clever, you could also check for length issues before searching in a given direction if you want to, or you can start traversing a direction and check for out-of- bounds errors as you go; either way works fine, but the first way is a bit cleverer. IF you use that method, please, please make a note of this in your header comments in the source file.

11. You could add a Boolean variable that controls whether you search for multiple or just single occurrences within the matrix. This is optional, but please consider adding it. Set it to multiple for your final run and for the output you submit to eLearning.

12. For extra fun, consider adding an interactive capability to your program that asks the user to enter additional words to search for in the matrix once you've searched for all words in the data file.

Annotations for the code:

1. The main function can be at either the beginning or the end of the program. I don't care which.

2. Add comments at the top of your program file to include your name, the name of the program, and any relevant notes on how your design works when executed.

3. Add a change log in your comments as you go that lists the major changes you make to your logic and when - nothing too terribly detailed, but a list of breadcrumbs that will remind you and others of what you've done as your program becomes more sophisticated and/or nearly complete.

4. Point out (in the comments at the top of your program) any special features or techniques you added using a comment saying something like "// Special Features:"

5. Comment your code effectively, as we discussed in class. Use descriptive variable names everywhere so that the code becomes as self-documenting as possible. Use additional commentary only to improve readability and comprehensibility by other people. No fluff!

6. You absolutely MUST use consistent indentation and coding styles throughout the program. Failure to do so will result in a loss of 5 points.

7. If the program does not work at all, or works incorrectly, at least 10 points will be deducted. So you must find every word that is in the matrix and must report all words that are NOT in the matrix. The starting coordinates and direction must also be correct.

Example output:

Oops, can't open the specified input file: No such file or directory
The file name used was: I_Dont_Exist.txt
Enter another file name to use (or quit): comedymovies-final.txt
--- The new file name is: comedymovies-final.txt

Nbr Rows: 18; Nbr Cols: 18
SCFRBOBROBERTSLOKL
TNLESREKCILSYTICRL
AOEPOBLRUAECHBUDEA
RITOTHEYOMTOLBATPH
LTCMWRGIFMLBEEIBEE
LCHAIBAONILLAURGEI
AEKNLULDDGCISLHKLN
MLCTILLAINTAGOLHSN
AEUDALYCUNZHSYLOSA
CRRURDBHSAGTEOPLUS
LOTCLULHLLBPCRAPLA
UMSKIROPOULALPEAAK
EHNSAHNNSTLASACCEH
LSOORADTEHSHBKCROA
EUOUFMEMECOHETHEER
SRMPARTRBTAROSAASV
SLEISTOOTHERUTLESE
NATTAHNAMSEYSLSSMY

ALL OF ME found at 9, 5: (direction = NE)
ANNIE HALL found at 9, 18: (direction = N)
BABE found at 3, 14: (direction = SE)
BEING THERE found at 3, 6: (direction = SE)
BIG found at 4, 14: (direction = SE)
BOB ROBERTS found at 1, 5: (direction = E)
.
.
.
UNCLE BUCK found at 9, 9: (direction = NE)
YES MAN found at 18, 12: (direction = W)
RUR found at 10, 3: (direction = E)
RUR found at 10, 5: (direction = W)

Couldn't find these movies:
Zzzz

[and maybe others!]
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.