Can someone help me with this code for C++ (using Code Blocks) Write a value-ret
ID: 3921320 • Letter: C
Question
Can someone help me with this code for C++ (using Code Blocks)
Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. Write a program that prompts the user to input a sequence of characters and outputs the number of vowels, using the functionisVowel.
Turn in your source code which should be commented as follows:
Analysis at the top of the file
Function analysis, preconditions, and postconditions after each function prototype
Major tasks identified as comments in main function
Comments in functions as needed
Explanation / Answer
//The code will read a sequence of character and return the numer of vowels in them.
#include <iostream>
#include <string>
using namespace std;
bool isVowel(char ch);
//The function reads a character and return true if the character is vowel.
//The function can only read a character and cannot understand anyother variable type.
//The function will return a boolean value.
bool isVowel(char ch)
{
//Comparing to all the possible vowels in lower case.
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
{
return true;
}
//Comparing to all the possible vowels in upper case.
else if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
return true;
}
return false;
}
int main(void)
{
char ch;
//This variable holds the number of vowels in the input.
int count=0;
//Prompting user for input.
cout<<"Enter a sequence of characters:";
string s;
//Reading the complete input as single line in to a string.
getline(cin,s);
//Iterating the string.
for (int i=0;i<s.length();i++)
{
ch=s[i];
if(isVowel(ch))
{
//Incrementing count if a vowel is found.
count++;
}
}
cout<<"The number of vowels is "<<count<<endl;
return 0;
}