//The 12 awesome oxen ambled
//quietly across 15 meters of lawn. q
#include <iostream>
using namespace std;
const int ArSize = 20;
bool check_vowel(char word[ArSize]);
int main()
{
char word[ArSize];
int vowels = 0;
int consonants = 0;
int outhers = 0;
cout << "Enter words (q to quit):\n";
while (cin >> word && !(word[0] == 'q' && word[1] == '\0'))
{
if(isalpha(word[0]))
if(check_vowel(word))++vowels;
else ++consonants;
else ++outhers;
}
cout << vowels << " words beginning with vowels" << endl;
cout << consonants << " words beginning with consonants" << endl;
cout << outhers << " outhers" << endl;
return 0;
}
bool check_vowel(char word[ArSize]){
bool is_vowel = false;
char vowel[5] = {'a','e','i','o','u'};
for(int i=0;i<5;i++)
{
if(vowel[i] == word[0])
is_vowel=true;
}
return is_vowel;
}
C++ Primer Plus(第6版)6.11编程练习7
于 2025-05-21 10:33:38 首次发布