C++ primer plus第六版课后编程练习答案:6.7

#define  _CRT_SECURE_NO_WARNINGS 
#include 
#include
using namespace std;



int main()
{
    char words[20];
    int vowels = 0;
    int consonants = 0;
    int others=0;

    cout << "Enter words (q to quit):\n";
    cin >> words;//与换行符、制表符、空格符则自动追加‘\0’
    do
    {
        if (words[0] == 'q' && (strlen(words) == 1))
            break;
        else if (isalpha(words[0]))
        {
            if (words[0] == 'a' || words[0] == 'e' || words[0] == 'i' || words[0] == 'o' || words[0] == 'u')
                vowels++;
            else
                consonants++;
        }
        else
            others++;
        cin >> words;
    } while (true);
    cout << vowels << " words beginning with vowels\n";
    cout << consonants << " words beginning with consonants.\n";
    cout << others << " others";
    return 0;

}

你可能感兴趣的:(C++,primer,plus第六版课后编程练习)