且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++显示元音和辅音并计数

更新时间:2023-09-18 22:19:46

要显示字母,可以使用以char为索引的for循环.

To show the letters, you can use a for loop, using a char as index.

int n = 13;
unsigned int vowel = 0;
unsigned int consonant = 0;
int a = (int)'a';
for (char letter = 'a'; (int)letter < a + n; letter++) {
    cout << letter << " ";
    if (is_vowel(letter)) vowel++;
    else consonant++;
}
cout << std::endl << "vowels: "<< vowel << " consonants: " << consonant << std::endl;

因此,您必须实现is_vowel方法.

So, you must implement the is_vowel method.