编程菜鸟的日记-初学尝试编程-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;
}

 

posted @ 2013-12-02 22:51  编程的爬行者  阅读(124)  评论(0编辑  收藏  举报