64 604
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #63138 in C++ for Seng

Question #63138
Write a program that reads an unspecified number of uppercase or lowercase alphabets, and determines how many of them are vowels and how many are consonants. Enter zero to signify the end of the input.
Expert's answer
//
// vowels_consonants.cpp
//
#include <iostream>
#include <cctype> // for isalpha
#include <cstring> // for strchr

using namespace std;

int main()
{
char ch;
const char VOWELS[] ={"AaEeIiOoUuYy"};
int num_vowels = 0;
int num_consonants = 0;
cout << "Enter string of chars (0 to quit); " ;
cin.get(ch);
while (ch != '0'){
if (isalpha(ch) ){
if ( strchr(VOWELS,ch) != NULL )
++num_vowels;
else
++num_consonants;
}
cin.get(ch);
}
cout << "\nNumber of vowels is " << num_vowels
<<",number of consonants is " << num_consonants;
cout << endl;
//keep console window open
cout << "\nPress any key to contnue...\n";
cin.get();
cin.get();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions