Question
THIS IS THE TEXT FILE # Here is the complete word search puzzle for the # Comedy Movies puzzle. Note that it is larger than
THIS IS THE TEXT FILE
# Here is the complete word search puzzle for the # Comedy Movies puzzle. Note that it is larger than # the file I distributed with the homework assignment, # so you should be able to find many more movies in this one. # You might test this file with your homework to see # what results you get. I believe you should find every # movie except for the last one, "zzzz." That one is # in there just for test purposes to see what your program # does when it can't find a particular movie. #rows X cols 18 18 #the matrix SCFRBOBROBERTSLOKL TNLESREKCILSYTICRL AOEPOBLRUAECHBUDEA RITOTHEYOMTOLBATPH LTCMWRGIFMLBEEIBEE LCHAIBAONILLAURGEI AEKNLULDDGCISLHKLN MLCTILLAINTAGOLHSN AEUDALYCUNZHSYLOSA CRRURDBHSAGTEOPLUS LOTCLULHLLBPCRAPLA UMSKIROPOULALPEAAK EHNSAHNNSTLASACCEH LSOORADTEHSHBKCROA EUOUFMEMECOHETHEER SRMPARTRBTAROSAASV SLEISTOOTHERUTLESE NATTAHNAMSEYSLSSMY #Movie Titles to Search For ALL OF ME ANNIE HALL BABE BEING THERE BIG BOB ROBERTS BULL DURHAM CARS CATBALLOU CITYSLICKERS CLERKS CLUELESS DUCK SOUP ELECTION FLETCH GHOSTBUSTERS HAPPY GILMORE HARVEY HOLIDAY HOTSHOTS LEGALLY BLONDE LIAR LIAR LOCAL HERO MALLRATS MANHATTAN MEATBALLS MOONSTRUCK NAPOLEAN DYNAMITE OH GOD PLAZA SUITE RAISING ARIZONA REPO MAN RUSHMORE #note that I can have comments anywhere in the data file SHREK SLACKER SLAP SHOT SLEEPER THE RUTLES TOOTSIE TRADING PLACES UNCLE BUCK YES MAN #And here's one little palindrome for testing. #It's a movie title not of a comedy but of a very famous #robot movie. Your program might find it twice depending... RUR
THIS IS MY CODE (it does the word search, not the ppm)
/* Wordsearch */ #include #include #include #include #include using namespace std;
//Constants
const int MAX_ROW_SIZE = 100, MAX_COLUMN_SIZE = 100; const int MAX_NUM_WORDS = 100;
//Function Prototypes
bool checkForRestOfWord(char[MAX_ROW_SIZE][MAX_COLUMN_SIZE], string, int, int, int, int); bool checkIfWordCanFit(int, int, int, int, int, int, int, string); string deleteSpaces(string); void wordDirection (int, int); void displaymatrix(char[MAX_ROW_SIZE][MAX_COLUMN_SIZE], int, int); void displayWordsNotFound(vector&); bool findDirectionOfWord(char [MAX_ROW_SIZE][MAX_COLUMN_SIZE], string, string, int, int, int , int); void getMatrixSize(ifstream&, int&, int&, bool&); void ignoreCommentsAndBlanks(ifstream&); bool openFileForReading(ifstream&, string&); void readMatrixFromFile(ifstream&, char[MAX_ROW_SIZE][MAX_COLUMN_SIZE], int, int); void readWordBankFromFile(ifstream&, string[MAX_NUM_WORDS], string[MAX_NUM_WORDS], int&); void searchForWords(char[MAX_ROW_SIZE][MAX_COLUMN_SIZE], string[MAX_NUM_WORDS], string[MAX_NUM_WORDS], vector&,int, int, int);
int main() { string fileName; ifstream inFile;
char matrix[MAX_ROW_SIZE][MAX_COLUMN_SIZE]; int rows, columns; bool isMatrixToWide = false;
string wordBankNoSpaces[MAX_NUM_WORDS], wordBankWithSpaces[MAX_NUM_WORDS]; int numWords = 0;
vector wordsNotFound;
if (openFileForReading(inFile, fileName)) { getMatrixSize(inFile, rows, columns, isMatrixToWide); if (!isMatrixToWide) { readMatrixFromFile(inFile, matrix, rows, columns); displaymatrix(matrix, rows, columns); readWordBankFromFile(inFile, wordBankNoSpaces, wordBankWithSpaces, numWords); searchForWords(matrix, wordBankNoSpaces, wordBankWithSpaces, wordsNotFound, rows, columns, numWords); displayWordsNotFound(wordsNotFound); } else { cout
bool checkForRestOfWord(char matrix[MAX_ROW_SIZE][MAX_COLUMN_SIZE], string word, int firstLetterRow, int firstLetterColumn, int yDirection, int xDirection) { bool restOfWordWasFound = true; for (int letter = 1; letter
bool checkIfWordCanFit(int wordLength, int rows, int columns, int firstLetterRow, int firstLetterColumn, int y, int x, string word) { bool wordCanFit = true;
if (((firstLetterRow + (y * wordLength)) rows)) {
wordCanFit = false; } else if (((firstLetterColumn + (x * wordLength)) columns)) {
wordCanFit = false; }
return wordCanFit; }
string deleteSpaces(string line) { for (int stringposition = 0; stringposition
void wordDirection (int horizontalDirection, int verticalDirection) { string cardinalDirections[3][3] = { {"NW", "W", "SW"}, {"N", "no direction", "S"}, {"NE", "E", "SE"} }; int horizontalDirectionArrayPointer = horizontalDirection + 1; int verticalDirectionArrayPointer = verticalDirection + 1; cout
void displayLocationOfWord(string word, int row, int column) { cout
void displaymatrix(char matrix[MAX_ROW_SIZE][MAX_COLUMN_SIZE], int rows, int columns) { cout
}
void displayWordsNotFound(vector & wordsNotFound) { cout
bool findDirectionOfWord(char matrix[MAX_ROW_SIZE][MAX_COLUMN_SIZE], string word, string wordWithSpaces, int firstLetterRow, int firstLetterColumn, int rows, int columns) { bool restOfWordWasFound = false; for (int x = -1; x
void getMatrixSize(ifstream& inFile, int& rows, int& columns, bool& isMatrixToWide) { ignoreCommentsAndBlanks(inFile); inFile >> rows >> columns;
if ((rows > MAX_ROW_SIZE) || (columns > MAX_COLUMN_SIZE)) { cout
void ignoreCommentsAndBlanks(ifstream& inFile) { string textLine; char ch; ch = inFile.peek(); while (ch == '#' || ch == ' ') { getline(inFile, textLine); ch = inFile.peek(); } }
bool openFileForReading(ifstream& inFile, string& fileName) { cout
return openFileForReading(inFile, fileName); } else { cout
void readMatrixFromFile(ifstream& inFile, char matrix[MAX_ROW_SIZE][MAX_COLUMN_SIZE], int rows, int columns) { ignoreCommentsAndBlanks(inFile); string line; for (int row = 0; row
void readWordBankFromFile(ifstream& inFile, string wordBankNoSpaces[MAX_NUM_WORDS], string wordBankWithSpaces[MAX_NUM_WORDS], int& numWords) { ignoreCommentsAndBlanks(inFile); string line; while(getline(inFile, line)) { wordBankWithSpaces[numWords] = line; wordBankNoSpaces[numWords] = deleteSpaces(line); numWords++; ignoreCommentsAndBlanks(inFile); } }
void searchForWords(char matrix[MAX_ROW_SIZE][MAX_COLUMN_SIZE], string wordBankNoSpaces[MAX_NUM_WORDS], string wordBankWithSpaces[MAX_NUM_WORDS], vector& wordsNotFound, int rows, int columns, int numWords){ bool wordWasFound; for (int word = 0; word First, recall how we make PPM files. The challenge here is to produce a PPM file of the results of your word-search program. (Comedy Movies-FINAL.txt) The PPM file should show which character cells contain letters that are part of a hidden word/movie. Here is an example of what your PPM file might look like. In the following figure, the colored cells show the movies I found, but only when searching for a few of the movies, not all of them (Comedy Movies-partial.txt, I think). And here's one that includes all the movies in the data file: In the both the above PPM files, I used only 5 different, distinct colors, but I clearly could have used more, even many more. To create such PPM files, what you will need to do is determine a way to record where you find hidden words in your main program; you will need starting cell indices, length of the hidden word, and direction of the hidden word. With that information, you can record in a second array - called perhaps something like PPMfoundArray -- which cells contain parts of a hidden word. Then from that array, you should be able to create a PPM output file of your own design. That is your main challenge. For additional challenges, try to come up with a variety of coloring schemes. For example, you coloring scheme could be based on 1. A random color for each movie. 2. The length of a hidden word (longer movies would be in different colors) 3. The length of a hidden word (longer words would have greater color saturations) 4. The direction of a hidden word (one color for each different direction). 5. The number of times a cell participates in hidden words (the more, the brighter/different the color) First, recall how we make PPM files. The challenge here is to produce a PPM file of the results of your word-search program. (Comedy Movies-FINAL.txt) The PPM file should show which character cells contain letters that are part of a hidden word/movie. Here is an example of what your PPM file might look like. In the following figure, the colored cells show the movies I found, but only when searching for a few of the movies, not all of them (Comedy Movies-partial.txt, I think). And here's one that includes all the movies in the data file: In the both the above PPM files, I used only 5 different, distinct colors, but I clearly could have used more, even many more. To create such PPM files, what you will need to do is determine a way to record where you find hidden words in your main program; you will need starting cell indices, length of the hidden word, and direction of the hidden word. With that information, you can record in a second array - called perhaps something like PPMfoundArray -- which cells contain parts of a hidden word. Then from that array, you should be able to create a PPM output file of your own design. That is your main challenge. For additional challenges, try to come up with a variety of coloring schemes. For example, you coloring scheme could be based on 1. A random color for each movie. 2. The length of a hidden word (longer movies would be in different colors) 3. The length of a hidden word (longer words would have greater color saturations) 4. The direction of a hidden word (one color for each different direction). 5. The number of times a cell participates in hidden words (the more, the brighter/different the color)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started