#include <iostream>
bool isVowel(char c)
{
switch(toupper(c))
{
case 'A': case 'E': case 'I': case 'O': case 'U' : return true;
default: return false;
}
}
int main()
{
const char* source = "Ayodhya";
const char* tmp = source;
char uppercaseLetters[26] = {};
char lowercaseLetters[26] = {};
int vowels = 0;
int consonants = 0;
bool flag = false;
while(*tmp)
{
char current = tmp[0];
if(isalpha(current))
{
if(isVowel(toupper(current)))
{
++vowels;
}
else
{
++consonants;
}
if(isupper(current))
{
++uppercaseLetters[current - 'A'];
}
else
{
++lowercaseLetters[current - 'a'];
}
}
++tmp;
}
std::cout << "No of vowels: " << vowels << "\n";
std::cout << "Frequency of occurrence: ";
for(int i = 0; i < sizeof(uppercaseLetters)/sizeof(uppercaseLetters[0]); ++i)
{
char current = 'A' + i;
if(uppercaseLetters[i] + lowercaseLetters[i] > 0)
{
if(isVowel(current))
{
if(!flag)
{
flag = true;
}
else
{
std::cout << ";";
}
if(uppercaseLetters[i] > 0)
{
std::cout << (char)toupper(current) << "-" << (uppercaseLetters[i] + lowercaseLetters[i]);
}
else
{
std::cout << (char)tolower(current) << "-" << (uppercaseLetters[i] + lowercaseLetters[i]);
}
}
}
}
std::cout << "\n";
std::cout << "No of consonants: " << consonants << "\n";
std::cout << "Frequency of occurrence: ";
flag = false;
for(int i = 0; i < sizeof(uppercaseLetters)/sizeof(uppercaseLetters[0]); ++i)
{
char current = 'A' + i;
if(uppercaseLetters[i] + lowercaseLetters[i] > 0)
{
if(!isVowel(current))
{
if(!flag)
{
flag = true;
}
else
{
std::cout << ";";
}
if(uppercaseLetters[i] > 0)
{
std::cout << (char)toupper(current) << "-" << (uppercaseLetters[i] + lowercaseLetters[i]);
}
else
{
std::cout << (char)tolower(current) << "-" << (uppercaseLetters[i] + lowercaseLetters[i]);
}
}
}
}
std::cout << "\n";
std::cout << "String without vowels: ";
tmp = source;
while(*tmp)
{
char current = tmp[0];
if(!(isalpha(current) && isVowel(toupper(current))))
{
std::cout << current;
}
++tmp;
}
std::cout << "\n";
return 0;
}
Comments
Leave a comment