It's shown on the C++ prime plus:
You would see it if you follow the step ..
I just want make a record, it takes me some times...
On page: 301
The excercise:
Write a program that reads input a word at a time until a lone q is entered. The program should then report the number of words that began with vowels, the number that began whith consonants, and the number that fit neither of those categories. One approach is to use isalpha() to discriminate between words beginning with letters and those that don't and then use an if or switch statement to further identify those passing the isalpha() test that begin with vowels. A sample run might look like this:
Enter words (q to quit):
The 12 awesome oxen ambled
quietly across 15 meters of lawn. q
5 words beginning with vowels
4 words beginning with consonants
2 others...
I give a similiar sample, It the same function as the excercise.. of course , you can find another way to expression to get the result.. But it give us a order to use the isalpha()..
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char char_tmp[32];
int words = 0, nums = 0, others = 0;
char *ch;
ch = char_tmp;
while(true){
cout << "Enter words ( q to quit): " << endl;
while(*ch = cin.get()){
if(ispunct(*ch)) others ++;
if(ispunct(*ch)&& !isalpha(*(ch-1)))continue;
if(isalpha(*ch) or isdigit(*ch)){ch++; continue;}
if(*ch == 0xa && *(ch-1) == 'q'){ch=char_tmp;break;}
if(*ch == ' ' && isalpha(*(ch-1))){words++; ch = char_tmp;}
if(*ch == '\n' && isalpha(*(ch-1))){words++; ch = char_tmp;}
if(*ch == ' ' && isdigit(*(ch-1))){nums++; ch = char_tmp;}
if(*ch=='\n' && isdigit(*(ch-1))){nums++; ch = char_tmp;}
if(isdigit(*ch)&&*(ch-1)=='.' && isdigit(*(ch-2))){nums++; ch = char_tmp;}
}
cout << "Words: " << words <<"\tNums: "<< nums << endl;
cout << "Punctuation_Symbols: " << others << endl;
words = 0;
others = 0;
nums = 0;
}
return 0;
}