Write a program which takes input as string and then implement the logic to find out Consonants, Digits, White spaces and Vowels in string Refer sample input and output: Input 1: SRM University 600203 Output 1: Vowels:4 Consonants:10 Whitespaces:3 Digits:6 Test Case 1 Input (stdin) india won the world cup during 1983 and 2011 Expected Output Vowels:10 Consonants:18 Whitespaces:8 Digits:8 Test Case 2 Input (stdin) WELCOME TO ELAB AUTO EVALUATION TOOL 2017 Expected Output Vowels:17 Consonants:14 Whitespaces:6 Digits:4
#include <iostream>
using namespace std;
int main()
{
char line[150];
int vowels, consonants, digits, spaces;
vowels = consonants = digits = spaces = 0;
//cout << "Enter a line of string: ";
cin.getline(line, 150);
for(int i = 0; line[i]!='\0'; ++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
line[i]=='o' || line[i]=='u' || line[i]=='A' ||
line[i]=='E' || line[i]=='I' || line[i]=='O' ||
line[i]=='U')
{
++vowels;
}
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
{
++consonants;
}
else if(line[i]>='0' && line[i]<='9')
{
++digits;
}
else if (line[i]==' ')
{
++spaces;
}
}
cout << "Vowels:" << vowels << endl;
cout << "Consonants:" << consonants << endl;
cout << "Whitespaces:" << spaces << endl;
cout << "Digits:" << digits << endl;
return 0;
}