问题:
解答:
#include <iostream>
#include <cctype>
using namespace std;int main()
{string words;int vowel = 0;int consonant = 0;int other=0;cout << "请输入一个单词(q结束):";cin >> words;while (words!="q"){if (!isalpha(words[0])){other++;}else{if (words[0] == 'a' || words[0] == 'e' || words[0] == 'i' ||words[0] == 'o' || words[0] == 'u'){vowel++;}else{consonant++;}}cout << "请输入下一个单词(q结束):";cin >> words;}cout << "元音开头单词有:" << vowel << "个" << endl;cout << "辅音开头单词有:" << consonant << "个" << endl;cout << "其他开头单词有:" << other << "个" << endl;return 0;
}
运行结果:
考查点:
- isalpha
- 字符串比较
- 循环
2024年8月28日20:56:33