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, 23.06.2019 01:50
Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: a. double the number. b. reverse the digits of the number. c. raise the number to the power of 2, 3, or 4. d. sum the digits of the number. e. if the number is a two-digit number, then raise the first digit to the power of the second digit. f. if the number is a three-digit number and the last digit is less than or equal to 4, then raise the first two digits to the power of the last digit. after performing an operation if the number is less than 10, add 10 to the number. also, after each operation determine if the number is prime. each successive operation should be performed on the number generated by the last operation. your program should not contain any global variables and each of these operations must be implemented by a separate function. also, your program should be menu driven. 7. (fraction calculator) write a program that
Answers: 1
question
Computers and Technology, 23.06.2019 07:30
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
question
Computers and Technology, 23.06.2019 16:10
What is the ooh? a. omaha occupation handbook b. online occupational c. occupations online d. occupational outlook handbook select the best answer from the choices provided
Answers: 3
question
Computers and Technology, 25.06.2019 06:00
Write a method public static string getdigits(string phonenumber) that takes an 11-character phone number written with any combination of 11 uppercase letters, lowercase letters and/or digits, and zero or more hyphens, and which returns the digits that a person would have to press on a cell phone to dial that phone number. we will use the mapping of letters to digits given at en.wikipedia.org/wiki/telephone_keypad# /media/file: telephone-keypad2.svg you may assume that the string parameter phonenumber contains some combination of exactly 11 uppercase letters, lowercase letters and/or digits, but that any number of hyphens may be present. you can assume that a hyphen will not appear as the first or last character of the string. do not assum
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, 09.01.2020 00:31
question
Computers and Technology, 09.01.2020 00:31
Questions on the website: 13722362