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 =8;
void readTable(std::ifstream& file, char table[SIZE][SIZE]){
for (int i =0; i SIZE; ++i){
for (int j =0; j SIZE; ++j){
file >> table[i][j];
}
}
}
bool searchWord(const char table[SIZE][SIZE], const std::string& word, int& row, int& col, std::string& direction){
int wordLength = word.length();
// Horizontal search
for (int i =0; i SIZE; ++i){
for (int j =0; j = SIZE - wordLength; ++j){// corrected loop condition
bool found = true;
for (int k =0; k wordLength; ++k){// corrected loop condition
if (table[i][j + k]!= word[k]){
found = false;
break;
}
}
if (found){
row = i;
col = j;
direction = "Horizontal";
return true;
}
}
}
// Vertical search
for (int i =0; i = SIZE - wordLength; ++i){// corrected loop condition
for (int j =0; j SIZE; ++j){
bool found = true;
for (int k =0; k wordLength; ++k){
if (table[i + k][j]!= word[k]){
found = false;
break;
}
}
if (found){
row = i;
col = j;
direction = "Vertical";
return true;
}
}
}
// Diagonal (top-left to bottom-right) search
for (int i =0; i = SIZE - wordLength; ++i){// corrected loop condition
for (int j =0; j = SIZE - wordLength; ++j){// corrected loop condition
bool found = true;
for (int k =0; k wordLength; ++k){
if (table[i + k][j + k]!= word[k]){
found = false;
break;
}
}
if (found){
row = i;
col = j;
direction = "Diagonal";
return true;
}
}
}
return false;
}
void printResults(const std::vector& words, const std::vector>& positions, const std::vector& directions){
std::cout "Word\tRow\tColumn\tDirection
";
for (size_t i =0; i words.size(); ++i){
std::cout words[i]'\t' positions[i].first '\t' positions[i].second '\t' directions[i]'
';
}
}
int main(){
std::ifstream inputFile("input.txt");
if (!inputFile){
std::cerr "Error: Unable to open input file.
";
return 1;
}
char table[SIZE][SIZE];
readTable(inputFile, table);
std::vector words;
std::string word;
while (inputFile >> word){
words.push_back(word);
}
std::vector directions;
std::vector> positions;
for (const auto& word : words){
int row, col;
std::string direction;
if (searchWord(table, word, row, col, direction)){
positions.push_back(std::make_pair(row, col));
directions.push_back(direction);
}
}
if (positions.empty()){
std::cout "Not found
";
} else {
printResults(words, positions, directions);
}
return 0;
}
I have updated my code once again to the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!