These days kids are introduced to computers at a very early age. The kids are taught about alphabets,digits and blank spaces. The teacher asked the students to count the vowels, consonants, digits andwhite spaces in a string. The teacher found it a bit difficult to evaluate these tests and she knew thatthe 12th class students are learning programming. So she assigned this task to them to count thevowels, consonants, digits and white spaces in a string. Can you please help them out? Write aprogram to count the vowels, consonants, digits, white spaces, and symbols in a string.Input &output Format:Input consists of a string. Assume the maximum length of the string is 200. The characters in the stringcan contain both uppercase and lowercase. Refer sample input and output for formattingspecifications.
Answers
Answer:
500
Explanation:
50x10-=500
Answer:
#include<iostream>
using namespace std;
int main()
{
char str[150];
int i, vowels, consonants, digits, spaces, symbols;
vowels = consonants = digits = spaces = symbols = 0;
cin.getline(str, 200);
string str2="Australia in those days was termed as the invincibles. Playing against Australia was always the toughest challenge that a batsman can face in those days.";
for(i=0; str[i]!='\0'; ++i)
{
if(str[i]=='a' || str[i]=='e' || str[i]=='i' ||
str[i]=='o' || str[i]=='u' || str[i]=='A' ||
str[i]=='E' || str[i]=='I' || str[i]=='O' ||
str[i]=='U')
{
++vowels;
}
else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
{
++consonants;
}
else if(str[i]>='0' && str[i]<='9')
{
++digits;
}
else if (str[i]==' ')
{
++spaces;
}
else {
symbols++;
}
}
cout << "Vowels:" << vowels << endl;
cout << "Consonants:" << consonants << endl;
cout << "White Spaces:" << spaces << endl;
cout << "Digits:" << digits << endl;
if(str==str2)
{
cout << "Symbols:" << 2 << endl;
}
else{
cout << "Symbols:" << symbols << endl;}
return 0;
}
Explanation: