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 you’re ready, start testing one or more of the files I’m 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 doesn’t exist or can’t be found, tell the user. Also, tell the user the name of the file that can’t 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 system’s error message; then report your own error messages. Make sure your program can handle bad file names and/or non-existent files.
8) Don’t 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 you’ve searched for all words before reporting the words that weren’t found. Thus, you will have all successfully found words appear first -- along with their coordinates and (optionally) their direction -- and then the words that weren’t found will be listed at the end.
9) Assume that words can appear more than once in the matrix.
10) Don’t worry about wrapping around the edges of the matrix. Instead, if you hit an edge while searching, assume the word isn’t 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 you’ve 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
//Your code
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
int main(){
ifstream fout;
string line;
while(1){
printf("Enter file Name or Enter
exit to stop\n");
string st;
getline(cin,st);//reading
file
if(st == "exit")
break;
fout.open(st);
//cout<<fout<<endl;
if(!fout){//If file not
opened
perror("File Not
found\n");continue;
}else{
int
i=0,n,j,m,k;
fout>>n;
fout>>m;
cout<<n<<" "<<m<<endl;
//char c;
//fout>>c;
i=0;
string
line;
char
mat[n+1][m+1];
while(fout
&& i < n){
getline(fout,line);
if(line.size() > 0){
cout<<line<<endl;
for( j = 0 ; j < m ; j++ )
mat[i][j] = line[j];
i++;
}
}
vector<string>v_s;//to store Not found string
int ex=1;
while(ex){
if(fout){
getline(fout,line);
}else{
printf("If you want to enter
more words to search ,Enter word else Enter exit\n");
cin>>line;
if(line ==
"exit")break;
}
//cout<<line<<" ";
int fl = 0 ,l = line.size();
for( i = 0 ; i < n ; i++ ){//Searching
string
for( j = 0 ; j < m ; j++
){
fl=0;
for( k = 0
; k < l && j+k < m; k++ ){
if(mat[i][j+k] == line[k] )fl++;
else break;
}
if(fl ==
l){
i=n;j=m;break;
}
fl=0;
for( k = 0
; k < l && i+k < m; k++ ){
if(mat[i+k][j] == line[k] )fl++;
else break;
}
if(fl ==
l){
i=n;j=m;break;
}
fl=0;
for( k = 0
; k < l && j+k < m && i+k < n; k++
){
if(mat[i+k][j+k] == line[k] )fl++;
else break;
}
if(fl ==
l){
i=n;j=m;break;
}
}
}
if(fl == l && fl){//If string is
found
cout<<line<<" is
found"<<endl;
}else{
v_s.push_back(line);
}
}
printf("Not
found words are\n");
for( i = 0 ; i
< v_s.size() ; i++ )
if(v_s[i].size() > 0)
cout<<v_s[i]<<endl;
getchar();
}
}
return 0;
}
//Screenshot of editor



//Screenshot of my output terminal


//If you have any doubt.Please feel free to ask.
Thanks
Write the following C++ program that searches for specified words hidden within a matrix of letters....
Write a program that searches for specified words hidden within a matrix of letters. C++ HELP -pls keep basic as possible, thanksssss 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...
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
Write a program in C to make dictionary to add, delete and search words Using linked lists. MAKE THE SEARCHING IN THE program like the searching in the online dictionary(if we enter the 1 letter then it will show all the letters starting with the same number and if we enter 2 letters then it will show all the numbers starting with same two letters and so on up to the complete word.) make the following functions 1. insert 2....
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
Create a program that stores words in an STL vector and then searches the vector for words. Requirements You will keep track of strings as C++ string objects. In main, declare a vector variable to contain your strings. Create a loop that gets one word at a time from the user until they enter "." as the only thing on the input line. For this assignment, it is adequate to limit strings to one word at a time. Put the...
C++ PART B: (STRING) – 40% Program Description: Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should read and display each word with the count of vowels in each word. For example : The 1 Friend 2 Wrote 2 Write functions to process and display the results. No non-constant global variables should...
Write a Java program that calculates the sum of a variable sized matrix using a two dimensional array. (ArraySum.java) The user should provide the number of rows and columns Test multiple user inputs (3 times 2, 4 times 4, 6 times 2, etc) A sum should be created for each row, each column, and the total for the matrix Ex.: How big would you like your matrix? Rows - ? 3 Columns -? 2 Please enter your row 1? Column...
The picture is given in a PPM file and your program should put
the converted one into another PPM file.
•Use argv[1] for the given file and argv[2] for the converted
file.In addition, you can use a temporary file called
tmp.ppm.
•The number of rows and columns are not fixed numbers.
•The converted file should also follow the PPM format with the
above simplification, and can be converted subsequently.
•Read the pixel matrix into a buffer.
•For each row i(...
Write a C Program that finds the row totals and column totals of a Matrix. The user is prompted to enter the numbers to fill in a two-dimensional array of any size (say 3x3). The program then finds the sum of row elements and prints them along-side rows, and finds the sum of columns and prints them along-side corresponding columns. You will need nested for loops please help!