Write a program in the file freq.cpp which reads text from the user and then com
ID: 653689 • Letter: W
Question
Write a program in the file freq.cpp which reads text from the user and then computes the
frequency of each vowel as well as the number of consonants that appear in the text. A vowel is
one of the letters a, e, i, o, u, or y. Note that y can be considered to be a vowel or a consonant.
We will count a lower case or capitalized version of a letter the same. The frequency of a letter in
some text is the number of times it appears in that text, i.e its count. For example, the vowels in
the following text
Explanation / Answer
Answer
function to calculate vowels:
int* vowelCounter(string str, int vowel)
{
int* vptr = new int[vowel];
for (int i = 0; i < str.length(); i++)
{
int temp = toupper(str[i]);
if (temp == 'A'')
vowelA++;
if (temp == 'E'')
vowelE++;
if (temp == 'I'')
vowelI++;
if (temp == 'O'')
vowelO++;
if (temp == 'O'')
vowelO++;
if (temp == 'U')
vowelU++;
else
{
cout << "There are no vowels. " << endl;
}
}
cout << "Total vowels A are " << vowelA<< endl;
cout << "Total vowels E are " << vowelE<< endl;
cout << "Total vowels I are " << vowelI<< endl;
cout << "Total vowels O are " << vowelO<< endl;
cout << "Total vowels U are " << vowelU<< endl;
return vptr;
}
function to calculate constants:
int* constantCounter(string str, int conson)
{
int* cptr = new int[conson];
for (int i = 0; i < str.length(); i++)
{
int temp = toupper(str[i]);
if (temp != 'A', 'E', 'I', 'O', 'U')
{
conson++;
}
else
{
cout << "There are no consonants. " << endl;
}
}
cout << "Total consonants are " << conson << endl;
cout << "Total consonants are " << conson << endl;
return cptr;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.