I'm not really sure what my professor wants this character to do? This is the instructions: Write a function (countChars) that accepts a string and a character as parameters. Returns the number of times the character appears in the string
Check for anagram using the following steps
Assume you have two strings – A and B
If A is not the same length as B, not anagrams
Convert A and B to all lower case.
For each letter in A, call your countChar on A and B. If the results do not match, stop
If each letter in A returns the same number in B, then they are anagrams.
And this is what i have so far, please let me know if you understand what my professor wants me to do with this character and if you see any other errors. Thanks!~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int countChars(string a, string b, char c) {
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a == b) {
return true;
}
else {
return false;
}
}
int main() {
string a, b;
cout << "Enter a word: " << endl;
cin >> a;
cout << "Enter another word: " << endl;
cin >> b;
if (true)
{
cout << "They are anagrams of each other." << endl;
}
else
{
cout << "They are not anagrams of each other." << endl;
}
return 0;
}
|