C++中 单独输出一个单词中的每个字母和每个字符的ASCII码 最后输出元音字母(vowels)的个数
这个是输出格式例如这次输出的是Hello.第一行输出的是第一个字母“H"后面的72是它的ASCII码依次类推后面的行输出一个字母和ASCII最后一行输出单词中有几个元音字...
这个是输出格式 例如这次输出的是Hello. 第一行输出的是第一个字母“H" 后面的72是它的ASCII码 依次类推 后面的行输出一个字母和ASCII 最后一行输出单词中有几个元音字母…(C++ freshman 问题低端 求解释清楚)
Enter any word (without spaces in it): Hello.
Here are the ASCII codes for the letters in that word:
H 72
e 101
l 108
l 108
o 111
. 46
There are 2 vowels. 展开
Enter any word (without spaces in it): Hello.
Here are the ASCII codes for the letters in that word:
H 72
e 101
l 108
l 108
o 111
. 46
There are 2 vowels. 展开
2个回答
展开全部
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string mystring;
cout<<"Please enter a string:"<<endl;
cin>>mystring;
int counter=0;
for(int i=0;i<mystring.size();i++)
{
cout<<mystring[i]<<"\t"<<(int)(mystring[i])<<endl;
if(mystring[i]=='a'||mystring[i]=='e'||mystring[i]=='i'||mystring[i]=='o'||mystring[i]=='u'||
mystring[i]=='A'||mystring[i]=='E'||mystring[i]=='I'||mystring[i]=='O'||mystring[i]=='U')
counter++;
}
if(counter==0)
cout<<"There is no vowel"<<endl;
else if (counter ==1)
cout<<"There are 1 vowel"<<endl;
else
cout<<"There are "<<counter<<" vowels"<<endl;
return 0;
}
我刚写的代码,能够通过visual studio2012 的编译
#include <string>
using namespace std;
int main(void)
{
string mystring;
cout<<"Please enter a string:"<<endl;
cin>>mystring;
int counter=0;
for(int i=0;i<mystring.size();i++)
{
cout<<mystring[i]<<"\t"<<(int)(mystring[i])<<endl;
if(mystring[i]=='a'||mystring[i]=='e'||mystring[i]=='i'||mystring[i]=='o'||mystring[i]=='u'||
mystring[i]=='A'||mystring[i]=='E'||mystring[i]=='I'||mystring[i]=='O'||mystring[i]=='U')
counter++;
}
if(counter==0)
cout<<"There is no vowel"<<endl;
else if (counter ==1)
cout<<"There are 1 vowel"<<endl;
else
cout<<"There are "<<counter<<" vowels"<<endl;
return 0;
}
我刚写的代码,能够通过visual studio2012 的编译
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询