subject

So I need help writing a few functions in C++ using recursion. Some word games, like Scrabble, require rearranging a combination of letters to make a word. This type of arrangement is generally referred to as an anagram, it's known as a permutation in mathematics. This assignment will give you some experience thinking about and writing recursive functions. Write a C++ program that searches for ``anagrams'' in a dictionary. An anagram is a word obtained by scrambling the letters of some string. For example, the word ``pot'' is an anagram of the string `"otp." A sample run of the program is given below. Your output does not have to be formatted exactly the same as that shown in the sample, but should be in a similar style.

All repetition must be accomplished using recursion.

Sample Runs

Here are two examples of how the program might work:

Please enter a string for an anagram: opt
Matching word opt
Matching word pot
Matching word top

Please enter a string for an anagram: blah
No matches found
I need help writing the following functions:

int readDictionary(istream &dictfile, string dict[]);

Places each string in dictfile into the array dict. Returns the number of words read into dict. This number should not be larger than MAXDICTWORDS since that is the size of the array.

int recursivePermute(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 recurPrint(const string results[], int size);

Prints size number of strings from results. The results can be printed in any order.

For words with double letters you may find that different permutations match the same word in the dictionary. For example, if you find all the permutations of the string kloo using the algorithm we've discussed you may find that the word look is found twice. The o's in kloo take turns in front. Your program should ensure that matches are unique, in other words, the results array returned from the recursivePermute function should have no duplicates. A nice way to test this, and your function in general, might be to use the assert facility from the standard library. If done properly the following code should run without a runtime error being generated.

string exampleDict[] = {"kool", "moe", "dee"};
int numResults = recursivePermute("look", exampleDict, 3, results);
assert(numResults == 1 && results[0] == "kool");
Again, your solution must not use 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.

Basically, the dictionary we are using is a word file called words. txt and it holds 30,000 words in it, so MAXDICTWORDS = 30000 and MAXRESULTS = the max number of words that can be formed, aka 20.

This is the main function you can use:

#include
#include
#include
#include
using namespace std;

const int MAXRESULTS = 20; // Max matches that can be found
const int MAXDICTWORDS = 30000; // Max words that can be read in

int main()
{
string results[MAXRESULTS];
string dict[MAXDICTWORDS];
ifstream dictfile; // file containing the list of words
int nwords; // number of words read from dictionary
string word;

dictfile. open("words. txt");
if (!dictfile) {
cout << "File not found!" << endl;
return (1);
}

nwords = readDictionary(dictfile, dict);

cout << "Please enter a string for an anagram: ";
cin >> word;

int numMatches = recursivePermute(word, dict, nwords, results);
if (!numMatches)
cout << "No matches found" << endl;
else
recurPrint(results, numMatches);
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:20
This problem has been solved! see the answeran evil king has a cellar containing n bottles of expensive wine, and his guards have just caught a spy trying to poison the king’s wine. fortunately, the guards caught the spy after he succeeded in poisoning only one bottle. unfortunately, they don’t know which one. to make matters worse, the poison the spy used was very deadly; just one drop diluted even a billion to one will still kill someone. even so, the poison works slowly; it takes a full month for the person to die. design a scheme that allows the evil king to determine exactly which one of his wine bottles was poisoned in just one month’s time while expending at most o(logn) of his taste testers.you are not allowed to use n testers, one for each bottle, and see which one tester dies after 30 days.(no pseudocode needed. just answer in words, how many testers you use, how you use them and why you correctly identify the poisoned bottle in 30 days)
Answers: 2
question
Computers and Technology, 22.06.2019 01:00
What can you find the under the privacy policy section of a shopping website?
Answers: 1
question
Computers and Technology, 23.06.2019 04:20
4. a1. vince owns a television repair shop that is insured undera commercial package policy. the policy includes thebuilding and personal property coverage form and thecauses-of-loss broad form. the declarations page indicatesthat coverage applies to both the building and the namedinsured's business property. explain whether or not thefollowing losses would be covered under his policy.a. a fire occurs on the premises, and the building isbadly damaged.b. a burglar steals some money and securities from anunlocked safe.c. a business computer is damaged by vandals whobreak into the shop after business hours.d. a tornado touches down near the store. several tel-evision sets of customers in the shop for repair aredamaged in the storm.til
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
You know the right answer?
So I need help writing a few functions in C++ using recursion. Some word games, like Scrabble, requ...
Questions
question
English, 23.02.2021 22:20
question
Mathematics, 23.02.2021 22:20
question
Mathematics, 23.02.2021 22:20
question
Biology, 23.02.2021 22:20
question
History, 23.02.2021 22:20
question
Mathematics, 23.02.2021 22:20
question
Chemistry, 23.02.2021 22:20
question
History, 23.02.2021 22:20
Questions on the website: 13722367