Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the following C++ program that searches for specified words hidden within a matrix of letters. 1) Read a file that the user specifies. The

Write the following C++ program that searches for specified words hidden within a matrix of letters.

1) Read a file that the user specifies. 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 row by row, column by column.

3) Following the rows of letters, there will be some number of words that might be hidden within the matrix. You are to search for these words and report 1) whether or not a given word is found within the matrix, and if so, the starting and ending matrix coordinates of the word.

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

5) Start by creating your own file of data. You can start with a small matrix size and your own hidden words. When youre ready, start testing one or more of the files Im going to upload for your use.

6) To test your program, I suggest searching for the first 4 letters in the top row, then the first 4 letters in the leftmost (first) column, and then the first 4 letters starting from position [0][0] down the diagonal to the right and down. That will let you know if you are traversing the matrix properly.

7) Provide for fault-tolerance when trying to open the input file. If it doesnt 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.

8) Dont report success or failure for each word as you go. Instead, report only words that are found; 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. Thus, you will have all successfully found words appear first -- along with their coordinates and (optionally) their direction -- and then the words that werent found will be listed at the end.

9) Assume that words can appear more than once in the matrix.

10) Dont worry about wrapping around the edges of the matrix. Instead, if you hit an edge while searching, assume the word isnt in the matrix.

11) Finally, add an interactive capability to your program that asks the user to enter additional words to search for in the matrix once youve searched for all words in the data file.

The following is hiddenWords.txt

15 18 SCFRBOBROBERTSLOKL TNLESREKCILSYTICRL AOEPOBLRUAECHBUDEA RITOTHEYOMTOLBATPH LCHAIBAONILLAURGEI AEKNLULDDGCISLHKLN CRRURDBHSAGTEOPLUS LOTCLULHLLBPCRAPLA UMSKIROPOULALPEAAK EHNSAHNNSTLASACCEH LSOORADTEHSHBKCROA EUOUFMEMECOHETHEER SRMPARTRBTAROSAASV SLEISTOOTHERUTLESE NATTAHNAMSEYSLSSMY

ALLOFME ANNIEHALL BABE BEINGTHERE BIG BOBROBERTS BULLDURHAM CARS CATBALLOU CITYSLICKERS MEATBALLS

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions