I'm creating a class for a text analysis for letter frequency.
I am trying to compile it, but i'm having some problems. Could someone look at this for me?
This is what I have so far:
class Analysis
{
private:
string letters[26];
string text;
int count;
public:
Analysis()
{
string letters[26] = {0};
string text = 0;
int count = 0;
}
Analysis (string l, string t, int c)
{
letters[26] = l;
text = t;
count = c;
}
void set(string l, string t, int c)
{
letters[26] = l;
text = t;
count = c;
}
string getLetters()
{
return letters;
}
string getText()
{
return text;
}
int getCount()
{
return count;
}
void display_text() //displays text
{
int max;
string text;
cout << " Enter text here: " << endl;
getline(cin, text);
max = text.length();
}
int strfreq (string str, string subs) //count and return how many times substring appears in text
{
int ct = 0, pos=0;
pos = str.find(subs, pos);
while (pos != -1)
{
ct++;
pos = str.find(subs, pos + 1);
}
return ct;
}
int letterfreq ()
{
int letters[26];
int count[26];
for(int i = 0; i < 26; i++)
{
letters[i] = 0;
count[i] = 0;
}
}
};
int main()
{
char ans;
do
{
Analysis wor;
char ans;
wor.display_text();
cout << endl;
wor.set(letters, text, count);
wor.letterfreq ();
cout << " Do you want to continue? (Y/N) " << endl;
cin >> ans;
cin.ignore();
} while (toupper(ans) == 'Y');
cout << setprecision(2) << fixed;
for(i = 0; i < 26; i++)
cout << setw(6) << (i + ('A')) << setw(6) << count[i] << setw(6) << letters[i] << endl;
system("PAUSE");
return 0;
}