Hello all,
This is my very first assignment using classes, and I am having a wee bit of a problem with it. I do not want you to correct the code but if if you could point me in the right direction I would appreciate the help.
The assignment involves "writing a C++ class to calculate the frequency of letters, number of vowels, number of uppercase letters and number of lower case letters in a word. Prompt the user to enter a word up to 10 characters and display the frequency of each of the letters, number of vowels, number of uppercase letters and number of lower case letters in that word."
By the way I am using Bloodshed DevC++ v.4.9.9.2
Basically I want to call a simple function that will not return any values but will simply print the frequency of letters to the screen (everything else prior to that works fine by the way).
Here is my code thus far;
Now at the moment I am stuck because the program will not compile. It is giving this lone error;Code:#include <iostream> #include <cctype> // Not sure if this is really needed here #include <string> using namespace std; class Word // Declaring the class object { public: char WordArray[25]; // Public member function void FrequencyOfLetters(); //--------------------------------------------------- // Function to calculate number of uppercase letters //--------------------------------------------------- unsigned int NumberOfUppercase() { int i,UppercaseTotal; int size = strlen(WordArray); for(int i=0; i<size; i++) { if (isupper(WordArray[i])) UppercaseTotal++; } return UppercaseTotal; } //---------------------------------------------------- // Function to calculate number of lowercase letters //---------------------------------------------------- unsigned int NumberOfLowercase() { int i,LowercaseTotal; int size = strlen(WordArray); for(int i=0; i<size; i++) { if (islower(WordArray[i])) LowercaseTotal++; } return LowercaseTotal; } //------------------------------------------- // Function to calculate number of wowels //-------------------------------------------- unsigned int NumberOfVowels() { int i,VowelTotal; int size = strlen(WordArray); for(int i=0; i<size; i++) { if ((WordArray[i]=='a') || (WordArray[i]=='A') || (WordArray[i]=='e') || (WordArray[i]=='E') || (WordArray[i]=='I') || (WordArray[i]=='i') || (WordArray[i]=='o') || (WordArray[i]=='O') || (WordArray[i]=='u') || (WordArray[i]=='U') || (WordArray[i]=='y') || (WordArray[i]=='Y')) VowelTotal++; } return VowelTotal; } //-------------------------------------------------------------- // Function to calculate an print the frequency of letters // Parameter: Input Word // Action prints an array listing the frequency of letters //-------------------------------------------------------------- void FrequencyOfLetters() { int size = strlen(WordArray); char alphabet[50]="abcdefghijklmnopqrstuvwxyz"; int letter_count[26]; for(int i=0; i<26; i++) { letter_count[i]=0; } for(int i=0; i<size; i++) { for(int j=0; j<=26; j++) { if(WordArray[i]==alphabet[j]) { letter_count[j]++; } } } for(int j=0; j<26; j++) { if (letter_count[j]>0) cout<<alphabet[j]<<" "<<letter_count[j]++<<endl; } } }; //---------------------------- // begin main processing //---------------------------- int main() { Word Input; char line[25]; cout<<"Enter a string 25 Char. long Max : "; cin >> line; strcpy(Input.WordArray,line); cout<< "The word you entered " << line << " has " << endl; cout<< Input.NumberOfUppercase() << " Uppercase Letters" << endl; cout<< Input.NumberOfLowercase() << " Lowercase Letters" << endl; cout<< Input.NumberOfVowels() << " Vowels" << endl; Input.FrequencyOfLetters(); // Pause to look at the results system("pause"); return 0; } // end main
Can you point me to what it is I am doing wrong? There is a piece of this puzzle that does not fit I know it, but I cannot find it. There is something I don't quite comprehend yet about using public member functions while passing a charater array to it.Code:82 C:\C++Course\A1-1.cpp `void Word::FrequencyOfLetters()' and `void Word::FrequencyOfLetters()' cannot be overloaded
Thanks in advance,