In this program, you will generate different arrangements of words, also known as an…
- User
In this program, you will generate different arrangements of words, also known as an anagram. In mathematics, it is referred to as a permutation. An anagram is a word obtained by scrambling the letters of some string of characters. For example, the word "cat" is an anagram of the string "tca". This project will allow you to gain experience thinking about and writing recursive functions while creating anagrams. A sample run of the program is given below. Your output does not have to be formatted the same as the example shown but should be in a similar style. You can use words.txt as your dictionary file and anagram.cpp as an example of the main program.
Since this assignment aims to give you experience using recursion, you must not use any STL algorithms or C++'s iteration constructs (do, while, for, and goto). All repetition should be accomplished using recursion. This applies to every operation in the program, even file operations.
Sample Runs: Here are two examples of how the program might work:
Please enter a string for an anagram: tca Matching word cat Matching word act
Please enter a string for an anagram: hmmm No matches found
Requirements: You must write these three functions with the exact same function signature (include case):
int loadR(istream &dictfile, string dict[]);
Places each string in dictfile into the array dict. Returns the number of words loaded into dict. This number should not be larger than MAXDICTWORDS since that is the size of the array.
int anagramR(string word, const string dict[], int size, string results[]);
Places all the permutations of word, which are found in dict into results. Returns the number of matched words found. This number should not be larger than MAXRESULTS since that is the size of the array. The size is the number of words inside the dict array.
void printR(const string results[], int size);
Prints size number of strings from results. The results can be printed in any order.
You may find that different permutations match the same word in the dictionary for words with more than one particular letter. For example, if you find all the permutations of the string kolo using the algorithm we've discussed, you may find the word look twice. The o's in kolo take turns in front, and your program should ensure that matches are unique. In other words, the results array returned from the permuteRecur function should have no duplicates. An excellent way to test this, and your functions in general, would be to use the assert facility from the standard library. If done properly, the following code should run without generating a runtime error.
string exampleDict[] = {"kool", "moe", "dee"}; int numResults = anagramR("look", exampleDict, 3, results); assert(numResults == 1 && results[0] == "kool");You will be subject to the point deduction listed earlier if your solution uses the keywords while, for, or goto or any STL algorithm functions. You must not use global variables or variables declared with the keyword static, and you must not modify the function parameter lists. You must use the integer constants MAXRESULTS and MAXDICTWORDS, as the declared sizes of your arrays, as in the anagram.cpp example provided to you.
- Assistant