您的位置:首页 > 编程语言 > C语言/C++

C++primer plus第六版课后编程练习答案6.7

2015-11-26 16:09 609 查看
#include<iostream>
#include<cctype>
#include<cstdlib>//support for exit(),atoi()
#include<string>
#include<fstream>//文件I/O
#include<sstream>//stringstream转换各种数据格式

using namespace std;

void main()
{
string str;
int vowel=0,consonant=0,other=0;//vowel元音,consonant辅音
cout<<"enter words (q to quit):"<<endl;
cin>>str;
while("q"!=str)
{
if(isalpha(str[0]))
{
if(('a'==str[0])||('o'==str[0])||('e'==str[0])||('i'==str[0])||('o'==str[0])||('u'==str[0]))//判断是否元音
vowel++;
else
consonant++;
}
else
other++;

cin>>str;
}
cout<<vowel<<" words beginning with vowels"<<endl;
cout<<consonant<<" words beginning with consonants"<<endl;
cout<<other<<" others"<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: