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

Code should be in C++ In this lab, you will be practicing using [ ] and indexing

ID: 3854100 • Letter: C

Question

Code should be in C++

In this lab, you will be practicing using [ ] and indexing to access individual characters in a C-string. Remember that a C-string variable is just an array of elements of type char. Use this fact to write a program that takes two words and determines if the two words are anagrams of each other or not. Two words are anagrams if they contain the same letters (include how frequent they are) only in a different order. For example These are anagrams of each other pit - tip skin kins blow - bowl alloy loyal hated - death hose shoe These are not anagrams of each other: ump pump house home hotter - tinker levels - vessel Note that your program needs to have at least one function areAnagram that takes two C- strings (the words) and passes back a boolean value of true if the two words are anagrams of each other and false if they are not anagrams Assume that the words typed only have letters (no spaces or punctuation). Let the user type in any number of words (two at a time) until they want to quit.

Explanation / Answer

The program to check the entered strings are anagram to each other are as follows.Hope you will understand the program. Here goes the program.

AnaStrings.cpp

#include <iostream>

#include <string>

using namespace std;

class AnaStrings

{

public:

bool chkAnagram(string wrd,string ana)

{

bool chkAnagram=false;

int wl=wrd.length();

int al=ana.length();

string tempo=ana.substr(0,al);

if(wl==al)

{

for(int uu=0;uu<wl;uu++)

{

int indice=tempo.find(wrd[uu]);

if(indice!=-1)

{

tempo.erase(indice,1);

}

}

if(tempo.length()==0)

{

chkAnagram=true;

}

}

return chkAnagram;

}

}

};

int main()

{

AnaStrings obj;

string wrd,ana;

cout <<endl<<" ***Anagram Checking Program*** " << endl;

cout <<"Enter the first word:";

getline(cin,wrd);

cout<<endl<<"Enter the second word:";

getline(cin,ana);

bool chkAnagram=obj.chkAnagram(wrd,ana);

if(chkAnagram)

{

cout<<endl<<"Words ""<<wrd <<"" & ""<<ana <<"" are anagram to each other"<<endl;

}

else

{

cout<<endl<<"Words ""<<wrd <<"" & ""<<ana <<"" are not anagram to each other"<<endl;

}

return 0;

}

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

Hope it helps....