Answer:
Here the code is given as follows,
Explanation:
#include <iostream>
#include <string>
using namespace std;
void Vowels(string userString);
int main()
{
string userString;
//to get string from user
cout << "Please enter a string: ";
getline(cin,userString,'\n');
Vowels(userString);
return 0;
}
void Vowels(string userString)
{
char currentChar;
//variables to hold the number of instances of each vowel
int a = 0, e = 0, i = 0, o = 0, u = 0;
for (int x = 0; x < userString.length(); x++)
{
currentChar = userString.at(x);
switch (currentChar)
{
case 'a':
a += 1;
break;
case 'e':
e += 1;
break;
case 'i':
i += 1;
break;
case 'o':
o += 1;
break;
case 'u':
u += 1;
break;
default:
break;
}
}
// to print no of times a vowels appears in the string
cout << "Out of the " << userString.length() << " characters you entered." << endl;
cout << "Letter a = " << a << " times" << endl;
cout << "Letter e = " << e << " times" << endl;
cout << "Letter i = " << i << " times" << endl;
cout << "Letter o = " << o << " times" << endl;
cout << "Letter u = " << u << " times" << endl;
}
Hence the code and Output.
Please enter a string
Out of the 16 characters you entered.
Letter a = 2 times
Letter e = 1 times
Letter i = 0 times
Letter o = 1 times
Letter u = 0 times.