编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习7
#include <iostream> #include <string> #include <cctype> using namespace std; int main() { string words; int yy=0; int fy=0; int other=0; cout<<"Enter words (q to quit):\n"; while(cin>>words) { if(isalpha(words[0])) { if(words[0]=='q' && (words.size())==1) break; else { switch(words[0]) { case 'a': case 'o': case 'e': case 'i': case 'u': yy++; break; default:fy++; } } } else other++; } cout<<yy<<" words beginning with vowels"<<endl; cout<<fy<<" words beginning with consonants"<<endl; cout<<other<<" others"<<endl; system("pause"); return 0; }