Write a program that
reads a string and outputs the number of lowercase vowels in the
string. Your program must contain a function with a parameter of a
char variable that returns an int. The function will return a 1 if
the char being passed in is a lowercase vowel, and a 0 for any
other character. The output for your main program should be:
There are XXXX lowercase vowels in string
yyyyyyyyyyyyyyyyyyyyyy
Where XXXX is the count of lowercase vowels and yyyyyyyyyyyyyyyyyy
is the string entered by the user.
Here is the original code for Exercise 22:
#include
<iostream>
#include <string>
using namespace std;
void countVowels(string str, int& aCt, int& eCt, int&
iCt,
int& oCt, int& uCt);
int main()
{
string inputString;
int aCount = 0;
int eCount = 0;
int iCount = 0;
int oCount = 0;
int uCount = 0;
cout << "Enter a string: " <<
endl;
getline(cin, inputString);
countVowels(inputString, aCount, eCount, iCount,
oCount, uCount);
cout << "The number of a's: " <<
aCount << endl;
cout << "The number of e's: " <<
eCount << endl;
cout << "The number of i's: " <<
iCount << endl;
cout << "The number of o's: " <<
oCount << endl;
cout << "The number of u's: " <<
uCount << endl;
return 0;
}
void countVowels(string str, int& aCt, int& eCt, int&
iCt,
int& oCt, int& uCt)
{
for (unsigned int i = 0; i < str.length();
i++)
switch (str.at(i))
{
case 'a':
aCt++;
break;
case 'e':
eCt++;
break;
case 'i':
iCt++;
break;
case 'o':
oCt++;
break;
case 'u':
uCt++;
}
}
C++ program- thank you
#include <iostream>
#include <string>
using namespace std;
void countVowels(string str, int& aCt, int& eCt,
int& iCt,
int& oCt, int& uCt);
int checkvowel(char ch);
int main()
{
string inputString;
int aCount = 0;
int eCount = 0;
int iCount = 0;
int oCount = 0;
int uCount = 0;
int vowelcount=0;
int count=0;
cout << "Enter a string: " <<
endl;
getline(cin, inputString);
countVowels(inputString, aCount, eCount,
iCount, oCount, uCount);
for (unsigned int i = 0; i <
inputString.length(); i++)
vowelcount +=
checkvowel(inputString.at(i));
if(aCount>0)
count++;
if(eCount>0)
count++;
if(iCount>0)
count++;
if(uCount>0)
count++;
cout<< "There are "<<count<< "
lowercase vowels in string "<<inputString<<endl;
cout<< " Where "<<vowelcount<<" is
the count of lowercase vowels and " <<inputString<<" is
the string entered by the user."<<endl;
return 0;
}
int checkvowel(char c)
{
switch(c)
{
case 'a':
return 1;
break;
case 'e':
return
1;
break;
case 'i':
return 1;
break;
case 'o':
return 1;
break;
case 'u':
return 1;
default : return
0;
}
return 0;
}
void countVowels(string str, int& aCt, int& eCt, int&
iCt,
int& oCt, int& uCt)
{
for (unsigned int i = 0; i < str.length();
i++)
switch (str.at(i))
{
case 'a':
aCt++;
break;
case 'e':
eCt++;
break;
case 'i':
iCt++;
break;
case 'o':
oCt++;
break;
case 'u':
uCt++;
}
}
Get Answers For Free
Most questions answered within 1 hours.