请各位大侠帮忙编写一下C++源程序,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/03 23:29:52
7.编写一个程序,它每次读取一个单词,直到用户只输入q。然后,该程序指出有多少个单词以元音打头,有多少个单词以辅音打头,还有多少个单词不属于这两类。为此,方法之一是,使用isalpha()来区分以字母和其他字符打头的单词,然后对于通过了isalpha ()测试的单词,使用if或switch语句来确定哪些以元音打头。该程序的运行情况如下:
Enter words (q to quit):
Tire 12 awesome oxen ambled
quietly aaroas 15 maters of la}nn.q
5 words beginning with vowels
4 words beginning with consonants
2 others

#include<cctype>
#include<iostream>
#include<string>
using namespace std;
bool check(char ch);
int main()
{
string a;int j=0,k=0,l=0;
cout<<"Enter words (q to quit): \n";
while(cin>>a &&a!="q");
{
if(isalpha(a[0]))
{
if(check(tolower(a[0])))
j++;
else
k++;
}
else
l++;
}
cout<<j<<" words beginning with vowels\n"<<k<<" words beginning with consonants\n"<< l<<"others\n";
cin>>k;
}
bool check(char ch)
{
switch(ch)
{
case'a':
case'e':
case 'i':
case '