Fa Lab 11 C Secure l https/losesc edu/ shepheri/osce145/Labsuab 11.html Lab 11 V
ID: 3792048 • Letter: F
Question
Fa Lab 11 C Secure l https/losesc edu/ shepheri/osce145/Labsuab 11.html Lab 11 Vowel Counter and Sorter objective: Write a program that takes a phrase and then counts the numbei of vewels case does not mates) in the phrase. should display all of the vowels in sorted aseending order according to theis count. Only consider (AEIOU) as vowels. It may be a good idea to keep track and sort two amays 1. Has the vowels in alphabetic order 2 Has the number of said vowels Whenever one would swap then it swaps the values in both amays. Example Dialog Welcome to the vowel counter and sorter! Enter a phrase! aaaaa eeeeiiioou The vowels and their count e 4 a 5 Another Example Welcome to the vowel counter and sorter! Enter a phrase! Facetious is the only word in English that contains all vowels in orderExplanation / Answer
// C++ code
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
string phrase;
cout << "Welcome to vowel counter and sorter! ";
cout << "Enter a phrase! ";
getline(cin, phrase);
// string t lower case
std::transform(phrase.begin(), phrase.end(), phrase.begin(), ::tolower);
int charArray[256];
for (int i = 0; i < 256; ++i)
{
charArray[i] = 0;
}
for (int i = 0; i < phrase.size(); ++i)
{
charArray[phrase[i]]++;
}
cout << "u " << charArray[int('u')] << endl;
cout << "o " << charArray[int('o')] << endl;
cout << "i " << charArray[int('i')] << endl;
cout << "e " << charArray[int('e')] << endl;
cout << "a " << charArray[int('a')] << endl;
return 0;
}
/*
output:
Welcome to vowel counter and sorter!
Enter a phrase!
aaaaaeeeeiiioou
u 1
o 2
i 3
e 4
a 5
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.