bool isValid(string, string); void ladder(string, int, bool&); bool isRepeated(string); void remove(string); bool allLetter(string); int main(int argc, char **argv) { - exit if no file is provided in command line bool bitmap[26][26][26][26]; vector<string> words; /* the solution vector */ int i, i2, i3, i4, transition; ifstream fin; string word; bool success; - initialize the random number generator - open the given file and use a 4-dimensional bool array to store valid words - prompt the user to enter a valid ladder size - use a while loop to find a word ladder of that size given the beginning and destination words if found, break the while loop and start the game if not found, issue an error message and exit - start the game by having the user input the intermediate words in the word ladder, given the beginning and destination words - make sure at each stage the user enters a valid word; if not, have him or her enter again - output results depending on how the user did } /* precondition: first and second must consist of only letters and must be of length 4 postcondition: return true if transition from first to second is valid and second is a word in the word list */ bool isValid(string first, string second) { - same } /* precondition: success should be false in the first function call t should be >= 1 w must be a 4-letter string postcondition: success is set true if the word ladder has been found */ void ladder(string w, int t, bool & success) { - put w into the solution vector - if t is 0, set success to true and return - iterate from ‘a’ through ‘z’ in the first letter of w if the new word is a valid word and is not in the solution vector, that means this is a valid word in the ladder; call ladder recursively with this new word if success is false, pop out the word at the back of the solution vector - iterate from ‘a’ through ‘z’ in the second letter of w if the new word is a valid word and is not in the solution vector, that means this is a valid word in the ladder; call ladder recursively with this new word if success is false, pop out the word at the back of the solution vector - iterate from ‘a’ through ‘z’ in the third letter of w if the new word is a valid word and is not in the solution vector, that means this is a valid word in the ladder; call ladder recursively with this new word if success is false, pop out the word at the back of the solution vector - iterate from ‘a’ through ‘z’ in the fourth letter of w if the new word is a valid word and is not in the solution vector, that means this is a valid word in the ladder; call ladder recursively with this new word if success is false, pop out the word at the back of the solution vector } /* precondition: w can be any string postcondition: return true if w is in the word list; return false otherwise */ bool isRepeated(string w) { - same } /* precondition: w can be any string postcondition: remove w from the word list */ void remove(string w) { - same } /* precondition: w must be a 4-character string postcondition: return true if w is alphabetic; return false otherwise */ bool allLetter(string w) { - same }Let's look at the next step!◀ Solving Word Ladder Game - Step 1▶ Solving Word Ladder Game - Step 3