Write a program that reads a string and outputs the number of times each lowerca
ID: 3674975 • Letter: W
Question
Write a program that reads a string and outputs the number of times each lowercasevowel appears in it. Your program must contain a function with one of its parametersas a string variable and five other integerreference parameters with each one representing the number a particular vowelappears in the string. The program shouldrequest a string input from the user thendisplay the results of the function.
Function Definition : voidvowelCount(string wordInput, int& aCount, int& eCount, int& iCount, int& oCount, int& uCount) ;
The following is a sample output :
Enter a string for vowel analyzing : Programming
Number of a’s : 1
Number of e’s : 0
Number of i’s : 1
Number of o’s : 1
Number of u’s : 0
Explanation / Answer
#include<iostream>
#include<stdlib.h>
using namespace std;
// function to test lowerCase vowel
bool isLowerVowel(char c){
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') {
return true;
}
else {
return false;
}
}
// function to count vowel
void vowelCount(string wordInput, int& aCount, int& eCount, int& iCount, int& oCount, int& uCount){
unsigned int i;
for(i=0; i<wordInput.size(); i++){
int c = wordInput.at(i);
if(isLowerVowel(c)){
switch(c){
case 'a': aCount++; break;
case 'e': eCount++; break;
case 'i': iCount++; break;
case 'o': oCount++; break;
case 'u': uCount++; break;
}
}
}
}
int main(){
string input;
int aCount=0, eCount=0, iCount=0, oCount=0, uCount=0;
//user input
cout<<"Enter a string: ";
cin>>input;
vowelCount(input, aCount, eCount, iCount, oCount, uCount);
//printing
cout<<"Number of a’s : "<<aCount<<endl;
cout<<"Number of e’s : "<<eCount<<endl;
cout<<"Number of i’s : "<<iCount<<endl;
cout<<"Number of o’s : "<<oCount<<endl;
cout<<"Number of u’s : "<<uCount<<endl;
return 0;
}
/*
Output:
Enter a string: Programming
Number of a’s : 1
Number of e’s : 0
Number of i’s : 1
Number of o’s : 1
Number of u’s : 0
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.