Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Text is readable just zoom in on browser. Thanks some word games require rearran

ID: 3856933 • Letter: T

Question

Text is readable just zoom in on browser. Thanks

some word games 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 stringotp. 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 You can use words.txt as your dictionary file and anagram.cpo as an example of a main program. Since the purpose of this assignment is to give you experience using recursion, you may not use any of C+'teration constructs (do, while, for, and goto) or any STL algorithms (if you have no idea was this means, you're OK). All repetition must be accomplished using recursion. This applies to every operation in the program, even file operations. Obviously, you would never write a program like this in industry but as an exercise it should be useful to gain experience with 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 IOASOTISTOTOSTSOTNIININONNRONOTOTONNNM llanagram.cpp #include include #include #include using namespace std; const int MA×RESULTS -20; // Max matches that can be found const int MAXDICTWORDS 30000; I/Max words that can be read in int main() string results[MAXRESULTSI: string dict(MAXDICTWORDS] ifstream dictfile; file containing the list of words int nwords; string word; I/ number of words read from dictionary dictfile.open"words.txt if (dictfile) cout

Explanation / Answer

The required code for matching the strings for anagram is as follows:

FindingAnagrams.cpp

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main (void)
{
int io = 0, qq = 0;
int nn = 0, pp = 0;
int mtX, mtY;
int matches = 0;
ifstream if, if1;
ofstream of;
string str8, ln[1500], ln1[50];
size_t searched;

if.open ("dictionary.txt");
if1.open ("input.txt");
of.open ("output.txt");

while (if.eof() == 0)
{
getline (if, str8);
ln[io] = str8;
io++;
}

while (if1.eof() == 0)
{
getline (if1, str8);
ln1[qq] = str8;
qq++;
}

mtX = io-1;
mtY = qq-1;

for (qq = 0; qq <= mtY; qq++)
{
for (io = 0; io <= mtX; io++)
{
if (ln1[qq].length() == ln[io].length())
{
for (nn = 0; nn < ln[io].length(); nn++)
{
searched = ln1[qq].find(ln[io][nn]);
if (searched != string::npos)
{
matches++;
ln1[qq].replace(searched, 1, 1, '.');

if (matches == ln[io].length())
{
of << ln[io] << ", ";
matches = 0;
}
}
}
}
}
}

if.close();
if1.close();
of.close();

return 0;
}

Please rate the answer if it helped.....Thankyou

Hope it helps....

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote