C++中测试输入的单词中有多少个原音单词和铺音单词和其他单词问题~

来源:百度知道 编辑:UC知道 时间:2024/07/06 16:09:46
C++中测试输入的单词中有多少个原音单词和铺音单词和其他单词问题~

下面是我写的,但是根本测试不出来,我不知道哪里错了和该如何判断,请各位前辈帮我指出错误并把程序该对,谢谢你们啊~!
//测试输入的单词中有多少个原音单词和铺音单词和其他单词~!
#include<iostream>
#include<cctype>

using namespace std;

int main()
{
cout<<"Enter words (q to quit): \n";
char ch;
cin>>ch;
int other=0,v=0,c=0;
while(ch!='q')
{
if(isalpha(ch))
{
if(isspace(ch))
{
if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u')
v++;
else
c++;
}
}
else
{
other++;
}
cin>>ch;
}

说实话,我没看懂你题目是什么意思,好像没有元音和辅音单词之说,看你程序的意思应该是找所有单词中以元音或者辅音开头的单词的个数;
如果这样那就没必要用到cctype了
直接用string就可以了,帮你重写了一下,不知道符不符合要求;
#include<iostream>
#include<string>

using namespace std;

int main()
{
string words;
getline(cin,words);//所有单词输入在一行,单词间用空格隔开,以回车作为输入结束;
words = ' '+words;//为了操作一致性,在所有单词前加一个空格;
int c=0,v=0;
for(int i=0;i<words.length();i++)
{
if(words[i]==' ')
{
char ch=words[i+1];
if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u')
v++;
else
c++;
}
}
cout<<v<<" words beginning with vowels \n";
cout<<c<<" words beginning with con