C++ Given Code #include #include #include using namespace std; // The puzzle will always have exactly 20 columns const int numCols = 20; // Searches the entire puzzle, but may use helper functions to implement logic void searchPuzzle(const char puzzle[][numCols], const string wordBank[], vector &discovered, int numRows, int numWords); // Printer function that outputs a vector void printVector(const vector &v); // Example of one potential helper function. // bool searchPuzzleToTheRight(const char puzzle[][numCols], const string &word, // int rowStart, int colStart) int main() { int numRows, numWords; // grab the array row dimension and amount of words cin >> numRows >> numWords; // declare a 2D array char puzzle[numRows][numCols]; // TODO: fill the 2D array via input // read the puzzle in from the input file using cin // create a 1D array for wods string wordBank[numWords]; // TODO: fill the wordBank through input using cin // set up discovery vector vector discovered; // Search for Words searchPuzzle(puzzle, wordBank, discovered, numRows, numWords); // Sort the results sort(discovered.begin(), discovered.end()); // Print vector of discovered words printVector(discovered); return 0; } // TODO: implement searchPuzzle and any helper functions you want void searchPuzzle(const char puzzle[][numCols], const string wordBank[], vector &discovered, int numRows, int numWords) { } // TODO: implement printVector void printVector(const vector &v) { }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 29SA
icon
Related questions
Question

C++ Given Code

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

// The puzzle will always have exactly 20 columns
const int numCols = 20;

// Searches the entire puzzle, but may use helper functions to implement logic
void searchPuzzle(const char puzzle[][numCols], const string wordBank[],
vector <string> &discovered, int numRows, int numWords);

// Printer function that outputs a vector
void printVector(const vector <string> &v);

// Example of one potential helper function.
// bool searchPuzzleToTheRight(const char puzzle[][numCols], const string &word,
// int rowStart, int colStart)


int main()
{
int numRows, numWords;

// grab the array row dimension and amount of words
cin >> numRows >> numWords;

// declare a 2D array
char puzzle[numRows][numCols];

// TODO: fill the 2D array via input
// read the puzzle in from the input file using cin

// create a 1D array for wods
string wordBank[numWords];

// TODO: fill the wordBank through input using cin


// set up discovery vector
vector <string> discovered;

// Search for Words
searchPuzzle(puzzle, wordBank, discovered, numRows, numWords);

// Sort the results
sort(discovered.begin(), discovered.end());

// Print vector of discovered words
printVector(discovered);

return 0;
}

// TODO: implement searchPuzzle and any helper functions you want
void searchPuzzle(const char puzzle[][numCols], const string wordBank[],
vector <string> &discovered, int numRows, int numWords)
{

}

// TODO: implement printVector
void printVector(const vector <string> &v)
{

}

Word Search
A word search is often a rectangular puzzle containing a bunch of characters, when these characters are combined across rows, columns,
or diagonals then hidden words can be discovered.
Assignment Specifications
You will implement a console version of a word search puzzle solver. For this assignment, we are providing an initial source code file which
contains skeleton code that you must complete. You are not allowed to change the provided code. You must use a two-dimensional array
to store the puzzle. Grab the initial C++ file and example input file, then upload all the files to your workspace or place all of the files in the
same folder on your computer if developing locally.
For the functions you must implement, we have provided only a stub. A stub is a function definition that compiles, but does not yet
implement the complete specifications for that function. As you develop the program, you should implement each function one at a time
and test each as you go. Additionally, we encourage the development of several helper functions. These helper functions will benefit your
code organization and will more than likely help reduce the debugging time spent fixing errors in your code.
Helpful Hints
• Solve on paper first!
o record the actual steps you take to find a word
• Go through the given code first and note all the TODO comments
• Don't bite off too much, do one TODO at a time, or even break down a TODO into many steps!
• Don't implement everything at once. A search in all 8 potential directions can be confusing, try implementing search in one direction
then move on to another direction.
o If you solved on paper first, then you should know all the words and the direction for each of the discovered words.
• Print the puzzle and other arrays out to make sure you read it in correctly.
• You should be adding the words to the discovery vector as you find them.
• You only need to find a word once, so it should only exist in the discovery vector a single time.
• Use input redirection to test: /a.out < mylnputFile.txt
o You do not want to type those entire puzzles in!
• The input file and executable must be in the same directory to use the above input redirection.
• Don't wait until the last minute, zyBooks will provide a grade and limited feedback so that you can fix your problems and resubmit
prior to the deadline to earn a better grade!
Example Execution
$ ./a.out < exampleInput.txt
HELLO
Example Input File
3
2
HELLOJKLI Y Q S R P Z IM KOE
W RL DQ JKL IY QS R P Z I M KOF
BY Z ANTINE Q WERTY U IOP z
HELLO
WORLD
Transcribed Image Text:Word Search A word search is often a rectangular puzzle containing a bunch of characters, when these characters are combined across rows, columns, or diagonals then hidden words can be discovered. Assignment Specifications You will implement a console version of a word search puzzle solver. For this assignment, we are providing an initial source code file which contains skeleton code that you must complete. You are not allowed to change the provided code. You must use a two-dimensional array to store the puzzle. Grab the initial C++ file and example input file, then upload all the files to your workspace or place all of the files in the same folder on your computer if developing locally. For the functions you must implement, we have provided only a stub. A stub is a function definition that compiles, but does not yet implement the complete specifications for that function. As you develop the program, you should implement each function one at a time and test each as you go. Additionally, we encourage the development of several helper functions. These helper functions will benefit your code organization and will more than likely help reduce the debugging time spent fixing errors in your code. Helpful Hints • Solve on paper first! o record the actual steps you take to find a word • Go through the given code first and note all the TODO comments • Don't bite off too much, do one TODO at a time, or even break down a TODO into many steps! • Don't implement everything at once. A search in all 8 potential directions can be confusing, try implementing search in one direction then move on to another direction. o If you solved on paper first, then you should know all the words and the direction for each of the discovered words. • Print the puzzle and other arrays out to make sure you read it in correctly. • You should be adding the words to the discovery vector as you find them. • You only need to find a word once, so it should only exist in the discovery vector a single time. • Use input redirection to test: /a.out < mylnputFile.txt o You do not want to type those entire puzzles in! • The input file and executable must be in the same directory to use the above input redirection. • Don't wait until the last minute, zyBooks will provide a grade and limited feedback so that you can fix your problems and resubmit prior to the deadline to earn a better grade! Example Execution $ ./a.out < exampleInput.txt HELLO Example Input File 3 2 HELLOJKLI Y Q S R P Z IM KOE W RL DQ JKL IY QS R P Z I M KOF BY Z ANTINE Q WERTY U IOP z HELLO WORLD
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Map
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning