Question: I have updated my code once again to the recommended corrections but I am still getting the same Not Found result as before. The updated
I have updated my code once again to the recommended corrections but I am still getting the same Not Found result as before. The updated code is below as well as a screenshot of the input.txt file:
#include
#include
#include
#include
const int SIZE ;
void readTablestd::ifstream& file, char tableSIZESIZE
for int i ; i SIZE; i
for int j ; j SIZE; j
file tableij;
bool searchWordconst char tableSIZESIZE const std::string& word, int& row, int& col, std::string& direction
int wordLength word.length;
Horizontal search
for int i ; i SIZE; i
for int j ; j SIZE wordLength; j corrected loop condition
bool found true;
for int k ; k wordLength; k corrected loop condition
if tableij k wordk
found false;
break;
if found
row i;
col j;
direction "Horizontal";
return true;
Vertical search
for int i ; i SIZE wordLength; i corrected loop condition
for int j ; j SIZE; j
bool found true;
for int k ; k wordLength; k
if tablei kj wordk
found false;
break;
if found
row i;
col j;
direction "Vertical";
return true;
Diagonal topleft to bottomright search
for int i ; i SIZE wordLength; i corrected loop condition
for int j ; j SIZE wordLength; j corrected loop condition
bool found true;
for int k ; k wordLength; k
if tablei kj k wordk
found false;
break;
if found
row i;
col j;
direction "Diagonal";
return true;
return false;
void printResultsconst std::vector& words, const std::vector& positions, const std::vector& directions
std::cout "WordtRowtColumntDirection
;
for sizet i ; i words.size; i
std::cout wordsit positionsifirst t positionsisecond t directionsi
;
int main
std::ifstream inputFileinputtxt;
if inputFile
std::cerr "Error: Unable to open input file.
;
return ;
char tableSIZESIZE;
readTableinputFile table;
std::vector words;
std::string word;
while inputFile word
words.pushbackword;
std::vector directions;
std::vector positions;
for const auto& word : words
int row, col;
std::string direction;
if searchWordtable word, row, col, direction
positions.pushbackstd::makepairrow col;
directions.pushbackdirection;
if positionsempty
std::cout "Not found
;
else
printResultswords positions, directions;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
