I'm in an entry level c++ class. My professor wants us to write a array project that keep a frequency count of each of the italic alphas, also keep a frequency count of other characters entered (numbers and symbols).
The project output a frequency count of each italic alpha, and the others.
Determine which italic alpha occurred most often.
Output the stream entered in uppercase transposted form [A becomes B, B becomes C etc;].
Do not use any library functions.
He also mentions ASCII character set
I have only done the word count part, and it only count italic alpha (A-Z). It cannot count frequency of number and symbols. Can someone help me....thanks.
#include <iostream>
using namespace std;
void readAndCount (int &numWords, int letterCount[]);
void outputLetterCounts (int letterCount[]);
int main()
{
int numWords;
int letterCount[26] = {0};
cout << endl;
cout << "Enter a line of text.." << endl << endl;
readAndCount (numWords, letterCount);
cout << endl;
outputLetterCounts(letterCount);
cout << endl;
return 0;
}
void readAndCount (int &numWords, int letterCount[])
{
char character;
int lastChar = 0; //Keeps track of previous entry.
do
{
if ( !cin.get ( character ))
break;
if ( character >= 'a' && character <= 'z' )
character -= 'a' - 'A';
// Only works with upper case letters
++letterCount[character - 'A'];
lastChar=isalnum(character);
}
while ((character != '\n'));
}
void outputLetterCounts(int letterCount[])
{
for (int i = 0; i < 26; i++)
{
if (letterCount[i] > 0)
{
cout << letterCount[i] << " " << char('a' + i) << endl;
}
}
}