Question: I can't get this C + + code to provide output. The requirements are as follows: 1 . ) Break up the problem into smaller
I can't get this C code to provide output. The requirements are as follows:
Break up the problem into smaller functions and get each one working before going on to the next. Concentrate first on how to build the twodimensional array.
Make sure your output shows the by array just like the sample above
My code is listed below and a screenshot of the input file conent is attached.
#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
bool found true;
for int k ; k wordLength; k
if tableij k wordk
found false;
break;i
if found
row i;
col j;
direction "Horizontal";
return true;
Vertical search
for int i ; i SIZE wordLength; i
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 search
for int i ; i SIZE wordLength; i
for int j ; j SIZE wordLength; j
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
